Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI mode #486

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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