awake: use native IOKit power assertion on macOS (drop caffeinate)#9
Merged
Conversation
Keep Awake spawned /usr/bin/caffeinate on macOS. Under the App Sandbox (the Mac App Store build) spawning a subprocess and having it hold a power assertion is unreliable, so the feature could silently fail to keep the Mac awake there. Replace it with a direct IOKit power-management assertion (IOPMAssertionCreateWithName) held in-process - the same public API that caffeinate itself wraps. No subprocess, no entitlements, works inside the sandbox. PreventUserIdleDisplaySleep keeps display+system awake; PreventUserIdleSystemSleep is used when the user allows display sleep. Timed sessions end via KeepAwake's deadline (like the Windows backend); the assertion is released on Drop. Verified with pmset: the assertion shows as "klipa keep awake" while held and clears on release. Windows/Linux backends unchanged.
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.
Keep Awake spawned
/usr/bin/caffeinateon macOS. Inside the App Sandbox (the Mac App Store build), spawning a subprocess and having it hold a power assertion is unreliable, so the feature could silently fail to keep the Mac awake there. (This is also what App Review's Guideline 2.1 question about the feature was probing.)Change
Replace the subprocess with a direct IOKit power-management assertion (
IOPMAssertionCreateWithName) held in-process - the same public APIcaffeinateitself wraps. No subprocess, no entitlements, works inside the sandbox.PreventUserIdleDisplaySleepkeeps display + system awake;PreventUserIdleSystemSleepwhen the user allows display sleep.KeepAwake's deadline (same mechanism as the Windows backend); the assertion is released onDrop.Verification
Empirically confirmed with
pmset -g assertions:IOPMAssertionCreateWithNamereturns success, the assertion shows as "klipa keep awake" while held, and clears on release. Builds clean on default /mas/mas weather; 8 tests pass; no clippy warnings. Windows/Linux backends unchanged.Ships in the next release; not required for the in-review 0.4.4 (that's answered via Resolution Center).