mirror of
https://github.com/end-4/dots-hyprland.git
synced 2026-06-05 14:59:27 -05:00
battery: add auto suspend
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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`]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user