Skip to content

Warn when battery drains faster than usual#15

Open
kawaiier wants to merge 4 commits into
homm:mainfrom
kawaiier:feature/abnormal-drain-warning
Open

Warn when battery drains faster than usual#15
kawaiier wants to merge 4 commits into
homm:mainfrom
kawaiier:feature/abnormal-drain-warning

Conversation

@kawaiier

Copy link
Copy Markdown

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:

  • BatteryTrackerSession keeps a sliding window of recent readings (~15 min) for rate calculation.
  • The engine compares the recent drain rate against the session average and sets an abnormalDrainDetected flag when the recent rate is sustained above the baseline.
  • Fast-drain warnings caused by High Power Mode are suppressed, since that drain is expected.
  • The notification UX is intentionally calm: deferred consent and a single toggle to control it.

Commits

  • Warn when battery drains faster than usual
  • Suppress fast-drain warnings caused by High Power Mode
  • Refine drain-warning UX: calmer tone, deferred consent, actions
  • Collapse drain-warning notification UI into one toggle

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.

kawaiier and others added 4 commits June 26, 2026 20:45
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Warn when battery is draining faster than usual

1 participant