fix(cli): run Windows sync without flashing a console window - #38
Open
sybrengg wants to merge 1 commit into
Open
fix(cli): run Windows sync without flashing a console window#38sybrengg wants to merge 1 commit into
sybrengg wants to merge 1 commit into
Conversation
The Windows service registers a schtasks task whose action points directly at the service-sync.cmd wrapper. schtasks can only create tasks that run in the interactive session, so a cmd console window appears on every run - every 5 minutes - which steals focus from full-screen apps and games. Launch the wrapper through a tiny generated VBScript (service-sync-launcher.vbs) via wscript.exe, a GUI-subsystem host, with window style 0. The sync then runs with no window at all while still propagating the wrapper's exit code back to Task Scheduler via WScript.Quit. Bump the service template version so existing installs self-migrate to the hidden launcher on their next repair. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Fixes #57 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows the background sync opens a console window on every run — every 5 minutes.
schtaskscan only register tasks that run in the interactive session, and the task action points straight atservice-sync.cmd(a console program), so acmd.exewindow flashes on the desktop each time the task fires. On a normal desktop it's a brief flash; for anyone in a full-screen app or game it repeatedly steals focus (in my case it kept knocking a full-screen game out of focus every 5 minutes).Root cause
windowsTaskCreateArgsregisters:schtaskshas no flag for the "run whether the user is logged on or not" (S4U) logon type, nor any way to hide the window, so the launched console is always visible on the user's desktop.Fix
Launch the existing wrapper through a tiny generated VBScript run by
wscript.exe(a GUI-subsystem host) with window style0:wscript.exehas no console, andRun(…, 0, …)hides the child. (Unlikepowershell -WindowStyle Hidden, which still briefly flashes a console before hiding it.)bWaitOnReturn = True+WScript.Quitpropagate the wrapper's exit code to Task Scheduler, soservice status/doctorLastTaskResultstays accurate.service installUX. (An S4U / "run whether logged on or not" task would also hide the window, but requires admin at install time — a UX regression — so I avoided it.)SERVICE_TEMPLATE_VERSIONis bumped5 → 6, so existing installs are seen as stale and self-migrate to the hidden launcher on their next scheduled repair.The
.cmdwrapper itself (log rotation, runner-pointer handling, logging) is unchanged — it's just no longer the task's entry point.Testing
renderWindowsLauncherunit test and updated thewindowsTaskCreateArgsexpectation.apps/cli:tsctypecheck,oxlint --type-aware --type-check, andoxfmtall pass on the changed files.wscript.exe //nologo //b launcher.vbsruns the wrapper with no visible window and returns the wrapper's exit code (a wrapper thatexit /b 42yields wscript exit code42).Heads up: a few pre-existing tests in
service.test.tsfail when the suite is run on a Windows host because they assume POSIX path separators fromnode:path'sjoin. Those are unrelated to this change (they fail the same way onmain) and pass on the Linux/macOS CI. Happy to send a separate PR making them host-agnostic if that'd be useful.🤖 Generated with Claude Code