Skip to content

Add battery percentage display option in menu bar icon - #17

Merged
srimanachanta merged 7 commits into
srimanachanta:mainfrom
DinanathDash:add-battery-percentage-inside-icon
May 17, 2026
Merged

Add battery percentage display option in menu bar icon#17
srimanachanta merged 7 commits into
srimanachanta:mainfrom
DinanathDash:add-battery-percentage-inside-icon

Conversation

@DinanathDash

Copy link
Copy Markdown
Contributor

This pull request introduces new customization options for how the battery percentage is displayed in the menu bar icon, allowing users to choose whether the percentage appears inside the icon when on battery, and/or outside the icon when powered. It updates the settings UI, underlying logic, and localization strings to support these options.

Battery Percentage Display Customization:

  • Added two new user defaults: showBatteryPercentageInsideIconOnBattery and showBatteryPercentageOutsideIconWhenPowered, enabling users to control whether the battery percentage appears inside the icon while on battery and outside the icon when plugged in, respectively.
  • Updated StatusBarContentView and BatteryIndicatorView to respect these new settings, including logic to determine when to show the percentage inside or outside the icon based on charging state and user preferences. [1] [2] [3] [4]

Settings UI Enhancements:

  • Modified GeneralSettingsView to include toggles for the new settings, with appropriate enabling/disabling logic based on related settings. Updated the settings section description to reflect the new options. [1] [2]
Screenshot 2026-05-13 at 2 59 12 PM

Localization Updates:

  • Added new localization string keys for the new settings and updated descriptions to match the new functionality. [1] [2] [3]

Closes #6

@DinanathDash

Copy link
Copy Markdown
Contributor Author

@srimanachanta Kindly review this MR.

@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/Views/BatteryIndicatorView.swift Outdated
if shouldShowOutsidePercentage {
Text("\(batteryLevel)%")
.font(.system(size: 10, weight: .medium))
.monospacedDigit()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was monospacedDigit removed? This will lead to UI shifts on percentage changes. This is a regression

if showPercentage {
if shouldShowOutsidePercentage {
Text("\(batteryLevel)%")
.font(.system(size: 10, weight: .medium))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for changing the font from 10 medium → NSFont.menuBarFont(ofSize: 11)? It changes the visual balance against the 12pt battery icon, and the weight drop reduces legibility at menu bar size.

Comment thread Stasis/Views/BatteryIndicatorView.swift Outdated
Comment thread Stasis/Views/BatteryIndicatorView.swift Outdated
Comment on lines +134 to +137
.foregroundStyle(.white)
.shadow(color: .black, radius: 0.5)
.shadow(color: .black, radius: 0.5)
.shadow(color: .black, radius: 0.5)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be moved back to the group level once previous comment is addressed.

Comment thread Stasis/Views/Settings/GeneralSettingsView.swift Outdated
Comment thread Stasis/Views/Settings/GeneralSettingsView.swift Outdated
Comment thread Stasis/L10n/Localizable.xcstrings Outdated
@DinanathDash
DinanathDash force-pushed the add-battery-percentage-inside-icon branch from b5b5bd6 to 88b6032 Compare May 16, 2026 09:50
@DinanathDash

DinanathDash commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

@srimanachanta I've applied the feedback from your review. Replaced the toggles with a Picker, removed the obsolete outline shadow with the 3 layered shadows, changed the font to Font.system, adding back .monospacedDigit(), and the obsolete strings from Localizable.xcstrings was auto-generated on build..

DinanathDash and others added 7 commits May 16, 2026 18:20
Restructures the inside-icon mode as a punch-out battery indicator:

- Fill colors by state:
    critical  → red    (white foreground)
    LPM       → yellow (black foreground)
    charging  → green  (white foreground)
    otherwise → .primary, foreground knocked out to the menu bar
- Percentage text sits inside the body with a small charging glyph
  (bolt / rotated powerplug) to its right, both sized to fit within
  the battery body rather than overlaying it.
- Knockout uses .blendMode(.destinationOut) within a compositingGroup
  so the digits show the menu bar background through the fill in the
  normal/discharging case.
- Hidden / outside-icon modes keep the original centered-glyph layout.
Use plain case names as rawValue so persisted preferences are stable
across label changes, and replace the runtime LocalizedStringKey lookup
with explicit Text literals so the strings are extractable for
localization.
…p stale strings

Change the default PercentageDisplayLocation to .nextToIcon so users
upgrading from the prior boolean see the same behavior they had before.
Rename the picker label to 'Show percentage' for brevity, and remove
two stale entries from the localization catalog.
The digit is rendered with monospaced glyphs and is purely numeric, so
route it through Text(verbatim:) to avoid registering '%lld' as a
translatable string.
@srimanachanta
srimanachanta force-pushed the add-battery-percentage-inside-icon branch from 88b6032 to c75038c Compare May 17, 2026 01:03
@srimanachanta
srimanachanta merged commit c4f2ac2 into srimanachanta:main May 17, 2026
@DinanathDash
DinanathDash deleted the add-battery-percentage-inside-icon branch May 17, 2026 04:16
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.

[FR] Battery percentage inside icon option

2 participants