Skip to content

Dismiss the low battery warning when the charger is plugged in - #14739

Closed
mikkelkonyher wants to merge 2 commits into
omacom:quattrofrom
mikkelkonyher:fix-dismiss-low-battery-on-ac
Closed

mikkelkonyher wants to merge 2 commits into
omacom:quattrofrom
mikkelkonyher:fix-dismiss-low-battery-on-ac

Conversation

@mikkelkonyher

@mikkelkonyher mikkelkonyher commented Oct 9, 2026 •

Copy link
Copy Markdown

Fixes #14639 and #8813.

The low battery warning is sent as a critical notification, so it never expires on its own and comes back after every shell restart. That is right while the battery is low, but the warning also stays after the charger is plugged in, and nothing takes it off screen.

The change

On every battery check where the battery is not low, the battery service dismisses the "Time to recharge" toast. Checks run every 30 seconds and whenever the charger is plugged in or unplugged.

The battery service and the notification service run in the same shell, so the battery service calls the notification service directly through firstPartyServiceFor("omarchy.notifications"), the way the lock service reaches the battery service. No process is spawned. The notification service's existing dismiss-by-summary loop moves from its IPC target into dismissBySummary(), which the IPC dismiss now calls, so omarchy notification dismiss behaves as before. A notifications clone made before this change has no dismissBySummary, so the battery service checks for it and skips the dismissal instead of throwing on every check.

It dismisses on every such check rather than only when the battery recovers, because a warning restored after a shell restart can appear after the first check, and the battery service has no record of sending it.

Critical notifications still never expire on their own. Only the battery service decides when its warning is no longer true.

Tested

  • test/shell.d/battery-test.sh covers dismissing when the charger is plugged in, dismissing a warning restored after a restart, and leaving the warning alone while the battery is low or not reported. notifications-test.sh and notification-send-test.sh still pass. The other failures in ./test/shell on my machine fail the same way on a clean quattro.
  • Tested on my MacBook Pro 2017 (MacBookPro14,3) running Omarchy 4.0.4. Before the change: the warning stayed after 30 seconds, after omarchy restart shell, and after plugging in the charger.
  • With the change, in a copy of the 4.0.4 shell with this patch applied to the built-in battery service (a cloned service gets the scoped plugin facade, where firstPartyServiceFor returns null, so a clone can't exercise this path):
    • Unplugging sent the warning, and plugging in the charger took it down.
    • A warning that appeared on AC after the service had already checked was taken down by the next check.
    • A warning restored by a shell restart while on AC was taken down about 30 seconds after the restart.
    • With my own notifications clone, which predates dismissBySummary, the battery check threw a TypeError without the guard, and threw nothing with it.
  • The low battery parts of Service.qml and BatteryModel.js are unchanged between v4.0.4 and current quattro. I have not run the shell from current quattro itself.

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The battery service removes “Time to recharge” warnings whenever a check finds that the battery is no longer low.

  • Battery checks dismiss the low-battery warning when it no longer applies.

Reviews (5) · Last reviewed commit: "Skip the dismissal when a notifications ..." · Reviewed by Greptile

@jandrusk

Copy link
Copy Markdown

Thanks for the thorough testing on the MBP. Heads-up that a few PRs are open for the same fix to #14639: #14218, #14825, #11959 and #11415 (plus the auto-expire part of #12666). It'd help maintainers if you could say what this one covers that the others don't. The case of a warning restored after a shell restart seems like the distinguishing point.

Two small things. GitHub shows conflicts with quattro, so it needs a rebase. And since this already runs inside the shell, dismissing through the notification service directly would avoid spawning omarchy-shell every 30 seconds.

@mikkelkonyher
mikkelkonyher force-pushed the fix-dismiss-low-battery-on-ac branch from 23b7d32 to a9d6d34 Compare October 12, 2026 18:55
@mikkelkonyher

mikkelkonyher commented Oct 12, 2026 •

Copy link
Copy Markdown
Author

Thanks, both points are done. I rebased on quattro, and the battery service now dismisses through the notification service directly, so nothing is spawned.

What this covers that the others don't, from reading their diffs:

This one keeps the warning critical while the battery is low, dismisses a restored warning whenever it shows up, and spawns no process.

The branch rofrol linked on #14639 (comment) handles the restart case more thoroughly: the notification service remembers a dismissal that arrives before its restore, so a restored warning never shows. This one is simpler, but a restored warning can stay up for up to 30 seconds after a restart.

One thing to note: like the others, it dismisses as soon as the battery stops discharging. If #9883 lands, an AC flap at critical charge would take the warning down while the latch keeps it from coming back, so whichever lands second needs to dismiss on recovery instead.

@aholbreich

Copy link
Copy Markdown
Contributor

Tested on quattro (4c1b4cb): merges cleanly, the new battery-test.sh cases fail on quattro and pass here (19/19), and notifications-test.sh passes, also when merged together with #12964. This also fixes #8813, the older report of the same bug, so it could close that one too.

One edge case: firstPartyServiceFor("omarchy.notifications") goes through resolveEnabledId, so a user who has cloned the notifications plugin gets the clone. Its code was copied before this change and has no dismissBySummary, so every battery check would throw a TypeError. A guard keeps that quiet:

if (notifications && typeof notifications.dismissBySummary === "function")
  notifications.dismissBySummary("Time to recharge")

@mikkelkonyher

Copy link
Copy Markdown
Author

Thanks for testing it, and for the clone case. I have a notifications clone myself, and in a copy of the 4.0.4 shell the battery check threw a TypeError without the guard and nothing with it. The guard is in now, and the description also closes #8813.

@aholbreich

Copy link
Copy Markdown
Contributor

Since #15326, bin/omarchy-battery-low sends its title through omarchy-i18n battery.lowTitle, so the summary is Time to recharge! only in English (German gets Zeit zum Aufladen!, Catalan És hora de recarregar!). dismissBySummary("Time to recharge") then finds nothing in any other language, and the warning stays up on AC. #14218 ran into the same thing and now matches the translated battery.lowTitle instead. Could this one match the translated title too, with a test that a non-English warning gets dismissed? I checked this by reading the source at quattro@8a787b6a8, not by running it.

@mikkelkonyher

Copy link
Copy Markdown
Author

Thanks, you're right. Since #15326 this only matches the English title, so the warning stays up in every other language.

#14218 now looks up the translated battery.lowTitle, covers a warning restored after a restart, and has been run on a worker, so I'm closing this one in favor of it. Thanks to everyone who reviewed and tested it.

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 never auto-dismisses and survives shell restarts (critical urgency ignores expire timeout)

3 participants