Skip to content

Commit

Permalink
Fixed Mac not showing a browser window
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Dec 5, 2024
1 parent 7b8821c commit 4cadb81
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/run_tribler.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ async def mac_event_loop() -> None:
await asyncio.sleep(0.01)


def open_webbrowser_tab(url: str) -> None:
"""
Open a webbrowser tab with the given URL.
"""
if sys.platform == "darwin":
os.system(f"open {url}") # noqa: S605
else:
webbrowser.open_new_tab(url)


def spawn_tray_icon(session: Session, config: TriblerConfigManager) -> Icon:
"""
Create the tray icon.
Expand All @@ -184,10 +194,10 @@ def spawn_tray_icon(session: Session, config: TriblerConfigManager) -> Icon:
image = Image.open(image_path.resolve())
api_port = session.rest_manager.get_api_port()
url = f"http://{config.get('api/http_host')}:{api_port}/ui/#/downloads/all?key={config.get('api/key')}"
menu = (pystray.MenuItem('Open', lambda: webbrowser.open_new_tab(url)),
menu = (pystray.MenuItem('Open', lambda: open_webbrowser_tab(url)),
pystray.MenuItem('Quit', lambda: session.shutdown_event.set()))
icon = pystray.Icon("Tribler", icon=image, title="Tribler", menu=menu)
webbrowser.open_new_tab(url)
open_webbrowser_tab(url)
if sys.platform == "darwin":
icon.run_detached(None)
asyncio.ensure_future(mac_event_loop()) # noqa: RUF006
Expand Down Expand Up @@ -217,7 +227,7 @@ async def main() -> None:
logger.info("Starting torrent using existing core")
await start_download(config, server_url, torrent_uri)
if not headless:
webbrowser.open_new_tab(server_url + f"?key={config.get('api/key')}")
open_webbrowser_tab(server_url + f"?key={config.get('api/key')}")
logger.info("Shutting down")
return

Expand Down

0 comments on commit 4cadb81

Please sign in to comment.