Skip to content

Commit 44ff3c5

Browse files
committed
Add CLI mode
Add option to download and install Tor Browser using CLI
1 parent 0e020dc commit 44ff3c5

File tree

3 files changed

+537
-24
lines changed

3 files changed

+537
-24
lines changed

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
SHARE = "share"
3636

3737
# detect linux distribution
38-
distro = platform.dist()[0]
38+
distro = ''
39+
if sys.version_info.major == 3:
40+
distro = platform.platform()[0]
41+
else:
42+
distro = platform.dist()[0]
3943

4044

4145
def file_list(path):

torbrowser_launcher/__init__.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from .common import Common, SHARE
3737
from .settings import Settings
3838
from .launcher import Launcher
39+
from .launcher_cli import LauncherCLI
3940

4041

4142
class Application(QtWidgets.QApplication):
@@ -59,10 +60,16 @@ def main():
5960
help="Open Tor Browser Launcher settings",
6061
)
6162
parser.add_argument("url", nargs="*", help="URL to load")
63+
parser.add_argument(
64+
'--cli',
65+
action='store_true',
66+
dest='cli',
67+
help='Open Tor Browser Launcher in CLI mode')
6268
args = parser.parse_args()
6369

6470
settings = bool(args.settings)
6571
url_list = args.url
72+
cli_mode = bool(args.cli)
6673

6774
# Load the version and print the banner
6875
with open(os.path.join(SHARE, "version")) as buf:
@@ -74,31 +81,37 @@ def main():
7481
print("https://github.com/micahflee/torbrowser-launcher")
7582

7683
common = Common(tor_browser_launcher_version)
77-
app = Application()
78-
79-
# Open the window
80-
gui = None
8184

82-
if settings:
83-
# Settings mode
84-
gui = Settings(common, app)
85+
if cli_mode:
86+
cli = LauncherCLI(common, url_list)
87+
cli.start()
88+
sys.exit(0)
8589
else:
86-
# Launcher mode
87-
gui = Launcher(common, app, url_list)
88-
89-
# Center the window
90-
desktop = app.desktop()
91-
window_size = gui.size()
92-
gui.move(
93-
(desktop.width() - window_size.width()) / 2,
94-
(desktop.height() - window_size.height()) / 2,
95-
)
96-
gui.show()
97-
98-
# Allow ctrl-c to work
99-
signal.signal(signal.SIGINT, signal.SIG_DFL)
100-
101-
sys.exit(app.exec_())
90+
app = Application()
91+
92+
# Open the window
93+
gui = None
94+
95+
if settings:
96+
# Settings mode
97+
gui = Settings(common, app)
98+
else:
99+
# Launcher mode
100+
gui = Launcher(common, app, url_list)
101+
102+
# Center the window
103+
desktop = app.desktop()
104+
window_size = gui.size()
105+
gui.move(
106+
(desktop.width() - window_size.width()) / 2,
107+
(desktop.height() - window_size.height()) / 2,
108+
)
109+
gui.show()
110+
111+
# Allow ctrl-c to work
112+
signal.signal(signal.SIGINT, signal.SIG_DFL)
113+
114+
sys.exit(app.exec_())
102115

103116

104117
if __name__ == "__main__":

0 commit comments

Comments
 (0)