Skip to content

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

Description

@kawaiier

Motivation

StillCore already tracks the battery session and shows how much was used since the last charge (e.g. "15% over 2 hours"). But this is retrospective — you only notice something's off once you already lost a lot of charge.

It would be useful to get an early warning while it's happening: if the battery has been discharging noticeably faster than usual over, say, the last 15 minutes, surface that to the user. That way you can catch runaway processes, heavy background tasks, or thermal throttling before the charge actually drops.

Suggested approach

Looking at the code, I think this fits naturally into the existing architecture:

  • BatteryTrackerEngine already polls every 5 seconds, so the data for rate calculation is available.
  • BatteryTrackerSession could grow a sliding window of recent readings (timestamp, capacityMah) bounded to ~15 minutes (~180 entries at 5s polling — around 1.5 KB).
  • The engine would then compare:
    • recent drain rate (last 15 min) vs.
    • session average drain rate (entire session so far).
  • When recent rate exceeds, say, 1.5× the session average for a sustained period, set an abnormalDrainDetected flag in BatteryTrackerState.
  • The main app would then show a macOS notification to surface this to the user.

I deliberately suggest a within-session baseline first (rather than cross-session history) because it's minimally invasive to the current schema and good enough as a first version. Cross-session history could be a follow-up if useful.

Open questions

A few things that probably make sense to discuss before implementing:

  1. Threshold — what multiplier (1.5× / 2×) and sustained duration feels right? Maybe user-configurable later, but the default should avoid noisy false positives.
  2. Energy mode interaction — with the recently added energy mode select, High Performance mode naturally drives higher drain. Should the check be suppressed or adjusted based on the active mode?
  3. Session maturity — for the first ~30 minutes of a session the session-average baseline is unreliable. Should we require a minimum session length before emitting the warning?
  4. UX — macOS notification, a persistent visual indicator in the menu bar / battery UI, or both?

Scope

For a first PR I'd aim at roughly:

  • Sliding capacity history on BatteryTrackerSession
  • Rate calculation + anomaly flag in BatteryTrackerEngine
  • Read/display in the main app (notification)
  • Respect the energy mode so High Performance doesn't trigger false positives

Happy to take a stab at an implementation once there's rough agreement on direction, or break it into smaller steps if preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions