battery: add auto suspend

This commit is contained in:
end-4
2025-06-23 01:34:10 +02:00
parent d03100d60a
commit 1cd5b0ba1d
2 changed files with 10 additions and 1 deletions
@@ -77,7 +77,8 @@ Singleton {
property QtObject battery: QtObject {
property int low: 20
property int critical: 5
property int suspend: 2
property bool automaticSuspend: true
property int suspend: 3
}
property QtObject dock: QtObject {
+8
View File
@@ -12,6 +12,7 @@ Singleton {
property bool isCharging: chargeState == UPowerDeviceState.Charging
property bool isPluggedIn: isCharging || chargeState == UPowerDeviceState.PendingCharge
property real percentage: UPower.displayDevice.percentage
readonly property bool allowAutomaticSuspend: ConfigOptions.battery.automaticSuspend
property bool isLow: percentage <= ConfigOptions.battery.low / 100
property bool isCritical: percentage <= ConfigOptions.battery.critical / 100
@@ -19,6 +20,7 @@ Singleton {
property bool isLowAndNotCharging: isLow && !isCharging
property bool isCriticalAndNotCharging: isCritical && !isCharging
property bool isSuspendingAndNotCharging: allowAutomaticSuspend && isSuspending && !isCharging
onIsLowAndNotChargingChanged: {
if (available && isLowAndNotCharging)
@@ -29,4 +31,10 @@ Singleton {
if (available && isCriticalAndNotCharging)
Quickshell.execDetached(["bash", "-c", `notify-send "Critically low battery" "🙏 I beg for pleas charg\nAutomatic suspend triggers at ${ConfigOptions.battery.suspend}%" -u critical -a "Shell"`]);
}
onIsSuspendingAndNotChargingChanged: {
if (available && isSuspendingAndNotCharging) {
Quickshell.execDetached(["bash", "-c", `systemctl suspend || loginctl suspend`]);
}
}
}