Skip to content

v1.1.2: Hardware Clamshell Detection & Zero-Polling Power Events

Choose a tag to compare

@himanzero himanzero released this 06 Nov 05:44
· 4 commits to main since this release

What's Changed in v1.1.2

⚡️ Critical Fix: Unplugging AC with Lid Closed Now Reliably Sleeps

Previously, when the laptop lid was closed while on AC power and then unplugged, a kernel-level race condition in macOS powerd would drop the clamshell sleep evaluation before disablesleep 0 finished executing, leaving the Mac awake indefinitely with the lid closed.

  • IOKit Clamshell Detection: Native query of IOPMrootDomain's AppleClamshellState directly via IOKit (<0.2ms latency, zero Mach port leak).
  • Native Demanded Sleep: Calls unprivileged native IOPMSleepSystem immediately upon AC disconnect if the lid is closed, instantly triggering sleep and lock screen engagement.

🍃 0.0% Idle CPU: Zero-Polling Event-Driven Architecture

  • Darwin Notification Listener: Completely eliminated the 4.0-second background polling timer in favor of macOS system-wide com.apple.powermanagement.preferencechanged Darwin notifications. Telemetry updates instantly upon external pmset changes with 0.0% background idle CPU.
  • On-Demand Privilege Check: Decoupled sudo -n -l validation from background loops; privilege checks now execute strictly on-demand when opening the status panel or dashboard.

🛡 Dual Lifecycle Recovery

  • Safe App Exit (applicationWillTerminate): Synchronously clears disablesleep 1 back to 0 on clean application quit to prevent lingering sleep-disabled states.
  • Boot-time Abnormal Exit Recovery: Automatically detects and restores disablesleep 0 if the app starts on battery power with lingering disabled sleep from a previous hard crash or power-off.

🌐 i18n & Quality Assurance

  • Fully localized new telemetry and log entries across all 5 supported languages (en, zh-Hans, zh-Hant-TW, zh-Hant-HK, ja).
  • Expanded automated unit test suite (Tests/SleepControlTests/ActivityLogTests.swift) to 17 test cases, passing in 0.024s.

📦 Assets & Verification

Asset Size SHA-256 Checksum
SleepControl-v1.1.2-macos.zip 3.4 MB f9fbd6af15fef73d6b84a1a5ea1c8b8d9581a4f5c3fb07cb552be7b4079049c2

Installation Note

If macOS Gatekeeper blocks opening the app on first launch, run:

xattr -cr /Applications/SleepControl.app