diff --git a/Config/Config.qml b/Config/Config.qml index 2f6686e..7bb6b0a 100644 --- a/Config/Config.qml +++ b/Config/Config.qml @@ -214,6 +214,10 @@ Singleton { }, idle: { timeouts: general.idle.timeouts + }, + battery: { + popupThresholds: general.battery.popupThresholds, + critPerc: general.battery.critPerc } }; } diff --git a/Config/General.qml b/Config/General.qml index a0a2a2c..7948941 100644 --- a/Config/General.qml +++ b/Config/General.qml @@ -4,6 +4,8 @@ import Quickshell JsonObject { property Apps apps: Apps { } + property Battery battery: Battery { + } property Color color: Color { } property string dateFormat: "ddd d MMM - hh:mm:ss" @@ -19,6 +21,17 @@ JsonObject { property list playback: ["mpv"] property list terminal: ["kitty"] } + component Battery: JsonObject { + property int critPerc: 5 + property list popupThresholds: [ + { + perc: 20, + name: qsTr("Low battery"), + message: qsTr("Battery at %1%").arg(Battery.currentPerc * 100), + icon: "battery_android_frame_2" + }, + ] + } component Color: JsonObject { property int hyprsunsetTemp: 5000 property string mode: "dark" diff --git a/Daemons/Battery.qml b/Daemons/Battery.qml new file mode 100644 index 0000000..ba346bd --- /dev/null +++ b/Daemons/Battery.qml @@ -0,0 +1,46 @@ +import Quickshell +import Quickshell.Services.UPower +import QtQuick +import ZShell +import qs.Config +import qs.Components.Toast + +Scope { + id: root + + readonly property real currentPerc: UPower.displayDevice.percentage + readonly property list popupThresholds: [...Config.general.battery.popupThresholds].sort((a, b) => b.perc - a.perc) + + Connections { + function onOnBatteryChanged(): void { + if (UPower.onBattery) { + if (Config.utilities.toasts.chargingChanged) + Toaster.toast(qsTr("Charger unplugged"), qsTr("Battery is discharging"), "power_off"); + } else { + if (Config.utilities.toasts.chargingChanged) + Toaster.toast(qsTr("Charger plugged in"), qsTr("Battery is charging"), "power"); + for (const level of root.popupThresholds) + level.warned = false; + } + } + + target: UPower + } + + Connections { + function onPercentageChanged(): void { + if (!UPower.onBattery) + return; + + const p = UPower.displayDevice.percentage * 100; + for (const perc of root.popupThresholds) { + if (p <= perc.perc && !perc.warned) { + perc.warned = true; + Toaster.toast(perc.title ?? qsTr("Battery warning"), perc.message ?? qsTr("Battery perc is low"), perc.icon ?? "battery_android_alert", perc.critical ? Toast.Error : Toast.Warning); + } + } + } + + target: UPower.displayDevice + } +} diff --git a/Helpers/Searcher.qml b/Helpers/Searcher.qml index c6f5016..23f15e5 100644 --- a/Helpers/Searcher.qml +++ b/Helpers/Searcher.qml @@ -6,7 +6,6 @@ import Quickshell Singleton { property var extraOpts: ({}) readonly property list fuzzyPrepped: useFuzzy ? list.map(e => { - console.log(useFuzzy); const obj = { _item: e }; diff --git a/shell.qml b/shell.qml index 90f6efa..599b41b 100644 --- a/shell.qml +++ b/shell.qml @@ -6,14 +6,20 @@ //@ pragma Env QT_SCALE_FACTOR_ROUNDING_POLICY=Round //@ pragma DropExpensiveFonts import Quickshell +import Quickshell.Services.UPower import qs.Modules import qs.Modules.Wallpaper import qs.Modules.Lock import qs.Drawers import qs.Helpers import qs.Modules.Polkit +import qs.Daemons ShellRoot { + id: root + + readonly property bool laptop: UPower.displayDevice.isLaptopBattery + settings.watchFiles: true Windows { @@ -38,4 +44,11 @@ ShellRoot { Polkit { } + + LazyLoader { + activeAsync: root.laptop + + component: Battery { + } + } }