Skip to content

Check for a low battery when UPower reports a change instead of every 30 seconds - #17387

Open
yamz8 wants to merge 1 commit into
omacom:quattrofrom
yamz8:battery-warning-events
Open

yamz8 wants to merge 1 commit into
omacom:quattrofrom
yamz8:battery-warning-events

Conversation

@yamz8

@yamz8 yamz8 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What changes

The battery service re-read the battery on a 30-second timer, all day, for the whole session. UPower's display device already signals each change to what the check reads (percentage, state, presence, readiness), so the check now runs on those signals and the timer is gone. The warning now goes out the moment the level crosses the threshold, instead of up to 30 seconds later.

The check also waits until UPower has filled in the device. It arrives one property at a time at startup, and a check against a half-read device cleared the "already warned" flag that persists across shell reloads, so a reload at low battery warned a second time. Running on UPower's signals is what exposes the check to that half-read device, so the guard belongs with this change.

The manifest description now mentions the service's other job, switching power profiles with the power source.

Interaction with #8284. #8284 holds low-battery warnings for five seconds after the shell starts (stale UPower state after resume, #7679), and counts on the 30-second timer this PR removes to run the first check once that window ends. Combined as they stand, nothing would check when the window ends, and the first warning would wait for the next percentage or state change. Whichever lands second should run checkBattery() when #8284's gate opens. Both PRs also wait for UPower.displayDevice.ready, so one of those checks can go.

Verification

  • Tested on a laptop with the threshold temporarily raised to 97%: unplugging at 98% checked and stayed quiet, and the warning went out as soon as the battery reported 97%.
  • battery-test.sh, battery-status-test.sh and battery-present-test.sh pass.
  • On 2026-11-11, with current quattro merged in: the service loads in the running shell, its battery IPC target answers, and shell-idle-spawn-test.sh passes (an idle shell starts no processes over 30 seconds).
  • Independently tested by raffsmagic on a Dell XPS 9320 (see the comment below): the warning went out the same second UPower reported the threshold, and the ready guard skipped the checks while UPower still read 0%.
  • Not checked: resume from suspend at low battery, which is Delay the first low-battery check until UPower settles #8284's case.

Screenshots

No visible change: the low-battery notification looks the same; only when the check runs changes.

🤖 Generated with Claude Code

… 30 seconds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Replaces the 30-second battery check with UPower change signals.

  • Low-battery checks now follow UPower changes instead of a timer.
  • The battery service description names its warnings and power-profile switching.

Reviews (1) · Last reviewed commit: "Check for a low battery when UPower repo..." · Reviewed by Greptile

@raffsmagic

Copy link
Copy Markdown
Contributor

Tested be873dd1 on a Dell XPS 9320 (dev channel), on battery, with the threshold bumped to 63% so I didn't have to drain it:

  • battery-test.sh passes.
  • The warning went out the same second UPower reported 63%. Between startup and then it only checked when something changed.
  • The ready guard does its job: while UPower was still filling in the device the shell saw 0%, and those checks were skipped.
  • A shell restart or plugin reload while low warns again. quattro does the same, just up to 30s later, so nothing new here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants