forked from Shinonome/dots-hyprland
Add battery health to battery popup (#2355)
This commit is contained in:
@@ -84,6 +84,30 @@ StyledPopup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
spacing: 5
|
||||||
|
visible: Battery.health > 0
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
MaterialSymbol {
|
||||||
|
text: "heart_check"
|
||||||
|
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)}%`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: 5
|
spacing: 5
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|||||||
@@ -31,6 +31,25 @@ 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: (function() {
|
||||||
|
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.01;
|
||||||
|
} else if (health < 1) {
|
||||||
|
return health * 100;
|
||||||
|
} else {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
})()
|
||||||
|
|
||||||
|
|
||||||
onIsLowAndNotChargingChanged: {
|
onIsLowAndNotChargingChanged: {
|
||||||
if (!root.available || !isLowAndNotCharging) return;
|
if (!root.available || !isLowAndNotCharging) return;
|
||||||
Quickshell.execDetached([
|
Quickshell.execDetached([
|
||||||
|
|||||||
Reference in New Issue
Block a user