Skip to content

Clear the low-battery toast when the charger is connected - #8895

Closed
chessing234 wants to merge 5 commits into
omacom:quattrofrom
chessing234:fix/omarchy-battery-clear-on-ac
Closed

chessing234 wants to merge 5 commits into
omacom:quattrofrom
chessing234:fix/omarchy-battery-clear-on-ac

Conversation

@chessing234

@chessing234 chessing234 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Critical "Time to recharge!" notifications ignore the send timeout and can remain visible after AC is connected. Leaving the low-discharging state now dismisses that notification and retains dismissal intent across the existing 30-second battery polls. This retries when notification insertion follows the first dismissal, the dismissal process is busy, or the quiet CLI times out without acknowledgement. A new low-battery episode cancels the previous dismissal intent and waits for an in-flight dismissal process to finish before sending its warning.

Fixes #8813.

Validation: bash test/shell.d/battery-clear-on-ac-test.sh and bash test/shell.d/battery-test.sh pass. The focused test executes the QML check and dismissal functions and covers the actual transition call, busy-process retry, and cancellation on a new low-battery episode.

Live Quickshell verification remains pending: trigger the critical notification, connect AC during notification delivery, and confirm eventual dismissal. This requires an Omarchy desktop, unavailable in the current macOS environment.

Copilot AI balanced review requested due to automatic review settings August 29, 2026 06:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Dismisses persistent critical low-battery notifications when the system leaves the low-discharging state.

Changes:

  • Tracks the prior low-battery notification state.
  • Dismisses the warning through omarchy-notification-dismiss.
  • Adds a shell regression test.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
shell/plugins/services/battery/Service.qml Dismisses the low-battery toast after leaving low-discharge state.
test/shell.d/battery-clear-on-ac-test.sh Adds static regression checks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

grep -q 'function clearLowBatteryWarning()' "$service_qml" || fail "battery service can dismiss the low-battery toast"
grep -q 'Time to recharge!' "$service_qml" || fail "battery service dismisses by the Time to recharge! summary"
grep -q 'omarchy-notification-dismiss' "$service_qml" || fail "battery service uses omarchy-notification-dismiss"
grep -q 'clearLowBatteryWarning()' "$service_qml" || fail "battery service calls clear when leaving low-discharging"
Comment on lines +49 to +50
function clearLowBatteryWarning() {
if (clearWarningProcess.running) return
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed on a disposable Omarchy VM with the shell actually running from this branch (quickshell -n -p .../pr-8895/shell), reviewed twice: once by me, Claude Opus 5 in Claude Code, and once by Codex at xhigh reasoning as an independent second opinion. Codex's independence is not currently guaranteed, so where it only agreed with something I had already written down I say so — the two mechanisms in the second finding below are its contribution rather than mine. battery-clear-on-ac-test.sh passes, and so do battery-test.sh, battery-status-test.sh, notifications-test.sh and notification-send-test.sh against your tree.

Your read of the bug is right, and I proved the premise live rather than taking it from the issue: omarchy-battery-low 8 posts {"summary":"Time to recharge!","urgency":2,"expireTimeout":30000} and the toast is still on screen 40 seconds later, because durationFor returns 0 for NotificationUrgency.Critical (shell/plugins/notifications/Service.qml:102-105) and discards the -t 30000 entirely. omarchy-notification-dismiss "Time to recharge!" takes it down; screenshots before and after confirm it. The mechanism you picked is the right one.

Two things worth fixing.

The test passes on a tree where the fix is disabled. I deleted only Service.qml:37 — the single line that ever calls clearLowBatteryWarning(), so #8813 is back in full — and ran test/shell.d/battery-clear-on-ac-test.sh on the worker: 1 passed, 0 failed. grep -q 'clearLowBatteryWarning()' on line 12 is satisfied by the declaration at Service.qml:49, and the other three assertions are satisfied by the now-dead function body. A full revert does turn it red, so the file catches "the code is gone" but not "the code is never called" — and the second is the regression that would actually reach a user. The regex you had in ca014811, before 303710dd replaced it, did assert the call site; the shell equivalent is one line:

grep -q 'else if (wasNotified && !state.notifiedLowBattery) clearLowBatteryWarning()' "$service_qml" || fail "battery service clears the toast when leaving the low-discharging state"

The dismiss is one-shot, and it can be issued before the toast exists. checkBattery writes the latch at Service.qml:33 before the dismiss at :37, and the wasNotified && !state.notifiedLowBattery edge is only ever computed from that latch — so a dismiss that is not issued is never recomputed by a later poll, and what it strands is specifically the popup that never expires. Two ways it is not issued:

  • omarchy-notification-send returns when the D-Bus Notify call returns, but the notification service defers the model insert behind Qt.callLater (shell/plugins/notifications/Service.qml:188-192). A charger edge landing before that deferred popupModel.insert makes the dismiss IPC scan an empty model and return "none" (:912); the toast then arrives, already on AC, and stays up.
  • if (clearWarningProcess.running) return at Service.qml:50 drops a second request. That window is wider than it looks: omarchy-notification-dismiss shells out to omarchy-shell -q, which runs timeout --kill-after=1s 2s (bin/omarchy-shell:58-59), so the process can be alive for about three seconds. -q also returns success when the shell is not answering at all (bin/omarchy-shell:27), so a dismiss that silently did nothing is indistinguishable from one that worked.

Both are narrow, but they land on the one path this change exists to fix. I have pushed nothing to your branch: how to close them is a design choice rather than a contained bug fix, so it belongs with the maintainer.

Two things that are clean, and worth saying so plainly. On a battery-less machine — no /sys/class/power_supply entries, DisplayDevice reporting battery-missing-symbolic — your change throws no QML TypeError and the bar comes up normally. I checked because a TypeError in this service would take the whole bar down for everyone, which is a great deal worse than a stale toast. And the "already warned" latch still resets correctly, so a user who warns, charges, and discharges again does get a second warning.

One thing outside your diff that you should know about: #8838, #8458 and #7688 are all open and all fix #8813 as well. Which one lands is the maintainer's call, not mine — I have reviewed this one on its own merits and given them the comparison.

@chessing234

Copy link
Copy Markdown
Contributor Author

@dhh @ryanrhughes ready for review

@chessing234

Copy link
Copy Markdown
Contributor Author

folding into #12115 with the other bar panel fixes

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.

Low-battery notification remains after charger is connected

3 participants