How az-code-lab/ampere works
Ampere is a macOS menu-bar battery monitor and charge manager. Its principal workflow samples battery and power state, applies automatic or user-requested charging policy, and uses a privileged helper to change charging or sleep-related system state; the app then presents live status and controls. Other documented branches include registration, updates, keep-awake, and helper lifecycle cleanup. The excerpts establish key calls but omit much of the app UI and monitoring implementation, so uncertain subsystem wiring is left out.
Main entry points: App.swift Menu Bar UI · BatteryInfo.swift Charge Policy · SMCWriter/main.swift SMC Writer · Ampere/main.swift App Launch
Components 17
Menu Bar App
- App Launch
Sources/Ampere/main.swift - Menu Bar UI
Sources/Ampere/App.swift
Charge Management
- Battery Monitor
Sources/Ampere/BatteryInfo.swift - Charge Policy
Sources/Ampere/BatteryInfo.swift
Privileged Helper
- SMC Writer
Sources/SMCWriter/main.swift - Native Charge Limit
Sources/Shared/NativeChargeLimit.swift - Sleep State
Sources/Shared/PmsetState.swift - Helper Setup
Sources/Ampere/HelperSetup.swift - Cleanup Daemon
Sources/Shared/CleanupDaemon.swift - Helper Uninstall
Sources/Shared/HelperUninstall.swift
App Services
- Registration
Sources/Ampere/Registration.swift - In-App Updater
Sources/Ampere/Updater.swift - Keep Awake
Sources/Ampere/BatteryInfo.swift
Other components
- Mac User
- macOS Power APIs
- License Service
- Homebrew Cask
Connections 22
- Mac User → Menu Bar UI: controls
- App Launch → Menu Bar UI: launches
- Menu Bar UI → Battery Monitor: shows status
- Battery Monitor → macOS Power APIs: samples power
- Menu Bar UI → Charge Policy: sets modes
- Battery Monitor → Charge Policy: feeds state
- Charge Policy → SMC Writer: requests writes
- SMC Writer → macOS Power APIs: sets SMC state
- Charge Policy → Native Charge Limit: uses charge limit
- Native Charge Limit → macOS Power APIs: updates limit
- Charge Policy → Sleep State: manages sleep
- Sleep State → macOS Power APIs: changes sleep settings
- App Launch → Helper Setup: sets up helper
- Menu Bar UI → Keep Awake: toggles assertion
- Keep Awake → macOS Power APIs: holds awake
- Menu Bar UI → Registration: registers
- Registration → License Service: verifies license
- Menu Bar UI → In-App Updater: checks and installs
- In-App Updater → Homebrew Cask: checks release
- App Launch → Cleanup Daemon: registers cleanup
- Cleanup Daemon → SMC Writer: invokes helper
- SMC Writer → Helper Uninstall: cleans artifacts