forked from Shinonome/dots-hyprland
Added battery health and made it configurable
This commit is contained in:
@@ -63,6 +63,29 @@ StyledPopup {
|
|||||||
text: Battery.isCharging ? Translation.tr("Time to full:") : Translation.tr("Time to empty:")
|
text: Battery.isCharging ? Translation.tr("Time to full:") : Translation.tr("Time to empty:")
|
||||||
color: Appearance.colors.colOnSurfaceVariant
|
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 {
|
StyledText {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
horizontalAlignment: Text.AlignRight
|
horizontalAlignment: Text.AlignRight
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ Singleton {
|
|||||||
property int full: 101
|
property int full: 101
|
||||||
property bool automaticSuspend: true
|
property bool automaticSuspend: true
|
||||||
property int suspend: 3
|
property int suspend: 3
|
||||||
|
property bool showHealth: true
|
||||||
}
|
}
|
||||||
|
|
||||||
property JsonObject conflictKiller: JsonObject {
|
property JsonObject conflictKiller: JsonObject {
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -31,6 +31,29 @@ Singleton {
|
|||||||
property real timeToEmpty: UPower.displayDevice.timeToEmpty
|
property real timeToEmpty: UPower.displayDevice.timeToEmpty
|
||||||
property real timeToFull: UPower.displayDevice.timeToFull
|
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: {
|
onIsLowAndNotChargingChanged: {
|
||||||
if (!root.available || !isLowAndNotCharging) return;
|
if (!root.available || !isLowAndNotCharging) return;
|
||||||
Quickshell.execDetached([
|
Quickshell.execDetached([
|
||||||
|
|||||||
Reference in New Issue
Block a user