fix: skip browser open on tray restart, add WLED rename TODO
Some checks failed
Lint & Test / test (push) Failing after 30s
Some checks failed
Lint & Test / test (push) Failing after 30s
Set WLED_RESTART=1 env var on tray restart so __main__.py skips opening a new browser tab — the user already has one open. Add important TODO item to eliminate WLED naming throughout the app (package rename, i18n, build scripts, etc.).
This commit is contained in:
@@ -5,6 +5,7 @@ shows a system-tray icon with **Show UI** / **Exit** actions.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
@@ -36,6 +37,11 @@ def _open_browser(port: int, delay: float = 2.0) -> None:
|
||||
webbrowser.open(f"http://localhost:{port}")
|
||||
|
||||
|
||||
def _is_restart() -> bool:
|
||||
"""Detect if this is a restart (vs first launch)."""
|
||||
return os.environ.get("WLED_RESTART", "") == "1"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
config = get_config()
|
||||
|
||||
@@ -60,12 +66,13 @@ def main() -> None:
|
||||
)
|
||||
server_thread.start()
|
||||
|
||||
# Browser after a short delay
|
||||
threading.Thread(
|
||||
target=_open_browser,
|
||||
args=(config.server.port,),
|
||||
daemon=True,
|
||||
).start()
|
||||
# Browser after a short delay (skip on restart — user already has a tab)
|
||||
if not _is_restart():
|
||||
threading.Thread(
|
||||
target=_open_browser,
|
||||
args=(config.server.port,),
|
||||
daemon=True,
|
||||
).start()
|
||||
|
||||
# Tray on main thread (blocking)
|
||||
tray = TrayManager(
|
||||
|
||||
@@ -65,6 +65,7 @@ class TrayManager:
|
||||
return
|
||||
self._icon.stop()
|
||||
self._on_exit()
|
||||
os.environ["WLED_RESTART"] = "1"
|
||||
os.execv(sys.executable, [sys.executable, "-m", "wled_controller"])
|
||||
|
||||
def _shutdown(self, icon: "pystray.Icon", item: "pystray.MenuItem") -> None:
|
||||
|
||||
Reference in New Issue
Block a user