Update battery icon promptly on power changes

This commit is contained in:
David Heinemeier Hansson
2026-06-29 10:49:43 -05:00
parent f67ed326df
commit 924254ed11
5 changed files with 60 additions and 9 deletions
+2 -4
View File
@@ -74,9 +74,7 @@ function batteryIcon(device, onBattery, states) {
if (threshold) return defaultIcons[index]
if (d.state === states.FullyCharged) return "󰂅"
if (d.state === states.Charging) return chargingIcons[index]
if (d.state === states.Discharging) return defaultIcons[index]
if (!onBattery) return ""
if (!onBattery) return chargingIcons[index]
return defaultIcons[index]
}
@@ -86,8 +84,8 @@ function modeLabel(device, onBattery, states) {
var percentage = d.isPresent ? d.percentage : 0
if (chargeThresholdActive(d, onBattery, states)) return "Threshold"
if (onBattery) return "On battery"
if (!onBattery && percentage >= 1) return "Fully charged"
if (onBattery || d.state === states.Discharging) return "On battery"
return "Charging"
}
+2 -2
View File
@@ -59,7 +59,7 @@ Panel {
}
readonly property bool discharging: {
var device = UPower.displayDevice
return !!(device && device.isPresent && (UPower.onBattery || device.state === UPowerDeviceState.Discharging))
return !!(device && device.isPresent && UPower.onBattery)
}
readonly property bool chargeThresholdActive: {
var device = UPower.displayDevice
@@ -76,7 +76,7 @@ Panel {
readonly property bool charging: {
var d = UPower.displayDevice
return d && d.isPresent && d.state === UPowerDeviceState.Charging && !root.chargeThresholdActive
return d && d.isPresent && !UPower.onBattery && !root.batteryFlowIdle
}
readonly property color batteryFillColor: {