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

Fixed Mac not showing a browser window #8313

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
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
Loading