Repository navigation
Warn on low battery even when line power is online - #11161
Conversation
When a machine is connected to a dock or power supply that delivers less power than the system draws, UPower.onBattery is false because a line-power source is online, but device.state is Discharging. Previously, isDischarging required onBattery to be true. As a result, shouldWarnLowBattery returned false throughout the discharge and suppressed the low-battery warning until the system was force-suspended at critical charge. Rely directly on device.state === dischargingState in isDischarging while preserving the onBattery argument for API compatibility. Fixes omacom#10939
|
I saw a hard battery drain on Omarchy 4.0.4-1 with no low-battery toast. I cannot recover the previous I applied this PR's state-only |
|
Reviewed by Claude Opus 5.5 and verified on a disposable Omarchy worker. The fix is correct and proportionate: one condition in Reproduction. I wrote a separate check against the model, feeding it the UPower values from #10939: Tests on the worker. Second opinion. It did not run: the configured reviewer (Codex) had used up today's review budget. So this pull request has had one model's review, not two. For the maintainer, both about other open pull requests on this model:
Labelled |
|
@greptileai Please review the current head, including the docked discharge warning and its regression tests. |
[Medium impact] The PR appears safe to merge. SummaryLow-battery warnings now depend on the battery’s discharge state, even when line power is online.
Reviews (2) · Last reviewed commit: "Drop the unused onBattery parameter from..." · Reviewed by Greptile |
|
Revalidated 16bb60d in a disposable VM: all nine battery assertions, 22 power assertions, and the CLI suite pass. Reverting only BatteryModel.js makes the docked-discharge assertion fail. The desktop shell loads from this branch and reports the battery plugin enabled; the original shell and configuration were restored. These are model-input and VM integration checks, not physical underpowered-dock validation. Greptile has now reviewed this head with no findings and a 5/5 score. No production change is needed for the current review. I checked the related work noted above: #9883 owns the low-battery latch/flapping fix, so this PR does not duplicate it. #8284's startup settling change is separate, but its assertion suppressing a discharging device while line power is online conflicts with this PR's intended behavior; that assertion must be reconciled if both land. |
isDischarging no longer reads onBattery, so taking it only suggests the warning still depends on it. Both callers are in Service.qml. The tests now also cover a missing battery and a charging battery staying silent, folded in from omacom#15009. Co-Authored-By: Omarchybot <317366263+omarchybot@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I pushed one commit to this branch, 62d4f52, carrying over what #15009 added on top of the same fix. #15009 is a newer pull request for #10939 that makes the same change. This one is older and handles every case it does, so this is the one to take. What changed. Tested on a disposable Omarchy worker, using this head merged with current Second opinion. Codex Medium reviewed the head and found nothing to change. It confirmed that no caller on this branch or on For the maintainer, other open pull requests on this model:
Labelled |
…tery (#19689) #19293 added tests that still passed UPower's onBattery, which #11161 had already removed from shouldWarnLowBattery, so every argument landed one slot over and the AC-flap test failed. Plugging in and out now shows as the battery's own state, so the flap test alternates it between discharging and charging. The test still fails on the model from before #19293. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What
Detect battery discharge directly via
device.state === dischargingStateinBatteryModel.isDischarging, removing the requirement that UPower's globalonBatteryproperty be true.Why
When a laptop is connected to a dock, hub, or under-wattage charger where system power consumption exceeds the power delivered by the power supply:
UPower.onBatteryisfalse(because a line-power device is online).UPower.displayDevice.stateisDischarging(the battery percentage is actively dropping).Because
isDischargingpreviously requiredonBattery && device.state === dischargingState, it returnedfalsewhile docked. As a result,shouldWarnLowBatterysuppressed the low-battery notification across the entire discharge, leaving the user with zero warning before the system drained to 2% and was force-suspended byupowerd.Checking
device.state === dischargingStateensures that any time the battery is genuinely discharging past the low threshold, the warning is sent. TheonBatteryargument is preserved in the function signature for compatibility with existing callers.Note that
Service.qml'sapplyPowerProfile()legitimately continues to useUPower.onBatteryfor profile switching between AC and battery.Testing
test/shell.d/battery-test.sh:!isDischargingwhenonBatteryis false with an assertion verifyingisDischargingreturns true even when line power is online (onBattery: false). Confirmed this fails on unmodified baseline and passes with the fix.shouldWarnLowBatterytriggers notification whenonBattery: falseandstate: dischargingunder threshold.omavm):freshsnapshot.BatteryModel.jsand verified unit assertions inside the guest session.Fixes #10939