battery low notification

This commit is contained in:
2025-09-29 14:34:39 +02:00
parent 453445a2d5
commit 3c06cf3f8a
2 changed files with 26 additions and 0 deletions

View File

@@ -294,6 +294,7 @@ in
gamemode
alsa-utils
acpi
libnotify
# fcitx5
# fcitx5-configtool
# kdePackages.dolphin
@@ -546,4 +547,27 @@ in
services.dbus.enable = true;
services.upower.enable = true;
systemd.user.services.battery-low = {
description = "batter low notif";
script = ''
battery_level=$(${pkgs.acpi}/bin/acpi -b | ${pkgs.gnugrep}/bin/grep -P -o '[0-9]+(?=%)')
if [ "$battery_level" -le 15 ] && [ "$(${pkgs.acpi}/bin/acpi -b | ${pkgs.gnugrep}/bin/grep -c 'Discharging')" -eq 1 ]; then
${pkgs.libnotify}/bin/notify-send -u critical "battery low" "battery level: $battery_level%"
fi
'';
serviceConfig = {
Type = "oneshot";
};
};
systemd.user.timers.battery-low = {
description = "check battery level";
timerConfig = {
OnBootSec = "2min";
OnUnitActiveSec = "2min";
};
wantedBy = [ "timers.target" ];
};
}