diff --git a/dots/.config/quickshell/ii/modules/bar/BatteryPopup.qml b/dots/.config/quickshell/ii/modules/bar/BatteryPopup.qml index 5bc07d18c..72523393d 100644 --- a/dots/.config/quickshell/ii/modules/bar/BatteryPopup.qml +++ b/dots/.config/quickshell/ii/modules/bar/BatteryPopup.qml @@ -63,6 +63,29 @@ StyledPopup { text: Battery.isCharging ? Translation.tr("Time to full:") : Translation.tr("Time to empty:") color: Appearance.colors.colOnSurfaceVariant } + RowLayout { + spacing: 5 + visible: Config.options.battery.showHealth + Layout.fillWidth: true + + MaterialSymbol { + text: "healing" + color: Appearance.colors.colOnSurfaceVariant + iconSize: Appearance.font.pixelSize.large + } + + StyledText { + text: Translation.tr("Health:") + color: Appearance.colors.colOnSurfaceVariant + } + + StyledText { + Layout.fillWidth: true + horizontalAlignment: Text.AlignRight + color: Appearance.colors.colOnSurfaceVariant + text: `${(Battery.health).toFixed(1)}%` + } + } StyledText { Layout.fillWidth: true horizontalAlignment: Text.AlignRight diff --git a/dots/.config/quickshell/ii/modules/common/Config.qml b/dots/.config/quickshell/ii/modules/common/Config.qml index 39c0ef131..854a059ab 100644 --- a/dots/.config/quickshell/ii/modules/common/Config.qml +++ b/dots/.config/quickshell/ii/modules/common/Config.qml @@ -257,6 +257,7 @@ Singleton { property int full: 101 property bool automaticSuspend: true property int suspend: 3 + property bool showHealth: true } property JsonObject conflictKiller: JsonObject { diff --git a/dots/.config/quickshell/ii/scripts/battery/calculate_health.sh b/dots/.config/quickshell/ii/scripts/battery/calculate_health.sh new file mode 100644 index 000000000..58a4b1d4d --- /dev/null +++ b/dots/.config/quickshell/ii/scripts/battery/calculate_health.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# This just guesses that the BAT0 is the actuall battery +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 \ No newline at end of file diff --git a/dots/.config/quickshell/ii/services/Battery.qml b/dots/.config/quickshell/ii/services/Battery.qml index b07bd5305..8ff75da10 100644 --- a/dots/.config/quickshell/ii/services/Battery.qml +++ b/dots/.config/quickshell/ii/services/Battery.qml @@ -31,6 +31,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` + ] + + stdout: StdioCollector { + onStreamFinished: { + const output = text.trim() + const value = Number(output) + if (!isNaN(value)) { + root.health = value + console.log("Battery health:", value) + } else { + console.warn("Battery script output invalid:", output) + } + } + } + } + onIsLowAndNotChargingChanged: { if (!root.available || !isLowAndNotCharging) return; Quickshell.execDetached([