forked from Shinonome/dots-hyprland
fix sound plays every time low and charge state changes
instead of just when it goes to low
This commit is contained in:
@@ -8,12 +8,14 @@ import QtQuick
|
|||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
|
id: root
|
||||||
property bool available: UPower.displayDevice.isLaptopBattery
|
property bool available: UPower.displayDevice.isLaptopBattery
|
||||||
property var chargeState: UPower.displayDevice.state
|
property var chargeState: UPower.displayDevice.state
|
||||||
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 ?? 1
|
property real percentage: UPower.displayDevice?.percentage ?? 1
|
||||||
readonly property bool allowAutomaticSuspend: Config.options.battery.automaticSuspend
|
readonly property bool allowAutomaticSuspend: Config.options.battery.automaticSuspend
|
||||||
|
readonly property bool soundEnabled: Config.options.sounds.battery
|
||||||
|
|
||||||
property bool isLow: available && (percentage <= Config.options.battery.low / 100)
|
property bool isLow: available && (percentage <= Config.options.battery.low / 100)
|
||||||
property bool isCritical: available && (percentage <= Config.options.battery.critical / 100)
|
property bool isCritical: available && (percentage <= Config.options.battery.critical / 100)
|
||||||
@@ -30,7 +32,8 @@ Singleton {
|
|||||||
property real timeToFull: UPower.displayDevice.timeToFull
|
property real timeToFull: UPower.displayDevice.timeToFull
|
||||||
|
|
||||||
onIsLowAndNotChargingChanged: {
|
onIsLowAndNotChargingChanged: {
|
||||||
if (available && isLowAndNotCharging) Quickshell.execDetached([
|
if (!root.available || !isLowAndNotCharging) return;
|
||||||
|
Quickshell.execDetached([
|
||||||
"notify-send",
|
"notify-send",
|
||||||
Translation.tr("Low battery"),
|
Translation.tr("Low battery"),
|
||||||
Translation.tr("Consider plugging in your device"),
|
Translation.tr("Consider plugging in your device"),
|
||||||
@@ -38,15 +41,12 @@ Singleton {
|
|||||||
"-a", "Shell"
|
"-a", "Shell"
|
||||||
])
|
])
|
||||||
|
|
||||||
if (available && Config.options.sounds.battery) {
|
if (root.soundEnabled) Audio.playSystemSound("dialog-warning");
|
||||||
if (isLowAndNotCharging) {
|
|
||||||
Audio.playSystemSound("dialog-warning")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onIsCriticalAndNotChargingChanged: {
|
onIsCriticalAndNotChargingChanged: {
|
||||||
if (available && isCriticalAndNotCharging) Quickshell.execDetached([
|
if (!root.available || !isCriticalAndNotCharging) return;
|
||||||
|
Quickshell.execDetached([
|
||||||
"notify-send",
|
"notify-send",
|
||||||
Translation.tr("Critically low battery"),
|
Translation.tr("Critically low battery"),
|
||||||
Translation.tr("Please charge!\nAutomatic suspend triggers at %1%").arg(Config.options.battery.suspend),
|
Translation.tr("Please charge!\nAutomatic suspend triggers at %1%").arg(Config.options.battery.suspend),
|
||||||
@@ -54,41 +54,33 @@ Singleton {
|
|||||||
"-a", "Shell"
|
"-a", "Shell"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (available && Config.options.sounds.battery) {
|
if (root.soundEnabled) Audio.playSystemSound("suspend-error");
|
||||||
if (isCriticalAndNotCharging) {
|
|
||||||
Audio.playSystemSound("suspend-error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onIsSuspendingAndNotChargingChanged: {
|
onIsSuspendingAndNotChargingChanged: {
|
||||||
if (available && isSuspendingAndNotCharging) {
|
if (root.available && isSuspendingAndNotCharging) {
|
||||||
Quickshell.execDetached(["bash", "-c", `systemctl suspend || loginctl suspend`]);
|
Quickshell.execDetached(["bash", "-c", `systemctl suspend || loginctl suspend`]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onIsFullAndChargingChanged: {
|
onIsFullAndChargingChanged: {
|
||||||
if (available && isFullAndCharging) Quickshell.execDetached([
|
if (!root.available || !isFullAndCharging) return;
|
||||||
|
Quickshell.execDetached([
|
||||||
"notify-send",
|
"notify-send",
|
||||||
Translation.tr("Battery full"),
|
Translation.tr("Battery full"),
|
||||||
Translation.tr("Please unplug the charger"),
|
Translation.tr("Please unplug the charger"),
|
||||||
"-a", "Shell"
|
"-a", "Shell"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (available && Config.options.sounds.battery) {
|
if (root.soundEnabled) Audio.playSystemSound("complete");
|
||||||
if (isFullAndCharging) {
|
|
||||||
Audio.playSystemSound("complete")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onIsPluggedInChanged: {
|
onIsPluggedInChanged: {
|
||||||
if (available && Config.options.sounds.battery) {
|
if (!root.available || !root.soundEnabled) return;
|
||||||
if (isPluggedIn) {
|
if (isPluggedIn) {
|
||||||
Audio.playSystemSound("power-plug")
|
Audio.playSystemSound("power-plug")
|
||||||
} else {
|
} else {
|
||||||
Audio.playSystemSound("power-unplug")
|
Audio.playSystemSound("power-unplug")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user