Skip to content

feat(macos): restore the light on wake / startup, add open-at-login#20

Merged
MegaManSec merged 2 commits into
mainfrom
feat/macos-power-restore
Jun 8, 2026
Merged

feat(macos): restore the light on wake / startup, add open-at-login#20
MegaManSec merged 2 commits into
mainfrom
feat/macos-power-restore

Conversation

@MegaManSec

Copy link
Copy Markdown
Owner

What

Replace the sleep/shutdown "turn the light off" toggles with a per-event choice — Do nothing / Turn off / Turn off, then restore — shown as pop-up menus in Settings. "Restore" brings the light back on when the Mac wakes (sleep) or next launches (shutdown), letting the bulb relight to its own remembered colour/brightness. Adds an Open at login toggle (SMAppService) so restore-on-startup can run after a reboot.

Behaviour / defaults

  • New installs default to turn off, then restore for both events, with open-at-login on. Pre-5.x users who'd enabled the old "turn off" keep Turn off (faithful migration); only installs with no stored choice get the new default.
  • Restore only fires if the light was connected and on when turned off, only within a grace window, and boot-restore only at low system uptime (so opening the app by hand long after a normal boot won't toggle the light). An explicit power toggle / disconnect cancels a pending restore.

Files

  • AppState.swiftPowerEventAction, migration, restore plumbing, openAtLogin
  • LoginItem.swift (new) — SMAppService.mainApp wrapper
  • AppDelegate.swiftdidWakeNotification observer
  • Views/SettingsView.swift — two pickers + login toggle + hint

Test plan

  • swift build clean; swift test 15/15.
  • Sleep→wake restore verified with a local build (pmset sleepnow).
  • Shutdown→boot leg needs a Developer ID build for SMAppService to register (ad-hoc signing may not take effect).

Replace the two "turn the light off on sleep / shutdown" toggles with a
per-event choice — Do nothing / Turn off / Turn off, then restore — shown
as pop-up menus in Settings. "Restore" turns the light back on when the Mac
wakes (sleep) or next launches (shutdown); a bare power-on lets the bulb
relight to its own remembered colour and brightness.

- PowerEventAction enum, persisted in UserDefaults; pre-5.x Bool prefs are
  migrated forward (legacy on -> Turn off). Installs with no stored choice
  default to "turn off, then restore", and the app opens at login.
- Restore is gated: only when the light was connected and on at the time,
  only within a grace window, and boot-restore only at low system uptime so
  opening the app by hand long after a normal boot won't toggle the light.
  An explicit power toggle or disconnect cancels a pending restore.
- Add an "Open at login" toggle backed by SMAppService (new LoginItem.swift),
  needed so restore-on-startup can run after a reboot; defaults on and is
  auto-enabled when a shutdown restore is chosen.
- Observe NSWorkspace.didWakeNotification to drive the wake restore.
Bump the root, core, and cli package versions and the app's
CFBundleShortVersionString to 5.1.0 in lockstep (CFBundleVersion 18 -> 19),
so the release workflow publishes on merge to main. Ships the sleep/shutdown
turn-off-then-restore options and the open-at-login toggle.
@MegaManSec MegaManSec merged commit 6710a55 into main Jun 8, 2026
2 checks passed
@MegaManSec MegaManSec deleted the feat/macos-power-restore branch June 8, 2026 15:46
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