Fix: tray icon missing after shutdown+power-on (Windows Fast Startup) - #1
Open
amerganim wants to merge 3 commits into
Open
Fix: tray icon missing after shutdown+power-on (Windows Fast Startup)#1amerganim wants to merge 3 commits into
amerganim wants to merge 3 commits into
Conversation
The service launched the tray then stopped itself. Windows Fast Startup (the default for "Shut down") hibernates session 0 and restores it on the next power-on instead of cold-booting, so auto-start services are not re-run. A self-stopped service therefore stays stopped after power-on and never receives the logon event, so the tray never appears. A full "Restart" bypasses Fast Startup, which is why restarting worked. - Remove StopSelf(): the service now stays running (idle) and relaunches the tray on SessionLogon/Unlock/Connect, including after a Fast-Startup resume. - Add IsTrayRunningInSession() guard so repeated session events do not spawn duplicate tray icons. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reverts to the "launch tray then stop the service" design (near-zero idle memory) while still fixing the shutdown+power-on case. The service now registers a Task Scheduler "at log on" task whose action is `sc start SmartThings.Service`. Logon triggers fire on the interactive logon that follows a Fast-Startup resume (unlike auto-start services, which are skipped on a hybrid resume), so on every sign-in the task restarts the service, it launches the tray, then stops itself again. - Re-add StopSelf() and call it after launching (and when the tray is already running). - EnsureLogonTaskRegistered() creates/refreshes the task on OnStart (idempotent, best effort). - Keep IsTrayRunningInSession() guard so the task + boot path can't spawn duplicate tray icons. - Uninstall.ps1 deletes the logon task so it isn't orphaned. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nstall) The self-registered logon Scheduled Task was not part of the MSIX package, so a right-click / Store uninstall (the real distribution path - no Uninstall.ps1) would leave it orphaned. Replace it with a package-declared windows.startupTask, which is added and removed with the package. - Package.appxmanifest: add desktop:StartupTask on the TrayHelper app so the tray helper is launched at every logon, including the logon after a Fast-Startup "Shut down -> power on" (auto-start services are not re-run on a hybrid resume; logon startup tasks are). - TrayService.cs: revert to the plain StopSelf design and drop the schtasks-based logon-task registration. The service still launches the tray at install / cold boot (and on preloaded devices, where the app may never be opened and the startup task's "run once" gate would otherwise apply). - The native tray helper is already single-instance (mutex in main.cpp), so a service launch and a startup-task launch never yield duplicate icons. - Revert the Uninstall.ps1 scheduled-task cleanup (no longer needed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
The tray icon appears after a Restart, but not after a Shut down → power on. Manually starting the
SmartThings.Serviceafterwards makes the tray appear.Root cause — Windows Fast Startup
The service was designed to launch the tray once, then stop itself (
StopSelf()).SessionLogonfires → tray launches. ✅OnSessionChange→ the tray never launches. ❌The confirming clue: you can only Start a stopped service, so the fact that a manual start works proves the service is sitting stopped after Fast Startup.
Fix
DesktopBridge/SmartThings.Service/TrayService.cs:StopSelf(). The service now stays running (idle) and keeps listening for session changes, so it relaunches the tray on the nextSessionLogon/Unlock/Connect— including the logon that follows a Fast-Startup resume. Idle cost is negligible.IsTrayRunningInSession()guard so repeated session events (e.g. lock/unlock, RDP reconnect) don't spawn duplicate tray icons. It filters bySessionIdbecause the LocalSystem service (session 0) can see processes in every session.LaunchThenStop→EnsureTrayRunningto match the new behavior.Builds clean (
dotnet build -c Release, 0 warnings/errors).How to verify
Service logs to
C:\ProgramData\DesktopBridge\TrayLauncherService.log.Session change: SessionLogonentry followed by a successful tray launch; tray present.Optional confirmation of the diagnosis (machine-level, not needed with this fix):
powercfg /h offdisables Fast Startup and the old build's symptom disappears.🤖 Generated with Claude Code