Skip to content

Commit

Permalink
Add CLI mode
Browse files Browse the repository at this point in the history
Add option to download and install Tor Browser using CLI
  • Loading branch information
vrask committed Aug 25, 2020
1 parent 275a2b8 commit a86c6ba
Show file tree
Hide file tree
Showing 3 changed files with 532 additions and 24 deletions.
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
SHARE = 'share'

# detect linux distribution
distro = platform.dist()[0]
distro = ''
if sys.version_info.major == 3:
distro = platform.platform()[0]
else:
distro = platform.dist()[0]


def file_list(path):
Expand Down
54 changes: 31 additions & 23 deletions torbrowser_launcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .common import Common, SHARE
from .settings import Settings
from .launcher import Launcher
from .launcher_cli import LauncherCLI


class Application(QtWidgets.QApplication):
Expand All @@ -53,10 +54,12 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--settings', action='store_true', dest='settings', help='Open Tor Browser Launcher settings')
parser.add_argument('url', nargs='*', help='URL to load')
parser.add_argument('--cli', action='store_true', dest='cli', help='Open Tor Browser Launcher in CLI mode')
args = parser.parse_args()

settings = bool(args.settings)
url_list = args.url
cli_mode = bool(args.cli)

# Load the version and print the banner
with open(os.path.join(SHARE, 'version')) as buf:
Expand All @@ -68,31 +71,36 @@ def main():
print('https://github.com/micahflee/torbrowser-launcher')

common = Common(tor_browser_launcher_version)
app = Application()

# Open the window
gui = None

if settings:
# Settings mode
gui = Settings(common, app)
if cli_mode:
cli = LauncherCLI(common, url_list)
cli.start()
else:
# Launcher mode
gui = Launcher(common, app, url_list)

# Center the window
desktop = app.desktop()
window_size = gui.size()
gui.move(
(desktop.width() - window_size.width()) / 2,
(desktop.height() - window_size.height()) / 2
)
gui.show()

# Allow ctrl-c to work
signal.signal(signal.SIGINT, signal.SIG_DFL)

sys.exit(app.exec_())
app = Application()

# Open the window
gui = None

if settings:
# Settings mode
gui = Settings(common, app)
else:
# Launcher mode
gui = Launcher(common, app, url_list)

# Center the window
desktop = app.desktop()
window_size = gui.size()
gui.move(
(desktop.width() - window_size.width()) / 2,
(desktop.height() - window_size.height()) / 2
)
gui.show()

# Allow ctrl-c to work
signal.signal(signal.SIGINT, signal.SIG_DFL)

sys.exit(app.exec_())


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit a86c6ba

Please sign in to comment.