mirror of
https://github.com/end-4/dots-hyprland.git
synced 2026-06-07 15:59:26 -05:00
57 lines
2.2 KiB
QML
57 lines
2.2 KiB
QML
pragma Singleton
|
|
|
|
import qs
|
|
import qs.modules.common
|
|
import Quickshell
|
|
import Quickshell.Services.UPower
|
|
import QtQuick
|
|
import Quickshell.Io
|
|
|
|
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 ?? 1
|
|
readonly property bool allowAutomaticSuspend: Config.options.battery.automaticSuspend
|
|
|
|
property bool isLow: available && (percentage <= Config.options.battery.low / 100)
|
|
property bool isCritical: available && (percentage <= Config.options.battery.critical / 100)
|
|
property bool isSuspending: available && (percentage <= Config.options.battery.suspend / 100)
|
|
|
|
property bool isLowAndNotCharging: isLow && !isCharging
|
|
property bool isCriticalAndNotCharging: isCritical && !isCharging
|
|
property bool isSuspendingAndNotCharging: allowAutomaticSuspend && isSuspending && !isCharging
|
|
|
|
property real energyRate: UPower.displayDevice.changeRate
|
|
property real timeToEmpty: UPower.displayDevice.timeToEmpty
|
|
property real timeToFull: UPower.displayDevice.timeToFull
|
|
|
|
onIsLowAndNotChargingChanged: {
|
|
if (available && isLowAndNotCharging) Quickshell.execDetached([
|
|
"notify-send",
|
|
Translation.tr("Low battery"),
|
|
Translation.tr("Consider plugging in your device"),
|
|
"-u", "critical",
|
|
"-a", "Shell"
|
|
])
|
|
}
|
|
|
|
onIsCriticalAndNotChargingChanged: {
|
|
if (available && isCriticalAndNotCharging) Quickshell.execDetached([
|
|
"notify-send",
|
|
Translation.tr("Critically low battery"),
|
|
Translation.tr("Please charge!\nAutomatic suspend triggers at %1").arg(Config.options.battery.suspend),
|
|
"-u", "critical",
|
|
"-a", "Shell"
|
|
]);
|
|
|
|
}
|
|
|
|
onIsSuspendingAndNotChargingChanged: {
|
|
if (available && isSuspendingAndNotCharging) {
|
|
Quickshell.execDetached(["bash", "-c", `systemctl suspend || loginctl suspend`]);
|
|
}
|
|
}
|
|
}
|