Skip to content

awake: use native IOKit power assertion on macOS (drop caffeinate)#9

Merged
peterdsp merged 1 commit into
mainfrom
feat/native-iokit-keepawake
Jul 8, 2026
Merged

awake: use native IOKit power assertion on macOS (drop caffeinate)#9
peterdsp merged 1 commit into
mainfrom
feat/native-iokit-keepawake

Conversation

@peterdsp

@peterdsp peterdsp commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Keep Awake spawned /usr/bin/caffeinate on 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 API caffeinate itself wraps. No subprocess, no entitlements, works inside the sandbox.

  • PreventUserIdleDisplaySleep keeps display + system awake; PreventUserIdleSystemSleep when the user allows display sleep.
  • Timed sessions end via KeepAwake's deadline (same mechanism as the Windows backend); the assertion is released on Drop.
  • Minimal raw FFI to CoreFoundation + IOKit frameworks - no new crate dependencies.

Verification

Empirically confirmed with pmset -g assertions: IOPMAssertionCreateWithName returns 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).

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.
Copilot AI review requested due to automatic review settings July 8, 2026 15:12
@peterdsp
peterdsp merged commit 0581493 into main Jul 8, 2026
@peterdsp
peterdsp deleted the feat/native-iokit-keepawake branch July 8, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants