Add reachability (Auto) keep-awake mode + battery-floor safety#49
Open
tomarai85 wants to merge 2 commits into
Open
Add reachability (Auto) keep-awake mode + battery-floor safety#49tomarai85 wants to merge 2 commits into
tomarai85 wants to merge 2 commits into
Conversation
Two opt-in additions; defaults are unchanged, so existing behaviour is identical. Keep-awake mode (Off / Caps Lock / Auto): - Caps Lock stays the default and works exactly as today. - Auto keeps the Mac awake automatically (independent of Caps Lock) -- for closing the lid and remote-controlling the machine (e.g. SSH from a phone), where you need it to stay reachable without remembering to toggle a key. Battery floor (default 15%, opt-in, hysteresis-latched): - On battery, release keep-awake at/below the threshold so the Mac can sleep before the battery fully drains (which would also drop remote access). Recovers on AC. - BatteryReader reads the power source via IOKit; the decision is isolated in a pure BatteryFloorPolicy with 10 unit tests (boundary, hysteresis, unreadable/AC/unknown fail-safes -- unreadable power state stays awake, i.e. reachable). Surfaced in the status menu (mode items + a Battery floor submenu) and the settings window. The poll timer runs in .default (not .common) so its periodic pmset verification never spawns a subprocess during menu tracking. All 24 tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The PR describes both additions as opt-in with defaults unchanged, but registerDefaults() shipped batteryFloorEnabled as true. On a stock install that released keep-awake at 15% on battery even with Caps Lock held, which is a behavior change upstream users never opted into. Registering it as false makes the stated contract true: fresh installs behave exactly as before, and the floor is something you turn on. Co-Authored-By: Claude Fable 5 <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.
What
Two small, opt-in additions. Defaults are unchanged — with no configuration the app behaves exactly as it does today (Caps Lock keeps the Mac awake).
1. Keep-awake mode: Off / Caps Lock / Auto
Caps Lock stays the default and works exactly as today.
Autokeeps the Mac awake automatically, independent of Caps Lock — for the case of closing the lid and driving the machine remotely (e.g. SSH from a phone), where you want it to stay reachable without remembering to toggle a key.Offis an explicit no-op.2. Battery floor (opt-in, default 15%)
On battery, keep-awake is released at/below a threshold so the Mac can sleep before the battery fully drains — which, in the remote-use case, would also drop your access. It re-arms on AC, with hysteresis so it doesn't oscillate as the percentage jitters near the threshold.
Implementation notes:
BatteryReaderreads the power source via IOKit (IOPSCopyPowerSourcesInfo) — no subprocess.BatteryFloorPolicywith 10 unit tests covering the floor boundary, the hysteresis latch, and the fail-safe cases (unreadable power → stay awake/reachable; on AC → keep; unknown percentage → keep).Both are surfaced in the status menu (mode items + a Battery floor submenu) and the settings window, following the existing preference + localization patterns.
One small responsiveness change: the poll timer runs in
.defaultinstead of.common, so its periodicpmset -gverification never spawns a subprocess while a menu is being tracked.Testing
swift test— all 24 tests green (14 existing + 10 new).Notes