Dismiss the low battery warning once the charger is back - #10900
Conversation
The low battery toast is sent at critical urgency, and the shell never
expires critical popups, so plugging in left a stale "Time to recharge!"
warning on screen until it was dismissed by hand.
Track the recovery transition in the battery model and have the service
dismiss its own warning when the battery stops being low.
Two paths would otherwise leave the toast stranded for good, since each
clears the notified flag without ever taking the toast down:
- Dismissing by summary only matches toasts the server already has, so
plugging in while omarchy-battery-low is still posting would dismiss
nothing. Defer the clear until the warning process has exited.
- PersistentProperties only spans in-process QML reloads, but a critical
popup is restored from disk across a full restart. Clear on the first
check after startup rather than trusting the flag alone.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V7sx1LYXKQrhFwchbfqPwz
db2854c to
c4f19a2
Compare
|
Pushed an amended commit (
Two more test cases cover the restart path (clears when restored, still warns when it genuinely starts up low); 12 assertions pass. One verification caveat worth stating plainly: my earlier check exercised |
The problem
Hit a 10% battery warning, plugged the charger in, and the toast stayed on screen.
omarchy-battery-lowsends the warning at-u critical, anddurationFor()inshell/plugins/notifications/Service.qmlreturns0for critical urgency — critical popups never expire, so the-t 30000on that send is ignored by design. The battery service resets its ownnotifiedLowBatteryflag when you plug in, but nothing takes the toast off screen, so a stale "Time to recharge!" sits there until dismissed by hand.The fix
Let the service dismiss the warning it sent, once the battery stops being low.
BatteryModel.shouldWarnLowBattery()gains aclearflag for the recovery transition (was notified, no longer low). Thelevel < 0early return folds into the same expression, so a battery that disappears also clears.Service.qmlcalls a newclearLowBatteryWarning(), which runsomarchy-notification-dismiss "Time to recharge!".onOnBatteryChangedalready triggerscheckBattery(), so it fires the moment the charger lands rather than on the next 30s tick.bin/omarchy-battery-lowties the headline tolowBatterySummaryso the two don't drift.Dismissing moves the toast to notification history rather than deleting it, so there's still a record that it fired.
I kept the dismissal keyed on the summary rather than tracking the notification id via
omarchy-notification-send -p: the id would have to survive a shell restart inPersistentPropertiesand could collide with a reused id, for no real gain.Testing
test/shell.d/battery-test.shcovers the new flag with three added cases — charger plugged in, never-warned, and battery removed../test/shelland./test/clipass;config-test.shandlocate-test.shfail identically on an unmodified checkout (plocate packaging and aUnicodeDecodeError), unrelated to this change.Verified in the running UI per
agents/skills/visual-verification.md: sent the real toast, confirmed it on screen, ran the dismissal, confirmed it gone.🤖 Generated with Claude Code
https://claude.ai/code/session_01V7sx1LYXKQrhFwchbfqPwz