From a323e32a4290b2e861f1d1a65dc581f03c5a5ef0 Mon Sep 17 00:00:00 2001 From: EinBowser <146022965+EinBowser@users.noreply.github.com> Date: Mon, 3 Nov 2025 20:53:40 +0100 Subject: [PATCH] Removed helper script and made workaround in qml --- .../ii/scripts/battery/calculate-health.sh | 16 --------- .../quickshell/ii/services/Battery.qml | 34 ++++++++++--------- 2 files changed, 18 insertions(+), 32 deletions(-) delete mode 100644 dots/.config/quickshell/ii/scripts/battery/calculate-health.sh diff --git a/dots/.config/quickshell/ii/scripts/battery/calculate-health.sh b/dots/.config/quickshell/ii/scripts/battery/calculate-health.sh deleted file mode 100644 index 83b52a5a0..000000000 --- a/dots/.config/quickshell/ii/scripts/battery/calculate-health.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# This just guesses that the BAT0 is the actuall battery -# because BAT0 is the default for modern systems -full=$(cat /sys/class/power_supply/BAT0/charge_full) -design=$(cat /sys/class/power_supply/BAT0/charge_full_design) - -if [ "$design" -gt 0 ]; then # basically if design > 0 - awk "BEGIN { printf \"%.1f\n\", ($full/$design)*100 }" -else - echo "Error" -fi - -# If you have any issues try to find your "real" battery. -# Run 'ls /sys/class/power_supply'. You may see BATM or BAT1 and no BAT0 -# You can check what is what my running 'cat /sys/class/power_supply/{whatever_you_got}/model_name' diff --git a/dots/.config/quickshell/ii/services/Battery.qml b/dots/.config/quickshell/ii/services/Battery.qml index a3f45ac77..0875bbe70 100644 --- a/dots/.config/quickshell/ii/services/Battery.qml +++ b/dots/.config/quickshell/ii/services/Battery.qml @@ -32,27 +32,29 @@ Singleton { property real timeToEmpty: UPower.displayDevice.timeToEmpty property real timeToFull: UPower.displayDevice.timeToFull - property real health: 0 - Process { - id: batteryProcess - running: Config.options.battery.showHealth - command: [ - "bash", - `${FileUtils.trimFileProtocol(Directories.scriptPath)}/battery/calculate-health.sh` - ] + property real health: (function() { + if (!Config.options.battery.showHealth) { + return 0; + } - stdout: StdioCollector { - onStreamFinished: { - const output = text.trim() - const value = Number(output) - if (!isNaN(value)) { - root.health = value + const devList = UPower.devices.values; + for (let i = 0; i < devList.length; ++i) { + const dev = devList[i]; + if (dev.isLaptopBattery && dev.healthSupported) { + const health = dev.healthPercentage; + if (health === 0) { + return 0; + } else if (health < 1) { + return health * 100; } else { - console.warn("Battery script output invalid:", output) + return health; } } } - } + return 0; + })() + + onIsLowAndNotChargingChanged: { if (!root.available || !isLowAndNotCharging) return;