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 Oct 21, 2020
1 parent 0e020dc commit 44ff3c5
Show file tree
Hide file tree
Showing 3 changed files with 537 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
59 changes: 36 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 @@ -59,10 +60,16 @@ def main():
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 @@ -74,31 +81,37 @@ 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()
sys.exit(0)
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 44ff3c5

Please sign in to comment.