warn on low battery

This commit is contained in:
end-4
2025-05-31 01:38:34 +02:00
parent a3d6f9f07d
commit 42abc57b65
3 changed files with 36 additions and 6 deletions
+29
View File
@@ -0,0 +1,29 @@
pragma Singleton
import "root:/modules/common"
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import Quickshell.Hyprland
import Quickshell.Services.UPower
Singleton {
property bool available: UPower.displayDevice.isLaptopBattery
property var chargeState: UPower.displayDevice.state
property bool isCharging: chargeState == UPowerDeviceState.Charging
property bool isPluggedIn: isCharging || chargeState == UPowerDeviceState.PendingCharge
property real percentage: UPower.displayDevice.percentage
property bool isLow: percentage <= ConfigOptions.battery.low / 100
property bool isCritical: percentage <= ConfigOptions.battery.critical / 100
property bool isSuspending: percentage <= ConfigOptions.battery.suspend / 100
onIsLowChanged: {
if (available && isLow) Hyprland.dispatch(`exec notify-send "Low battery" "Consider plugging in your device" -u critical -a "Shell"`)
}
onIsCriticalChanged: {
if (available && isCritical) Hyprland.dispatch(`exec notify-send "Critically low battery" "🙏 I ask for pleas charge\nAutomatic suspend triggers at ${ConfigOptions.battery.suspend}%" -u critical -a "Shell"`)
}
}