Skip to content

Dismiss low-battery notification when charger is connected - #11959

Closed
stappmus wants to merge 1 commit into
omacom:quattrofrom
stappmus:fix/dismiss-low-battery-on-ac
Closed

stappmus wants to merge 1 commit into
omacom:quattrofrom
stappmus:fix/dismiss-low-battery-on-ac

Conversation

@stappmus

Copy link
Copy Markdown

Dismiss the low-battery notification when a charger is connected, since the warning is no longer needed once external power is available.

@llstrk

llstrk commented Sep 28, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: For an ordinary charger, the change does what the description says. Plugging in flips UPower.onBattery to false, and the shell runs omarchy-notification-dismiss "Time to recharge!". That reaches the notifications service's dismiss(summary) handler, which removes every popup whose summary contains that text. This matters because critical toasts in this shell never expire on their own. The extra warningProcess.onExited call covers the case where the charger is connected before omarchy-battery-low has posted its toast: the first dismiss finds nothing, and the second runs after the toast has been added. The PR merges cleanly onto current quattro. The dismiss path there (the socket fast path in omarchy-shell and ShellIpc in the notifications service) still reaches the same, unchanged dismiss(summary) handler.

The two points below concern other open PRs and one hardware case, not the ordinary-charger path.

Three other open PRs implement the same dismissal; one combination stops the battery service loading

#8036, #11415 and #12115 also dismiss the "Time to recharge!" toast, each in its own way. How they combine with this PR:

Combined with Git result Outcome
#11415 Textual merge is clean Service.qml declares function dismissLowBatteryWarning() twice. qmllint reports Duplicated method name, and a minimal Qt runtime repro of a duplicate method fails to load with Duplicate method name.
#12115 Conflict Both change the Process { id: warningProcess } block. #12115 adds its own clearWarningProcess with a retry and recheck protocol.
#8036 Conflict Both edit onOnBatteryChanged.

Impact: If this PR and #11415 both land, nothing flags the problem at merge time. The duplicate method stops Service.qml from loading, so the shell skips the battery service. Low-battery warnings and automatic AC/battery power-profile switching then stop. The headless test/shell suite reads Service.qml only as text, so it would not catch this.

Suggested change: Settle on one implementation among #8036, #11415, #12115 and this PR. If more than one lands, merge the helpers into a single function rather than keeping two definitions.

"Not on battery" does not mean the battery stopped draining

The dismissal is keyed on UPower.onBattery alone. In upower 1.91.4 (src/up-daemon.c), OnBattery is false as soon as any line-power supply reports online, even when the battery itself is still discharging. Open issue #10939 shows this on real hardware: a dock that supplies less than the draw reports AC online and OnBattery false while the battery drains from 20% to 2%.

dock that supplies less than the draw, battery at 8% and still discharging
  onBattery: true -> false
    before this PR: critical "Time to recharge!" toast stays on screen
    this PR:        toast dismissed; no new warning while docked (the warning gate requires onBattery)

Impact: On such a charger or dock, the only low-battery toast disappears exactly when the user believes the laptop is charging. Two open PRs aimed at related hardware cases (#11161 for this dock case, #9883 for AC-online flapping) make it worse when combined with this one (based on source reading of the combined code):

#8036, #11415 and #12115 rest on the same onBattery premise, so this is a design question for the feature as a whole.

Suggested change: Dismiss only when the battery is actually no longer discharging, for example when the display device state is Charging, FullyCharged or PendingCharge, not on UPower.onBattery alone. Recheck on state changes or on the existing 30-second checkBattery tick.

Optional test improvement: "Time to recharge!" is now hard-coded in both Service.qml and bin/omarchy-battery-low. test/shell.d/battery-test.sh only loads BatteryModel.js, so removing either new call, or rewording the toast title, leaves every assertion passing. An assertion that the dismissed string matches the summary bin/omarchy-battery-low sends would catch a silent mismatch. Other shell tests already check Service.qml text this way (for example powerprofiles-set-test.sh). Open PR #7434 translates that summary with omarchy_t, so under a translated locale a fixed English needle would stop matching there too.

Not covered: toast restored after a shell restart. If the charger was connected while the shell was not running, a toast restored when the shell starts again is not dismissed. That case produces no onBattery transition and no warning exit, so the toast stays until the next power change or a manual dismiss.


Review information

Test scope: Mostly source review of the pinned head (51ae2cf) and current quattro (3faafba), plus Quickshell v0.3.1, upower 1.91.4 and Qt 6.11.2 sources. Isolated command runs covered the existing battery and power-profile shell tests on head, on head merged onto quattro, and on that merge plus #11415; qmllint on the merged Service.qml; and a minimal Qt duplicate-method load test. Combinations with #11161 and #9883 were assessed from source. No live desktop, notification daemon or hardware charger testing.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot

Copy link
Copy Markdown
Collaborator

Closing in favour of #16562, which fixes the low battery warning staying up on the new notification engine (#15932). Thank you for working on this. Your change pointed at the right moment to take the warning down, and #16562 credits it.

#16562 matches the warning on its sender and icon rather than the English title, so it also works in other languages. It also covers the warning restored after a restart and one held behind an open notification deck.

@omarchybot omarchybot closed this Oct 25, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

A correction to the note above: #16562 has since taken the simpler route #14639 proposed. It sends the warning as a normal toast that expires after 30 seconds instead of dismissing it from the battery service. It still credits this pull request.

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.

3 participants