Repository navigation
Restore owned sleep state on unplug, quit and unexpected termination - #12
Open
future-gareth wants to merge 1 commit into
Open
future-gareth wants to merge 1 commit into
future-gareth wants to merge 1 commit into
Conversation
future-gareth
marked this pull request as ready for review
October 22, 2026 16:52
This branch has not been deployed
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 does this change?
Fixes #8. Quitting while ON previously left the global sleep-disabled flag set after the app's battery floor and timer stopped. Normal quit now restores Sleepless-owned state; crashes and force-quits are handled independently.
The lease/watchdog design is adapted from mmavko/Sleepless. No wholesale merge or unrelated CLI, activity tracking or thermal features are included. Both repositories carry the same MIT licence and Adam Boudjemaa copyright notice, retained unchanged.
Why the watchdog must be independent
Issue #8 concerns a system-global setting whose lifetime exceeds the GUI process. A normal
applicationShouldTerminate/applicationWillTerminatehandler covers orderly Quit, but cannot run after SIGKILL/Force Quit, and cannot be relied on after a crash. An in-process timer, signal handler or shutdown callback therefore cannot provide the required unexpected-termination recovery; checking only on the next launch would also leave sleep disabled until someone reopens the app.The separate per-user LaunchAgent runs a copied helper independently of the GUI. The GUI must continually renew its short ownership lease; when renewal stops, the watchdog restores recorded Sleepless-owned state without waiting for another app launch. The copied helper also survives app-bundle deletion. Arming is blocked until the watchdog has demonstrated health and both exact sleep permissions are available. This complements immediate normal-quit cleanup; it does not replace it or guarantee recovery after permission revocation, logout or agent failure.
Maintainer action required: Homebrew uninstall integration
Before distributing this version through Homebrew, update the external tap's uninstall action to invoke
Sleepless.app/Contents/Resources/uninstall.shas the logged-in user before deleting the bundle. If restoration fails, abort removal and retain the watchdog and grant. A cask action that only quits/deletes the app does not remove the separately copied watchdog or scoped sudoers grant. The uninstaller fences new arms, restores owned state and verifies normal sleep before removing recovery and privileges. Only its fixed grant-removal command requires native administrator authorization; do not run the entire helper/uninstaller as root.The tap is outside this repository, so this PR does not implement that hook. This is a distribution prerequisite for complete Homebrew removal and needs coordinated maintainer review. The retained watchdog provides lease recovery after bundle deletion while its permissions and login session remain available; it is not a substitute for complete uninstall integration.
How was it tested?
bash tests/run.sh: 104 safety assertions, 5 lifecycle integration scenarios and 3 native read-only checks passed. Covers power removal/return/opt-out, normal exit, expiry, process death, real-process concurrency, ownership, failed permissions/commands/read-back, and failure-preserving lifecycle behavior.bash build.sh: zero-warning arm64/macOS 26 build passed. App and helper strict signature checks passed; both Mach-O minimums and Info.plist are 26.0. Required resources and licence verified.TARGET=arm64-apple-macos13.0 bash build.sh build/compatibility: build and strict app/helper signature checks passed; minimum 13.0 verified. Compile validation only; no macOS 13 runtime claim.No new privileged installation or sleep-setting mutation was performed during contribution preparation. These final checks build and test without modifying the installed app.
Remaining limitations / maintainer review
Checklist