Guidelines for AI coding agents working on this project.
Awake is a macOS menu bar app that prevents the system from sleeping. It uses IOKit power assertions to keep the Mac awake and Carbon APIs for global keyboard shortcuts.
Awake/
├── main.swift # App entry point (pure AppKit, no SwiftUI @main)
├── AppDelegate.swift # Menu bar UI and app lifecycle
├── AwakeManager.swift # IOKit power assertion management
├── HotKeyManager.swift # Global hotkey registration (Carbon)
└── Assets.xcassets/ # App icons
- No SwiftUI @main: The app uses
main.swiftwith manualNSApplicationsetup. SwiftUI's@mainwithNSApplicationDelegateAdaptordoesn't reliably initialize menu bar items. - Menu bar only:
NSApp.setActivationPolicy(.accessory)hides the dock icon. - IOKit for sleep prevention: Uses
IOPMAssertionCreateWithNameandIOPMAssertionRelease. - Carbon for global hotkeys: Uses
RegisterEventHotKeysinceNSEvent.addGlobalMonitorForEventsrequires accessibility permissions.
cd /Users/sid/Projects/Awake
xcodebuild -scheme Awake -configuration Release buildThe built app will be in ~/Library/Developer/Xcode/DerivedData/Awake-*/Build/Products/Release/Awake.app.
Edit setupMenu() in AppDelegate.swift. Create an NSMenuItem, set its target to self, and add an @objc handler method.
Edit HotKeyManager.swift. Modify keyCode and modifiers. Key codes are defined in Carbon's Events.h. Current shortcut is Cmd+Shift+A.
Edit AwakeManager.swift. Add a new case to the Mode enum with the appropriate kIOPMAssertionType* constant.
- IOKit.framework: Sleep prevention APIs
- Carbon.framework: Global hotkey APIs
- Cocoa.framework: UI (implicit)
Manual testing only. Key scenarios:
- Toggle via menu and verify icon changes
- Toggle via global hotkey (⌘⇧A) from another app
- Set a duration and verify auto-disable
- Switch modes and verify behavior
- Quit app and verify sleep prevention stops