Repository navigation
Dismiss the low battery warning once the charger is plugged in - #14218
emirbelkahia wants to merge 5 commits into
Conversation
[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
SummaryThe 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 |
|
Manual check on a live shell, to complement the unit tests: Done and observed on screen
Not done
Happy to run either of those if a reviewer wants it. |
chessing234
left a comment
There was a problem hiding this comment.
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.
|
Thanks, and nice job chasing the restore race on a live shell. Heads-up that #11415 ("Dismiss stale low battery warnings") touches the same |
|
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. |
|
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 (
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. |
|
I read this pull request against current It no longer merges into The summary it dismisses is now translated. Since #15326, 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. |
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>
e7daa20 to
d4687f8
Compare
|
Updated for both points:
|
| } | ||
| 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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Comments Outside DiffThese findings could not be posted inline.
|
|
Reviewed at Reproduction. In each case the warning was on screen first:
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. 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 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. |
|
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
#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. |
|
Reviewed again on the new notification engine (#15932), with the branch merged into current What still holds. The IPC that Three things stop it now:
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 |
|
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 |
The critical "Time to recharge!" toast never goes away on its own. Critical toasts don't expire (the
-t 30000fromomarchy-battery-lowis 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:
shouldWarnLowBatteryreturns adismissflag 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.omarchy-notification-dismisson that transition, with the translated summary. It matches on-screen toasts only, so history is untouched.docs/notifications.mdand theomarchy-notification-dismisssummary now mention the battery service as a caller.The summary is translated (
battery.lowTitle), so the service looks it up withomarchy-i18nthe same wayomarchy-battery-lowdoes, andbattery-test.shchecks 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).omarchy-restart-shelland thenomarchy-shell notifications dismiss "Time to recharge!"every 100ms. The new shell answerednoneat about 1.6s andokat 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.shandtest/shell.d/bin-style-test.sh: passed.omarchy-battery-low 8followed byomarchy-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../test/shellon 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