Skip to content

Fix: tray icon missing after shutdown+power-on (Windows Fast Startup) - #1

Open
amerganim wants to merge 3 commits into
feature/rename-smartthingsfrom
fix/tray-fast-startup
Open

Fix: tray icon missing after shutdown+power-on (Windows Fast Startup)#1
amerganim wants to merge 3 commits into
feature/rename-smartthingsfrom
fix/tray-fast-startup

Conversation

@amerganim

Copy link
Copy Markdown
Owner

Problem

The tray icon appears after a Restart, but not after a Shut down → power on. Manually starting the SmartThings.Service afterwards makes the tray appear.

Root cause — Windows Fast Startup

The service was designed to launch the tray once, then stop itself (StopSelf()).

  • Restart = a true cold boot. Fast Startup is always bypassed for Restart, so the SCM starts the auto-start service fresh → it waits for logon → SessionLogon fires → tray launches. ✅
  • Shut down → power on = a hybrid resume. Windows logs off the user, then hibernates session 0 (kernel + SCM + services) and restores that image on power-on instead of cold-booting. Auto-start services are not re-run. Because the service had already stopped itself, it stays STOPPED after resume, and a stopped service cannot receive 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:

  • Remove StopSelf(). The service now stays running (idle) and keeps listening for session changes, so it relaunches the tray on the next SessionLogon / Unlock / Connect — including the logon that follows a Fast-Startup resume. Idle cost is negligible.
  • Add IsTrayRunningInSession() guard so repeated session events (e.g. lock/unlock, RDP reconnect) don't spawn duplicate tray icons. It filters by SessionId because the LocalSystem service (session 0) can see processes in every session.
  • Renamed LaunchThenStopEnsureTrayRunning to match the new behavior.

Builds clean (dotnet build -c Release, 0 warnings/errors).

How to verify

Service logs to C:\ProgramData\DesktopBridge\TrayLauncherService.log.

  • Before: after shutdown→power-on, no new "Service starting" line at logon; tray absent.
  • After: a Session change: SessionLogon entry followed by a successful tray launch; tray present.

Optional confirmation of the diagnosis (machine-level, not needed with this fix): powercfg /h off disables Fast Startup and the old build's symptom disappears.

🤖 Generated with Claude Code

amerganim and others added 3 commits July 30, 2026 21:40
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant