Skip to content

Integrate overlapping battery warnings, charger status, and power panel updates - #21013

Closed
chessing234 wants to merge 19 commits into
omacom:quattrofrom
chessing234:integrate/battery-power
Closed

chessing234 wants to merge 19 commits into
omacom:quattrofrom
chessing234:integrate/battery-power

Conversation

@chessing234

Copy link
Copy Markdown
Contributor

Why one branch

These pull requests all change how the shell reads one battery: the warning service, omarchy-battery-status, and the power panel. Separately they conflict in Service.qml, BatteryModel.js, and battery-test.sh. The 20% warning and the dismiss-on-recovery work do not fit together if each keeps its own latch, and the charger announcement was inserted in the middle of the usage-history helpers.

Incorporated pull requests

Original commits are cherry-picked. They are not squashed into one author.

Fixes on top

  • One latch, lowBatteryWarnedAt, covers 20% and 10%. It is not persisted, so a restart while the battery is still low warns again. The unused notifiedLowBattery flag from the single-threshold version is gone. Dismissing because charging clears that latch. Dismissing because the level climbed does not, so a discharge that is still low does not warn again.
  • The usage-history checks and the warning checks shared a helper name, at, in one script, so the file did not parse. The hour helper is hourAt.

Conflicts

Service.qml had both the threshold list and the dismiss/rearm path. Both stayed. BatteryModel.js had the usage-history functions and shouldAnnounceChargerConnected written into the same brace. Both functions stayed, and both are exported. battery-test.sh kept the warning, dismiss, usage, charger, and charge-limit sections.

Tests

test/shell.d/battery-test.sh passed, including both thresholds, dismiss and rearm, usage history, and the charger toast steps. The charge-limit Quickshell fixture skipped here (no dbus-run-session). test/shell.d/power-test.sh passed, including the charger share. battery-status-test.sh did not get through omarchy-i18n on this Mac because /bin/bash is 3.2 and that script uses mapfile. No Omarchy shell was running, so the power panel was not screenshotted.

Closure of the original pull requests is left to the maintainers.

Made with Cursor

itxkarthik and others added 18 commits December 1, 2026 07:28
A pack whose gauge reads high, such as an uncalibrated replacement, can cut out above 10%, so the only warning never came. The shell now warns once at 20%, UPower's own PercentageLow, and once more at 10%. Each level is latched through AC flaps as before, and climbing back above one re-arms it.

Fixes omacom#20084
A battery-low hook still running from the 20% warning made the 10% one return early, and its level was already latched, so it was lost for the rest of the discharge. Hold it and send it when the running warning exits.
The Surface Pro 11's battery manager reports cycle_count 0: its ADSP
firmware keeps no count. The Surface EC does, and
microsoft-surface-pro-11-support writes it to
/run/surface-pro-11-battery/cycle-count. omarchy-battery-status takes
that file when the battery's own count is 0 or missing; a real count
still wins and a file that isn't a number is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Send a transient toast when line power arrives after the machine has been on battery. A flip shorter than two seconds is ignored, so a USB-C renegotiation or a UPower reading that settles at startup does not announce a charger that was not just plugged in.
A USB-C blip during the confirm wait was clearing the on-battery clock, so plugging back in within two seconds never qualified. A confirmation already earned stays pending across that blip and is dropped only if the machine stays on battery through the window.
A rejected hardware write leaves the one-time top-up marker in place.
Refresh the state when the process exits without rechecking the same
charge reading. A new battery event can still restore the limit.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Wait for Quickshell to handle the failed write before watching for a
retry, and wait for the successful write to clear the marker. Bound both
waits so slow startup or D-Bus calls do not fail a working implementation.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Keep immediate reads for panel opens, power source changes and
charge-limit updates. Poll the remaining battery telemetry every
30 seconds while the panel is open.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
The 20% and 10% warnings and the charger announcement were joined into one battery model. The old boolean latch was unused, and the usage checks reused the device helper's name.
@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; all previous findings are fixed, and no new actionable issues were found.

Summary

This PR combines battery warnings, charger notices, battery readings, and power-panel updates.

  • Low-battery warnings arrive at 20% and 10%, then clear when resolved.
  • The battery service announces a confirmed charger connection with a toast.
  • The power panel shows charger power and how the load is shared.
  • Battery status reads cycle counts and UPower values more reliably.
  • Failed charge-limit writes wait for a later battery event before retrying.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Battery check] --> B{Warning due?}
  B -->|Yes| C{Sender running?}
  C -->|Yes| D[Queue warning]
  C -->|No| E[Send warning and run hooks]
  E --> F[Sender exits]
  F --> G[Defer completion]
  G --> H{Battery recovered?}
  H -->|No| I[Send queued warning if any]
  H -->|Yes| J[Drop queued warning]
  I --> A
  J --> A
  B -->|No| K{Recovered and sender stopped?}
  K -->|Yes| L[Dismiss warning]
Loading

Reviews (2) · Last reviewed commit: "Serialize low battery warnings and recov..." · Reviewed by Greptile

Comment thread bin/omarchy-battery-low Resolved
@Cynnamoroll

Copy link
Copy Markdown
Contributor

Thanks for bringing these fixes together. For now, I’ll keep #20879 and #21006 open and keep both patches up to date with quattro. If you’d prefer to take responsibility for keeping both patches current with quattro here in #21013, let me know and we can avoid duplicating that work. If this PR lands first, I’ll check both fixes on quattro and close the originals it supersedes.

@itxkarthik

Copy link
Copy Markdown

Thanks @chessing234 for pulling these together and keeping the original commits.

On Greptile's first finding ("Queued battery warning never sends"): it doesn't happen on Quickshell 0.3.2, where running is already false inside Process.onExited, so the direct call sends the queued warning. #20264 now has a test for it in 672d20a: battery-test.sh loads the battery service with a stub omarchy-battery-low and checks that 20 and then 10 are both sent. It fails if the queue is removed, and the commit applies on its own if you want it here.

One behavior change from #20264 to flag: when a charger dismisses the warning, warningDismissProcess sets lowBatteryWarnedAt = 0. So a charger that connects and drops right at a threshold (a loose cable, for example) dismisses the warning, then brings the critical warning and sound back on every drop. #20264 avoided that by re-arming only as the level climbs back above each threshold.

Two ways to settle it:

  • Dismiss on charge but leave lowBatteryWarnedAt alone; it already re-arms as the level recovers.
  • Keep the reset on charge, and update the comment above shouldWarnLowBattery, which still says "Charging does not re-arm it".

I'd lean toward the first, but either is fine with me. If #21013 lands I'll close #20264 as superseded.

@omarchybot omarchybot added the enhancement New feature or request label Dec 2, 2026
@chessing234

Copy link
Copy Markdown
Contributor Author

ready for a look @dhh @ryanrhughes

@emirb

emirb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the time you put into this. Some of the fixes you added on top catch real bugs in the original PRs. I'm closing it anyway, along with the other Integrate PRs.

Each bundle puts several people's work in one branch. We can't review it one change at a time or revert a single piece. Merging it would also leave every original PR open. That's why our PR template asks for one problem per PR.

None of the bundles ran on an Omarchy install either.

Please post each fix on the PR it belongs to, so its author can pick it up. If two PRs conflict, a comment on the later one helps us most. A small fix of your own, tested on a real install, is always welcome. Smaller and proven gets merged. Thanks!

@emirb emirb closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants