Skip to content

Dismiss the low battery warning once the charger is plugged in - #14218

Closed
emirbelkahia wants to merge 5 commits into
omacom:quattrofrom
emirbelkahia:dismiss-low-battery-on-charge
Closed

emirbelkahia wants to merge 5 commits into
omacom:quattrofrom
emirbelkahia:dismiss-low-battery-on-charge

Conversation

@emirbelkahia

@emirbelkahia emirbelkahia commented Oct 4, 2026 •

Copy link
Copy Markdown

The critical "Time to recharge!" toast never goes away on its own. Critical toasts don't expire (the -t 30000 from omarchy-battery-low is ignored for them), and nothing dismisses it when the charger is plugged in, so it stays on screen until it's closed by hand.

Fixes #8813. Overlaps with #11415, which fixes the same issue in a subset of the same files. This one also dismisses a toast restored after a shell restart (the gap noted in the review on #11415) and queues a dismiss that arrives while an earlier one is still running. Only one of the two should land.

This dismisses it once the battery is no longer low:

  • shouldWarnLowBattery returns a dismiss flag when a warning was sent and the battery is no longer discharging at or below the threshold (charger plugged in, or level recovered). It also fires if the battery disappears.
  • The battery service runs the existing omarchy-notification-dismiss on that transition, with the translated summary. It matches on-screen toasts only, so history is untouched.
  • A dismiss requested while an earlier one is still running is queued and runs once it exits, the same way power profile changes are, so a new toast can't be left behind. Sending a new warning drops any queued dismiss, so it can't close that warning.
  • After a shell restart, the first three checks with a known battery level also dismiss when not low (about a minute at the 30s timer). The critical toast is restored from disk after a restart, but the in-memory flag is not, so without this a restart while low would leave the toast stuck for good. A single first check was not enough: popups are restored asynchronously, and a check before UPower reports a level would use up that one chance.
  • docs/notifications.md and the omarchy-notification-dismiss summary now mention the battery service as a caller.

The summary is translated (battery.lowTitle), so the service looks it up with omarchy-i18n the same way omarchy-battery-low does, and battery-test.sh checks that both use the same catalog key.

Validation:

  • test/shell.d/battery-test.sh: passed, including plug-in while low, recovery, no warning sent, battery disappearing, and the restart window (restored warning dismissed, low battery still warns, unknown level neither dismisses nor uses up a check).
  • Restore race, measured on a live shell: with a "Time to recharge!" toast on screen, I ran omarchy-restart-shell and then omarchy-shell notifications dismiss "Time to recharge!" every 100ms. The new shell answered none at about 1.6s and ok at about 2.0s, so a dismiss sent as soon as the shell is up can miss the restored toast. The retry covers that.
  • test/shell.d/qml-text-format-test.sh and test/shell.d/bin-style-test.sh: passed.
  • On a live shell, omarchy-battery-low 8 followed by omarchy-notification-dismiss "Time to recharge!" exits 0. I did not drain or plug a real battery, so the UPower-driven path (threshold crossed, then charger plugged in) is covered by the model tests and review only.
  • Restart window, live: the installed shell with only this PR's battery change patched in, on AC and fully charged. A "Time to recharge!" toast restored after replacing the shell was dismissed 31-32s after launch in 3 runs (the second timer tick), and stayed on screen with the unpatched shell. Details in the comments.
  • ./test/shell on the parent commit and on this branch shows the same unrelated failures I re-ran (config, launch-browser, snapper and others); none touch the battery service.

🤖 Generated with Claude Code

Fixes #14639

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] Battery service now dismisses low-battery warnings automatically.

The PR does not appear safe to merge until dismissal survives a language change and profile tracking recovers after a missed daemon subscription.

Findings

  1. P1 Language changes strand battery warnings ▶

Summary

The PR dismisses low-battery notifications on recovery or charging, retries dismissal after shell startup, and updates the battery service’s power-profile tracking. Two edge cases remain: changing language can strand an existing warning, and daemon recovery can leave the power-saver state stale.

Reviews (5) · Last reviewed commit: "Dismiss the low battery warning by its t..." · Reviewed by Greptile

@emirbelkahia

Copy link
Copy Markdown
Author

Manual check on a live shell, to complement the unit tests:

Done and observed on screen

  • A real low-battery toast ("Time to recharge!", 2%) was already showing.
  • Ran omarchy-battery-low 8: a second "Time to recharge!" toast (8%) appeared next to it.
  • Ran omarchy-notification-dismiss "Time to recharge!", which is the exact command Service.qml runs on the new dismiss transition. Both toasts disappeared at once, so the summary match works on critical toasts that never expire.

Not done

  • I did not drive the full path end to end, i.e. a real battery crossing the 10% threshold and then plugging the charger in so that UPower.onBattery flips and dismiss fires from checkBattery(). That path is covered by the BatteryModel.js unit tests (plug-in while low, recovery, battery absent, first check after a shell restart) but not by a live run.
  • I did not test the shell-restart case on a live shell, only in the model tests.

Happy to run either of those if a reviewer wants it.

@chessing234 chessing234 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.

Reviewed head e7daa20b0fa0f990ce18f9fc9eb50224f55008d0.

Reviewed low-battery dismissal decisions, unknown-level restart-budget preservation, and clearing a queued dismiss when a new warning is sent. The isolated battery model test passed. No additional actionable defect found. UPower/restored-popup ordering still needs live integration coverage.

@jandrusk

jandrusk commented Oct 6, 2026

Copy link
Copy Markdown

Thanks, and nice job chasing the restore race on a live shell. Heads-up that #11415 ("Dismiss stale low battery warnings") touches the same BatteryModel.js/Service.qml paths for the same symptom. This one looks more complete (restart window, queued dismiss), but it'd help maintainers if one of the two referenced the other so only one lands.

@emirbelkahia

Copy link
Copy Markdown
Author

Thanks @jandrusk, good catch. I've added a reference to #11415 (and to #8813) in the description so maintainers can see the overlap and pick one.

For context, both fix #8813, and every file #11415 changes is also changed here. This one also dismisses the toast restored after a shell restart (the gap noted in the review on #11415; popups are restored asynchronously, hence a short retry window) and queues a dismiss that arrives while an earlier one is still running. Happy to go with whichever the maintainers prefer.

@emirbelkahia

Copy link
Copy Markdown
Author

Thanks for the review, @chessing234. On the UPower / restored-popup ordering, I ran a live check of the restart path.

Setup: the installed 4.0.4 shell with only this PR's battery change applied (BatteryModel.js copied, the Service.qml diff patched on top), launched with OMARCHY_PATH pointing at that tree so omarchy-notification-dismiss reaches it. Laptop on AC, fully charged. I put a "Time to recharge!" toast on screen with omarchy-battery-low 8, then killed the installed shell and started the patched one with quickshell -n -p <tree>/shell. The toast is restored from disk, and notifiedLowBattery is false in the new shell (it is not kept across processes, and here the toast came from omarchy-battery-low directly), so only the restart window can dismiss it. I tracked whether the toast was on screen through its popup file in ~/.local/state/omarchy/notifications/ (the shell keeps one file per on-screen toast and moves it to history when the toast leaves the screen).

  • Unpatched shell: after omarchy-restart-shell, the restored toast was still there 75s later.
  • Patched shell, 3 runs: the restored toast was dismissed 32s, 32s and 31s after launch.

In all 3 runs the startup check did not dismiss it and the next timer tick, 30s later, did. This doesn't tell whether the popup wasn't restored yet or UPower hadn't reported a level at startup, but it matches the restore race measured earlier (the restored toast only became reachable about 2s after launch).

Not covered: a real battery crossing the threshold and then the charger being plugged in. I did not drain the battery, so that path is still covered by the model tests only.

@omarchybot

Copy link
Copy Markdown
Collaborator

I read this pull request against current quattro. I have not run it yet. It has not been labelled either, because the second opinion could not run: the reviewer's daily limit was used up, so the classification was never confirmed and nothing went to a worker. Everything below is from Claude Opus 5.5 reading the source alone.

It no longer merges into quattro. A trial merge conflicts in shell/plugins/services/battery/BatteryModel.js and test/shell.d/battery-test.sh, against the power profile change in #15027. Keeping both sides should resolve both conflicts.

The summary it dismisses is now translated. Since #15326, bin/omarchy-battery-low sends "$(omarchy-i18n battery.lowTitle)" rather than the literal Time to recharge!. So lowBatterySummary: "Time to recharge!" in Service.qml only matches in English. With any other language set (for example Zeit zum Aufladen! in German), the toast would stay on screen. After the merge, the new check at the end of battery-test.sh would also fail, because its sed looks for a literal summary in omarchy-battery-low and will not find one. The dismiss needs to use the same battery.lowTitle string, and the test needs to check the key rather than the text.

Related. #11415, #11959, #12666, #13041, #14739 and #14825 also address #8813. Which one goes forward has not been decided this time, because that comparison needs the second opinion too.

Next. This waits for the second opinion to classify it. After that it gets a run on a worker and the comparison with the other fixes, and then it waits on the maintainer. Nothing is needed from you before then. If you update the branch for the two points above, that work will be picked up.

emirbelkahia and others added 5 commits October 15, 2026 11:27
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
After a shell restart the notifications service restores popups
asynchronously, so the single first-check dismiss could run before the
toast was back. A check without a known battery level also used up that
one chance. Retry for the first three checks with a known level instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirbelkahia
emirbelkahia force-pushed the dismiss-low-battery-on-charge branch from e7daa20 to d4687f8 Compare October 15, 2026 09:30
@emirbelkahia

Copy link
Copy Markdown
Author

Updated for both points:

  • Rebased on current quattro. The conflicts in BatteryModel.js and battery-test.sh with Track the power profile through Quickshell instead of polling busctl #15027 are resolved by keeping both sides.
  • The dismiss now uses the translated summary: Service.qml keeps the battery.lowTitle key and runs omarchy-notification-dismiss "$(omarchy-i18n battery.lowTitle)", so it matches what omarchy-battery-low sends in any language. The check at the end of battery-test.sh now compares the catalog key in both files.

battery-test.sh, qml-text-format-test.sh and bin-style-test.sh pass on the rebased branch.

}
dismissPending = false
// The summary is translated, so look it up the same way omarchy-battery-low does
dismissProcess.command = ["bash", "-c", "omarchy-notification-dismiss \"$(omarchy-i18n \"$1\")\"", "bash", lowBatteryTitleKey]

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.

P1 Language changes strand battery warnings

If the user changes Omarchy’s language while a low-battery toast is visible, this command looks up the title in the new language, but the toast still has its original title. The dismissal cannot find it, so the critical warning stays on screen after the charger is plugged in. Keep the title used when sending the warning, or match the existing toast without relying on the current language.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, but narrow: it needs a language change while the low battery toast is on screen, then the charger plugged in. Keeping the sent title in the service wouldn't fully cover it, since omarchy-battery-low builds the title and a shell restart would lose it anyway. A complete fix would need omarchy-notification-dismiss to match on something other than the summary, which is beyond this PR. Leaving it as a known limit unless a maintainer prefers otherwise.

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.

Agreed. The limitation is specifically: toast shown in the old language → language changes → charger is plugged in. The translated summary then cannot match the existing toast.

Retaining the title in memory would not cover shell restarts, and a complete fix requires changing omarchy-notification-dismiss to identify notifications independently of their summary. I’ll leave this as a known limitation for this PR.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Recovered daemon leaves profile stale shell/plugins/services/battery/Service.qml:145 ▶

    If power-profiles-daemon is unavailable when the shell starts, this listener may never attach. After the daemon recovers, changing the profile outside omarchy-powerprofiles-set triggers neither this signal nor a fallback read while the power source stays the same. The battery service then keeps an outdated profile, so the lock screen can continue playing video after power-saver is selected.

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Oct 15, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at d4687f8 and run on an Omarchy worker built from the ISO, with the real shell and notification service and a mock UPower on the system bus. Both points from the earlier comment are addressed: the branch merges cleanly into quattro, and the dismiss now looks up battery.lowTitle the same way omarchy-battery-low does.

Reproduction. In each case the warning was on screen first:

  • On quattro (246f33a), the warning was still on screen 20 s after the charger was plugged in, 45 s after the level recovered to 100%, and 75 s after a shell restart on AC. It also stayed with the language set to German (Zeit zum Aufladen!).
  • On this head, it was gone 0.7 s after the charger was plugged in (0.1 s in German), 28 s after the recovery (the next 30 s check), and 32 s after the restart (the second check after startup).
  • On this head with shell/plugins/services/battery/ reverted, it stayed in all three cases I re-ran (charger, restart, German), just as on quattro.

I also unplugged and replugged the charger at 8% with gaps from 0 to 1 s, to see whether the dismiss could finish before the warning was delivered and leave it stuck. In all six runs the warning was sent and then taken down.

Tests, on the worker. battery-test.sh passed 26 of 26, notifications-test.sh 149 of 149, and notification-send-test.sh, qml-text-format-test.sh, bin-style-test.sh and battery-status-test.sh all passed. ./test/cli passed. The full shell suite has the same six failures on this head as on quattro, and none of them are in the battery or notification code.

One gap remains. The dismiss looks up the title in the language that is set when it runs, not the one the warning was sent in. If someone switches language while the warning is on screen and then plugs in, the old-language toast stays. That needs a language switch at the wrong moment, and fixing it would mean remembering what was sent or matching on something other than the summary, so I have left it for the maintainer to decide. Nothing was pushed.

Competing fixes. #11415, #11959, #14739 and #14825 also fix #8813 from the battery service. This one should go forward even though #11415 and #11959 are older, because both of them miss cases this one handles. Both match the English Time to recharge!, so since #15326 they leave the warning on screen in every other language. #11415 also needs the in-memory flag, so it misses a warning restored after a restart. #14739 dismisses on every check rather than during a window after startup, and it calls the notification service directly, but it also matches the English text. #12666, #13041 and #12964 take a different approach: they let the critical warning expire, even while the battery is still low. Whether to do that is a separate policy decision.

Who checked it. Claude Opus 5.5 reviewed and ran this. Codex Medium was given this pull request and the competing ones without my conclusion. It also chose this one for the reasons above, though its independence from my review is not guaranteed. It raised the language-switch gap. It also raised three timing cases: a dismiss finishing before the warning is delivered, a dismiss still running when a new warning is sent, and a restored toast appearing after the three restart checks. I did not act on those three. The first did not happen in the replug runs above, the second needs the charger replugged and pulled again within a fraction of a second, and restored toasts were back within about 3 s of a restart, well inside the roughly one-minute window.

This now waits on the maintainer, who needs to choose among the open fixes and decide on the language-switch gap. Nothing is needed from you.

@paulogeyer

Copy link
Copy Markdown
Contributor

Compared the PRs for the low-battery warning staying on screen after the charger is plugged in and across shell restarts (#8813, #14639). Tested on my laptop by running #14218's battery-test.sh on each tree (it fails on stock), plus code review of the rest.

PR Dismisses on AC Works in non-English locales Restored toast after restart
#14218 yes yes (looks up battery.lowTitle via omarchy-i18n) yes
#14825 yes no (hardcodes "Time to recharge") no
#11959 yes no (hardcodes "Time to recharge!") no
#11415 partial n/a no; conflicts

#14218 is the one to merge: it closes both issues, matches the translated summary, and handles the toast restored after a restart. #14825, #11959 and #11415 are duplicates of it. #11959 also bundles unrelated screen-recording, sysctl and keyring changes.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 24, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed again on the new notification engine (#15932), with the branch merged into current quattro (bd97868) and run on a disposable Omarchy worker with a mock UPower. The approach still works, but the branch can't merge as it stands, and I've taken the verified label off.

What still holds. The IPC that omarchy-notification-dismiss calls survived the new engine. Merged into quattro, the warning came down 0.5 s after plugging in (also in German), 28 s after recovering while discharging, and 31 s after a shell restart on AC. On quattro itself it stayed in all of these, and with the new engine it stays for good, since critical toasts no longer expire.

Three things stop it now:

  1. It conflicts with quattro in BatteryModel.js. Show a video wallpaper's still frame on the lock screen instead of playing it #15289 removed isPowerSaverOnBattery right next to where this adds remainingRestartChecks. Keeping the new function and dropping the removed one resolves it.
  2. It fails test/shell.d/shell-idle-spawn-test.sh once merged. The startup dismiss window spawns bash, omarchy-i18n, jq, omarchy-shell and socat on every shell start, 11 processes in the test's 30 s idle window, to dismiss a warning that usually isn't there. The test passes on quattro. The only spawn-free way to dismiss is inside the shell, and the shell's I18n doesn't load battery.lowTitle (it's in the CLI catalog), so fixing this means matching some other way than the translated title.
  3. A warning held behind an open notification deck is never dismissed. The new engine keeps a toast that arrives while the deck is expanded out of the on-screen list for up to 30 s. The dismiss misses it, notifiedLowBattery is already cleared, and once the toast is released it stays. Reproduced on the worker: warning sent while the deck was held in keyboard mode, then the charger plugged back in. On this branch the warning was still up 75 s later. Re-opening the existing retry window on every fresh dismiss, counted down only by the 30 s timer so a burst of power events can't use it up, took it down 16.5 s after plugging in. That change is written and tested, but I haven't pushed it, because of 2.

Also open, and not blocking: matching on the translated title misses a warning sent before a language change, and a substring match could close another app's toast with the same text.

Second opinion: Codex Medium and Muse Spark 1.3 High reviewed this in three rounds. Both found the held-deck case (3) independently in the first round, and both found in the second that power-event checks could use up the retry window. In the third, Codex found nothing left. Muse Spark noted that power events still each dismiss while the window is open. I left that alone: each power event already spawns omarchy-powerprofiles-set, and capping the dismisses would bring back the burst problem. Whether to finish this approach or port #15902's matching to the new engine is with the maintainer.

@omarchybot

Copy link
Copy Markdown
Collaborator

Closing in favour of #16562, which fixes the same bug on the new notification engine (#15932). Thank you, Emir: your work on the translated title and on the warning restored after a restart shaped what #16562 had to cover, and it credits you.

#16562 dismisses inside the shell instead of through omarchy-notification-dismiss, and matches the warning on its sender and icon rather than its title. On the new engine that also reaches a warning held behind an open deck, which a dismiss by summary misses, and it spawns no process, which keeps shell-idle-spawn-test passing.

@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

bug Something isn't working

Projects

None yet

5 participants