Skip to content

feat: reflect Low Power Mode in the menu bar battery icon - #22

Merged
srimanachanta merged 3 commits into
srimanachanta:mainfrom
DinanathDash:feat/low-power-mode-icon
May 16, 2026
Merged

feat: reflect Low Power Mode in the menu bar battery icon#22
srimanachanta merged 3 commits into
srimanachanta:mainfrom
DinanathDash:feat/low-power-mode-icon

Conversation

@DinanathDash

Copy link
Copy Markdown
Contributor

This pull request adds support for detecting and displaying macOS Low Power Mode status in the battery indicator. The main changes include tracking Low Power Mode in the view model, observing system notifications for changes, and updating the battery indicator's color when Low Power Mode is enabled.

Low Power Mode support:

  • Added a new property isLowPowerModeEnabled to MenuViewModel to track the current Low Power Mode status, and initialized it using ProcessInfo.processInfo.isLowPowerModeEnabled.
  • Implemented startObservingPowerMode() in MenuViewModel to listen for .NSProcessInfoPowerStateDidChange notifications and update isLowPowerModeEnabled accordingly. This ensures the app responds to system changes in Low Power Mode. [1] [2]

UI updates:

  • Updated StatusBarContentView to pass the new isLowPowerModeEnabled property to BatteryIndicatorView, enabling the UI to reflect Low Power Mode status.
  • Modified BatteryIndicatorView to accept the isLowPowerModeEnabled parameter and change the battery fill color to yellow when Low Power Mode is active.

Closes #14

@DinanathDash

Copy link
Copy Markdown
Contributor Author

"Hey! @srimanachanta Just a quick heads-up: I've submitted 6 modular PRs (PRs #17 through #22) to break down a larger set of features and make the review process much easier for you.

Because a few of these PRs touch the same core files (like MenuViewModel.swift and BatteryIndicatorView.swift), merging one might cause merge conflicts in the others. Please review and merge them in whatever order makes the most sense to you!

Once you merge a PR, if GitHub flags any of my remaining open PRs with conflicts, just let me know or leave them be—I will actively monitor the repo and locally rebase my remaining branches against your updated main to resolve the conflicts for you. You won't have to resolve the conflicts yourself!
For the easiest path with the least overlap, my suggested review/merge order is:

  1. Fix Homebrew install command by removing --no-quarantine flag #21 (Fix Homebrew install) - Standalone.
  2. Add app icons for multiple sizes and update Contents.json #19 (App icons) - Standalone.
  3. Refactor time remaining calculation and integrate estimator #18 (Refactor time remaining)
  4. Add battery percentage display option in menu bar icon #17 (Battery percentage in menu bar)
  5. feat: reflect Low Power Mode in the menu bar battery icon #22 (Low Power Mode icon) - builds slightly on the view from Add battery percentage display option in menu bar icon #17.
  6. Add outgoing power visualization to Sankey diagram #20 (Outgoing power Sankey diagram) - heaviest changes.

Thanks for maintaining Stasis! Let me know if you need any adjustments.

Comment thread Stasis/ViewModels/MenuViewModel.swift Outdated
Comment thread Stasis/ViewModels/MenuViewModel.swift
Comment thread Stasis/ViewModels/MenuViewModel.swift
Comment thread Stasis/Views/BatteryIndicatorView.swift
Comment thread Stasis/Views/BatteryIndicatorView.swift
- Remove TOCTOU gap: seed isLowPowerModeEnabled inside startObservingPowerMode() instead of stored-property default
- Pass object: ProcessInfo.processInfo to notification sequence to avoid waking on unrelated posts
- Hop mutation back to MainActor.run in observer task
- Cancel powerModeObservation in deinit
- Add comment clarifying red (critical) takes priority over yellow (low power) -- intentional behavior
- Expand #Preview with Low Power Mode section (yellow for normal, red for critical <=10%)
@DinanathDash

Copy link
Copy Markdown
Contributor Author

Hey @srimanachanta! I've addressed all the review comments. Here's a summary of what was updated:

MenuViewModel.swift

  • TOCTOU fix: Removed the ProcessInfo.processInfo.isLowPowerModeEnabled call from the stored-property default. The initial value is now seeded at the top of startObservingPowerMode() so the "read current state + subscribe" logic lives in one place.
  • MainActor safety: The mutation inside the observer task is now explicitly hopped to MainActor.run { } to ensure thread-safe updates.
  • Notification filter: Added object: ProcessInfo.processInfo to the notification sequence so we only wake on relevant power state changes.
  • Task cleanup: powerModeObservation is now canceled in deinit alongside the other tasks.

BatteryIndicatorView.swift

  • #Preview updated: Added a Low Power Mode section to the preview — shows yellow for normal battery levels and red for critical (≤10%), visually confirming the priority behavior.
  • Priority clarification: Added an inline comment to fillColor making it explicit that critical (red) intentionally takes priority over Low Power Mode (yellow) — the logic order was already correct.

Let me know if anything needs further adjustment!

@srimanachanta srimanachanta changed the title Display orange battery icon for Low Power Mode feat: reflect Low Power Mode in the menu bar battery icon May 16, 2026
@srimanachanta
srimanachanta merged commit e6eeeac into srimanachanta:main May 16, 2026
@DinanathDash
DinanathDash deleted the feat/low-power-mode-icon branch May 17, 2026 04:17
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.

Orange icon if low power mode is on

2 participants