sapsaldog/open-caffeine
Tentang
Open-source macOS menu-bar utility with timers, hotkeys, battery protection, and automatic updates.
Pengembangan web dan aplikasiYang dapat Anda lakukan
- Timed sessions from 5 minutes to 8 hours, plus a keep-awake-forever mode
- Separate control over display sleep and system sleep
- Display Off: turn the screens off right away while the Mac keeps working
- Stay awake with the lid closed (MacBooks, optional): keep working with the lid shut, with automatic safety cutoffs
Pertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- 0
- dalam 15 hari
- +1
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
AsliOpen Caffeine
An open-source macOS menu-bar utility that keeps your Mac awake for a chosen duration. Built for Apple Silicon and macOS 26 (Tahoe) or newer with a native Liquid Glass UI.
🏆 Ranked #10 Product of the Day on Product Hunt
Features
- Timed sessions from 5 minutes to 8 hours, plus a keep-awake-forever mode
- Separate control over display sleep and system sleep
- Display Off: turn the screens off right away while the Mac keeps working
- Stay awake with the lid closed (MacBooks, optional): keep working with the lid shut, with automatic safety cutoffs
- Live menu-bar countdown and a customizable global shortcut
- Optional battery threshold that stops an active session
- Launch-at-login, Dock visibility, appearance, and menu-bar icon preferences
- EdDSA-verified automatic updates through Sparkle
Install
Download the latest archive from GitHub Releases, extract it, and move Open Caffeine.app to /Applications.
Releases are signed with Developer ID and notarized by Apple (since 1.1.0), so macOS opens them normally. Sparkle updates are also EdDSA-signed and checked before they install. (1.0.x releases weren't notarized: on first launch macOS asked for System Settings → Privacy & Security → Open Anyway.)
Build from source
Prerequisites:
brew install xcodegen swiftlint
Generate and build:
xcodegen generate
xcodebuild -project OpenCaffeine.xcodeproj -scheme OpenCaffeine -configuration Release build
The app bundle is in ~/Library/Developer/Xcode/DerivedData/OpenCaffeine-*/Build/Products/Release/Open Caffeine.app.
Releasing updates (Sparkle)
Auto-updates use Sparkle. SUFeedURL points at
appcast.xml in this repo (served via raw.githubusercontent.com), and updates
are EdDSA-signed with the private key in your login keychain (public key is in
Info.plist as SUPublicEDKey).
To cut a release:
- Bump
MARKETING_VERSION/CURRENT_PROJECT_VERSIONinproject.yml. - Run
Scripts/release.sh— builds Release, signs it with Developer ID, has Apple notarize it, zips, EdDSA-signs, and regeneratesappcast.xml. It needs a "Developer ID Application" certificate of the team and notarytool credentials saved asopen-caffeine-notary; the top of the script shows how to set up both. - Commit the version bump,
CHANGELOG.md, andappcast.xmlasRelease v<version>, tag that commitv<version>, push the tag, and create the GitHub release from it withdist/Open-Caffeine-<version>.zipattached. - Push
main: the committedappcast.xmlis whatSUFeedURLserves.
The Updates preferences tab ("Check Now" + automatic checks) drives the real Sparkle updater against that feed.
Run tests
xcodebuild -project OpenCaffeine.xcodeproj -scheme OpenCaffeine -destination 'platform=macOS' test
Coverage
Every logic file must keep 100% line coverage. The gate runs the suite with
coverage and fails if any non-excluded file under OpenCaffeine/ or Shared/ drops below 100%:
Scripts/coverage-gate.sh
It is enforced on git push via a pre-push hook. Enable it once per clone:
git config core.hooksPath Scripts/hooks
Bypass a single push with git push --no-verify.
What's excluded and why. Only UI/AppKit/system shells are exempt — SwiftUI view
bodies, the @main entry, AppDelegate/MenuBarController wiring, NSAlert/NSWindow
presenters, and thin IOKit/SMAppService/KeyboardShortcuts/NSWorkspace adapters. Their
decision logic has been extracted into separately-tested types (GeneralSettingsActions,
BatteryThresholdFormatter, MenuBarIconModel, CustomDurationParser, AppLaunchLogic,
BatterySnapshotParser, the *Providing/*Controlling seams). The full, justified list
lives in Scripts/coverage_check.py — new source files are not exempt by default, so
adding one forces a conscious choice: test it, or extract its logic and list the shell.
Manual QA Checklist
- Start for 5 min → countdown begins at 5:00 next to icon.
- After 5 min, icon reverts and sleep works again.
- Forever → still awake after 30 min idle.
- Forever + "Keep the screen on" ON (default) → screen stays on past the display-sleep timer.
- "Keep the screen on" OFF → display may sleep, but the Mac stays awake.
- Toggling "Keep the screen on" during an active session takes effect immediately.
- Hotkey toggles caffeine on/off.
- Start-at-login toggle survives reboot.
- Show-in-dock toggle takes effect immediately.
- Battery threshold triggers stop (use
pmsetif hard to drain). -
pmset -g assertionsshows bothPreventUserIdleDisplaySleepandPreventUserIdleSystemSleepwhile active (only…SystemSleepwhen "Keep the screen on" is off). - About menu shows custom Open Caffeine panel.
- Screensaver button launches the screen saver.
- Desktop Mac (no lid) → no "Stay awake with lid closed" switch in the panel.
- MacBook: turning on "Stay awake with lid closed" explains itself once, then opens System Settings to allow the helper; after allowing, the caption disappears.
- MacBook, session running, lid mode on →
pmset -g | grep SleepDisabledshows1; closing the lid keeps the work running and the built-in display dark. Stopping the session (or turning the switch off) →0. - MacBook, lid mode active → force-quit Open Caffeine →
SleepDisabledgoes back to0within seconds. - MacBook on battery below 20% → caption says it's paused and
SleepDisabledis0; plugging in brings it back. - MacBook, lid mode on, 5-minute session, lid closed (no external display) → when the session ends the Mac goes to sleep (
pmset -g log | grep -i " Sleep "). - Display Off → panel closes, the displays turn off about a second later, and the Mac stays awake (the countdown keeps running). When idle, it first starts a session with the selected duration.
- Custom duration prompt accepts minutes input.
- Switching Appearance in Preferences changes the menubar icon immediately.
Project layout
OpenCaffeine/
App/ # @main, AppDelegate (bootstrap)
MenuBar/ # NSStatusItem controller, menu builder, countdown formatter, custom-duration prompt
Services/ # SleepAssertion, CaffeineSession, DisplayOffAction, LidSleepController, HotKeyService, BatteryMonitor, LoginItemManager, ScreenSaverLauncher
Settings/ # SwiftUI Preferences scene + tabs
Models/ # CaffeineDuration, SessionState, MenuBarIconStyle, LidSleepState
Resources/ # Assets.xcassets, About panel
OpenCaffeineHelper/ # Root helper for lid mode (runs `pmset -a disablesleep`) + its launchd plist
Shared/ # XPC protocol + trust rules shared by the app and the helper
OpenCaffeineTests/ # XCTest suites + Mocks/
docs/superpowers/ # Spec + plan that drove this build
project.yml # XcodeGen project definition (single source of truth — .xcodeproj is regenerated, not committed)
.swiftlint.yml # Lint config (file_length 500 hard cap)
How lid mode works
macOS sleeps a MacBook when its lid closes no matter which power assertions an
app holds, so "Stay awake with lid closed" needs pmset -a disablesleep, which
only root can set. Open Caffeine ships a small helper for that:
- It is registered with
SMAppService.daemonand only runs after you allow it in System Settings › General › Login Items & Extensions. - It can run exactly two commands:
/usr/bin/pmset -a disablesleep 1|0, and/usr/bin/pmset sleepnowright after sleep comes back while the lid is shut. - It only accepts connections from Open Caffeine signed by the same team.
- A change only counts once both the saved setting (
pmset -g) and the kernel (IOPMrootDomain'sSleepDisabled) show it:pmsetcan print an error and still exit 0, and the two are applied separately. - Sleep is one system-wide setting: it stays disabled while any Open Caffeine connection holds it and comes back when the last one lets go — asks, quits, crashes, or is force-quit. A restore that fails is retried until it works.
- Before disabling sleep it writes a marker file, removed only once sleep is
confirmed back. If the helper itself dies, launchd restarts it (
KeepAlive) and the restart puts sleep back; the same happens at boot. If launchd stops the helper (unregistered, shutdown), it refuses new requests and retries putting sleep back, exiting with an error if it can't (so launchd tries again). - If the helper goes away, the app asks a new one for the hold when it still wants it, warns while the kernel says sleep is still disabled, and — if it keeps running with the lid shut (approval revoked) — puts the Mac to sleep itself.
- macOS decides about sleep at the moment the lid closes. So whenever lid mode ends while the lid is still shut (session over, low battery, heat, quit, or crash), the Mac is put to sleep right away — unless macOS keeps it awake for an external display on power (closed-display mode).
- The app only asks for it while a session is running and the switch is on, and lets the Mac sleep below 20% battery (on battery power) or when macOS reports serious heat. When the lid closes with no external display, it also turns the built-in display off.
The helper needs a team-signed build. Releases are signed with Developer ID, so
lid mode works in them; it is not part of the Mac App Store version (sandboxed
apps may not request root). Build your own team-signed copies with the hardened
runtime and without get-task-allow, so other code can't borrow the app's
identity to talk to the helper:
xcodebuild … -configuration Release \
CODE_SIGN_IDENTITY="<your signing identity>" DEVELOPMENT_TEAM=<team> CODE_SIGN_STYLE=Manual \
ENABLE_HARDENED_RUNTIME=YES CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO build
Ad-hoc builds can't use the hardened runtime: library validation then refuses the
embedded Sparkle.framework, which has no team ID either.
Architecture
See docs/superpowers/specs/2026-05-28-open-caffeine-design.md.
License
MIT © Open Caffeine contributors.
Jelajahi proyek terkait
Memuat…