feat(autostart): suppress browser auto-open on Windows login

When the user enables "Start with Windows" in the installer, the app
launches on every PC login. Previously each login popped a fresh WebUI
tab, which is noisy for a tray-resident background service.

The autostart shortcut now passes --autostart to start-hidden.vbs, which
sets LEDGRAB_AUTOSTART=1 in the child env. __main__ checks this flag
alongside LEDGRAB_RESTART when deciding whether to open the browser.

Manual launches (desktop/start-menu shortcuts) and the installer's
post-install "Launch LedGrab" finish-page action are unchanged — they
don't pass the arg, so they still open the WebUI tab.
This commit is contained in:
2026-04-26 23:41:03 +03:00
parent 1c9acc5afb
commit de13f44f24
3 changed files with 25 additions and 3 deletions
+12 -2
View File
@@ -83,6 +83,16 @@ def _is_restart() -> bool:
return os.environ.get("LEDGRAB_RESTART", "") == "1"
def _is_autostart() -> bool:
"""Detect if launched via the Windows autostart shortcut."""
return os.environ.get("LEDGRAB_AUTOSTART", "") == "1"
def _should_skip_browser() -> bool:
"""Skip auto-opening the browser on restarts and on Windows login autostart."""
return _is_restart() or _is_autostart()
def _check_port(host: str, port: int) -> None:
"""Exit with a clear message if the port is already in use."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
@@ -120,8 +130,8 @@ def main() -> None:
)
server_thread.start()
# Browser after a short delay (skip on restart — user already has a tab)
if not _is_restart():
# Browser after a short delay (skip on restart and on Windows login autostart)
if not _should_skip_browser():
threading.Thread(
target=_open_browser,
args=(config.server.port,),