Skip to content

feat(macos): turn the light off on system sleep / shutdown#17

Merged
MegaManSec merged 2 commits into
mainfrom
feat/off-on-sleep-shutdown
Jun 8, 2026
Merged

feat(macos): turn the light off on system sleep / shutdown#17
MegaManSec merged 2 commits into
mainfrom
feat/off-on-sleep-shutdown

Conversation

@MegaManSec

Copy link
Copy Markdown
Owner

Summary

Two opt-in Settings → Behaviour toggles turn the selected light off just before the Mac sleeps or shuts down — so it is not left lit in an empty room.

How

  • Sleep: an NSWorkspace.willSleepNotification observer, selector-based so it runs synchronously on the main thread during the sleep transition — the off datagrams egress while Wi-Fi is still up.
  • Shutdown / logout / restart: reuses the existing isSystemInitiatedQuit() check in applicationShouldTerminate; disableSuddenTermination() guarantees that path runs instead of a SIGKILL.
  • Both call a synchronous WizClient.sendNow power-off (3×, ≈240 ms) rather than the usual debounced/async send, which would never leave the machine before the NIC sleeps.
  • Prefs persist in UserDefaults (macOS-only behaviour — kept out of the shared cross-tool settings.json, mirroring UpdateChecker.autoCheckEnabled). Both default off.

Test plan

  • swift build + swift test (15 WizKit tests) green.
  • Manual: enable sleeppmset sleepnow → bulb turns off; disable → stays on. Enable shutdown → Apple menu → Restart → bulb turns off; quitting the app from the menu bar leaves the light untouched.

Adds two opt-in toggles under Settings → Behaviour that switch the selected light off just before the Mac sleeps or shuts down, so it is not left lit in an empty room.

Sleep is handled by an NSWorkspace.willSleepNotification observer (synchronous, on the main thread). Shutdown/logout/restart reuses the existing isSystemInitiatedQuit check in applicationShouldTerminate, with sudden termination disabled so that path is guaranteed to run. Both fire a synchronous WizClient.sendNow power-off so the command leaves the machine before the network drops, unlike the usual debounced async path.

The prefs persist in UserDefaults (a macOS-only behaviour, kept out of the shared cross-tool settings.json, mirroring UpdateChecker.autoCheckEnabled) and default off.
Bump root, wiz-light-core, wiz-light-cli, and the macOS app (CFBundleShortVersionString 0.6.0 / build 18) in lockstep, alongside the sleep/shutdown auto-off feature in this PR.
@MegaManSec MegaManSec merged commit 6c3799a into main Jun 8, 2026
2 checks passed
@MegaManSec MegaManSec deleted the feat/off-on-sleep-shutdown branch June 8, 2026 10:26
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