Warn when battery drains faster than usual#15
Open
kawaiier wants to merge 4 commits into
Open
Conversation
Add an early warning for abnormally fast battery discharge (issue homm#14). The helper keeps a ~15 min sliding window of capacity readings on the session and flags abnormal drain when the recent rate is >=1.5x the session average, gated on session maturity (>=30 min), a minimum window span (>=5 min of data), and a homogeneous energy mode across the window so toggling Low Power Mode doesn't trigger false positives. The app reads the flag, posts a macOS notification on the rising edge (with a 30 min cooldown), shows a small warning marker in the session status text, and exposes a "Warn on Fast Battery Drain" toggle in the energy mode menu (default on). New persisted fields are Optional so existing state JSON still decodes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extend the energy-mode guard to cover High Power Mode (16" MacBook Pro with Max chips), which intentionally raises drain and could otherwise trip a false "abnormal drain" warning when toggled mid-session. High Power Mode has no public API, so the helper reads it from the `powermode` field of `pmset -g custom` (Battery Power section), throttled to once per 60s to keep the daemon light. Detection fails safe: anything other than an explicit `powermode 2` -- including the field being absent on the vast majority of Macs that lack the feature -- reads as not-high, so those Macs behave exactly as before. The per-reading highPowerMode is Optional for backward-compatible decode, and the window-homogeneity check now requires both Low Power and High Power state to be constant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make the abnormal-drain warning feel like a calm system advisory rather than a utility alert. - Defer notification permission request until the user enables the warning or a warning first needs to be shown, instead of prompting at launch. - Drop notification sound (banner only) for a calmer advisory tone. - Reword copy to "Battery Is Draining Quickly" / "StillCore noticed higher power use over the last few minutes." - Rename menu item to "Notify When Battery Drains Quickly". - Add "Open Activity Monitor" and "Battery Settings" notification actions via a registered category. - Reflect denied notification permission in the energy menu with an explanation and an "Open Notification Settings…" shortcut.
The battery menu showed three items for the drain warning: the toggle, a "Notifications are turned off in System Settings" label, and an "Open Notification Settings…" action. Replace them with a single toggle whose checkmark reflects whether the warning can actually reach the user. - Default the warning to off so the user opts in explicitly. - Enabling requests notification permission and only checks the item if granted; if previously denied, route to System Settings instead. - Gate the checkmark on the live authorization status so it shows off again when notifications are revoked. - Have requestNotificationAuthorization report whether permission was granted so the menu can reflect the result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14
Summary
Adds an early warning when the battery is discharging noticeably faster than usual within the current session, surfaced as a macOS notification.
Approach
Implements the within-session baseline suggested in the issue:
BatteryTrackerSessionkeeps a sliding window of recent readings (~15 min) for rate calculation.abnormalDrainDetectedflag when the recent rate is sustained above the baseline.Commits
Notes
Uses a within-session baseline rather than cross-session history, as suggested in the issue — cross-session history could be a follow-up if useful.