forked from Shinonome/dots-hyprland
battery: add auto suspend
This commit is contained in:
@@ -77,7 +77,8 @@ Singleton {
|
|||||||
property QtObject battery: QtObject {
|
property QtObject battery: QtObject {
|
||||||
property int low: 20
|
property int low: 20
|
||||||
property int critical: 5
|
property int critical: 5
|
||||||
property int suspend: 2
|
property bool automaticSuspend: true
|
||||||
|
property int suspend: 3
|
||||||
}
|
}
|
||||||
|
|
||||||
property QtObject dock: QtObject {
|
property QtObject dock: QtObject {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Singleton {
|
|||||||
property bool isCharging: chargeState == UPowerDeviceState.Charging
|
property bool isCharging: chargeState == UPowerDeviceState.Charging
|
||||||
property bool isPluggedIn: isCharging || chargeState == UPowerDeviceState.PendingCharge
|
property bool isPluggedIn: isCharging || chargeState == UPowerDeviceState.PendingCharge
|
||||||
property real percentage: UPower.displayDevice.percentage
|
property real percentage: UPower.displayDevice.percentage
|
||||||
|
readonly property bool allowAutomaticSuspend: ConfigOptions.battery.automaticSuspend
|
||||||
|
|
||||||
property bool isLow: percentage <= ConfigOptions.battery.low / 100
|
property bool isLow: percentage <= ConfigOptions.battery.low / 100
|
||||||
property bool isCritical: percentage <= ConfigOptions.battery.critical / 100
|
property bool isCritical: percentage <= ConfigOptions.battery.critical / 100
|
||||||
@@ -19,6 +20,7 @@ Singleton {
|
|||||||
|
|
||||||
property bool isLowAndNotCharging: isLow && !isCharging
|
property bool isLowAndNotCharging: isLow && !isCharging
|
||||||
property bool isCriticalAndNotCharging: isCritical && !isCharging
|
property bool isCriticalAndNotCharging: isCritical && !isCharging
|
||||||
|
property bool isSuspendingAndNotCharging: allowAutomaticSuspend && isSuspending && !isCharging
|
||||||
|
|
||||||
onIsLowAndNotChargingChanged: {
|
onIsLowAndNotChargingChanged: {
|
||||||
if (available && isLowAndNotCharging)
|
if (available && isLowAndNotCharging)
|
||||||
@@ -29,4 +31,10 @@ Singleton {
|
|||||||
if (available && isCriticalAndNotCharging)
|
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"`]);
|
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