mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
fix battery health properly
- apparently displayDevice does not expose all the right properties
This commit is contained in:
@@ -10,8 +10,10 @@ import Quickshell.Services.UPower
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property UPowerDevice device: UPower.displayDevice
|
||||
readonly property bool batteryAvailable: device && device.ready && device.isLaptopBattery
|
||||
readonly property UPowerDevice device: {
|
||||
UPower.devices.values.find(dev => dev.isLaptopBattery) || null
|
||||
}
|
||||
readonly property bool batteryAvailable: device && device.ready
|
||||
readonly property real batteryLevel: batteryAvailable ? Math.round(device.percentage * 100) : 0
|
||||
readonly property bool isCharging: batteryAvailable && device.state === UPowerDeviceState.Charging && device.changeRate > 0
|
||||
readonly property bool isPluggedIn: batteryAvailable && (device.state !== UPowerDeviceState.Discharging && device.state !== UPowerDeviceState.Empty)
|
||||
@@ -25,10 +27,6 @@ Singleton {
|
||||
return `${Math.round(device.healthPercentage)}%`
|
||||
}
|
||||
|
||||
if (batteryHealthUpower > 0) {
|
||||
return `${batteryHealthUpower}%`
|
||||
}
|
||||
|
||||
return "N/A"
|
||||
}
|
||||
readonly property real batteryCapacity: batteryAvailable && device.energyCapacity > 0 ? device.energyCapacity : 0
|
||||
@@ -62,39 +60,6 @@ Singleton {
|
||||
return btDevices
|
||||
}
|
||||
|
||||
readonly property string capacityBaseCmd: `upower -i /org/freedesktop/UPower/devices/battery_DEVICE_REPLACE_ME | awk -F': *' '/^\\s*capacity:/ {gsub(/%/,"",$2); print $2; exit}'`
|
||||
property var batteryHealthUpower: -1
|
||||
|
||||
Component.onCompleted: {
|
||||
// ! TODO - quickshell doesnt seem to expose health correctly all the time, so this is a janky workaround
|
||||
for (const device of UPower.devices.values) {
|
||||
if (device.isLaptopBattery) {
|
||||
batteryCapacityProcess.command = ["sh", "-c", capacityBaseCmd.replace("DEVICE_REPLACE_ME", device.nativePath)]
|
||||
console.log("Executing battery capacity command: " + batteryCapacityProcess.command)
|
||||
batteryCapacityProcess.running = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: batteryCapacityProcess
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
console.log("Battery capacity (upower) raw: " + text)
|
||||
const capacity = parseFloat(text.trim())
|
||||
if (!isNaN(capacity) && capacity > 0 && capacity <= 100) {
|
||||
root.batteryHealthUpower = Math.round(capacity)
|
||||
console.log("Battery health (upower): " + root.batteryHealthUpower + "%")
|
||||
} else {
|
||||
root.batteryHealthUpower = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function formatTimeRemaining() {
|
||||
if (!batteryAvailable) {
|
||||
return "Unknown"
|
||||
|
||||
Reference in New Issue
Block a user