From de13f44f2434b3e74719c3a480d1c14097ed2e05 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sun, 26 Apr 2026 23:41:03 +0300 Subject: [PATCH] feat(autostart): suppress browser auto-open on Windows login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- build/installer.nsi | 5 ++++- server/scripts/start-hidden.vbs | 9 +++++++++ server/src/ledgrab/__main__.py | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/build/installer.nsi b/build/installer.nsi index 550d126..4c1ceca 100644 --- a/build/installer.nsi +++ b/build/installer.nsi @@ -162,8 +162,11 @@ Section "Desktop shortcut" SecDesktop SectionEnd Section "Start with Windows" SecAutostart + ; Pass --autostart so the VBS sets LEDGRAB_AUTOSTART=1 and the app suppresses + ; the browser auto-open on Windows login. Manual launches (desktop / start + ; menu) don't pass the arg, so they keep opening the WebUI tab. CreateShortcut "$SMSTARTUP\${APPNAME}.lnk" \ - "wscript.exe" '"$INSTDIR\scripts\${VBSNAME}"' \ + "wscript.exe" '"$INSTDIR\scripts\${VBSNAME}" --autostart' \ "$INSTDIR\app\src\ledgrab\static\icons\icon.ico" 0 SectionEnd diff --git a/server/scripts/start-hidden.vbs b/server/scripts/start-hidden.vbs index c961d8c..de8d66a 100644 --- a/server/scripts/start-hidden.vbs +++ b/server/scripts/start-hidden.vbs @@ -10,6 +10,15 @@ Set procEnv = WshShell.Environment("Process") procEnv("PYTHONPATH") = appRoot & "\app\src" procEnv("LEDGRAB_CONFIG_PATH") = appRoot & "\app\config\default_config.yaml" +' If launched as Windows autostart (via the SMSTARTUP shortcut), suppress the +' browser auto-open. Manual launches (desktop / start menu) pass no args. +For Each arg In WScript.Arguments + If arg = "--autostart" Then + procEnv("LEDGRAB_AUTOSTART") = "1" + Exit For + End If +Next + ' Use embedded python.exe (NOT pythonw.exe) with WindowStyle=0. ' Same pattern as the Media Server sibling app. embeddedPython = appRoot & "\python\python.exe" diff --git a/server/src/ledgrab/__main__.py b/server/src/ledgrab/__main__.py index c11d8ac..c990319 100644 --- a/server/src/ledgrab/__main__.py +++ b/server/src/ledgrab/__main__.py @@ -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,),