Fix battery script

This commit is contained in:
2026-07-10 20:19:04 +01:00
parent 6154c9cf0d
commit e7fa524261
+3 -8
View File
@@ -6,28 +6,22 @@ let
LEVEL=$(cat "$BAT/capacity") LEVEL=$(cat "$BAT/capacity")
STATUS=$(cat "$BAT/status") STATUS=$(cat "$BAT/status")
has_notifications() {
${pkgs.dbus}/bin/busctl --user status org.freedesktop.Notifications >/dev/null 2>&1
}
if [ "$STATUS" = "Discharging" ] && [ "$LEVEL" -lt 3 ]; then if [ "$STATUS" = "Discharging" ] && [ "$LEVEL" -lt 3 ]; then
${pkgs.systemd}/bin/systemctl hibernate ${pkgs.systemd}/bin/systemctl hibernate
exit 0 exit 0
fi fi
if has_notifications; then
if [ "$STATUS" = "Discharging" ] && [ "$LEVEL" -lt 20 ]; then if [ "$STATUS" = "Discharging" ] && [ "$LEVEL" -lt 20 ]; then
${pkgs.dunst}/bin/dunstify \ ${pkgs.dunst}/bin/dunstify \
-r 9991 \ -r 9991 \
-t 0 \ -t 0 \
-u critical \ -u critical \
"Battery Low" \ "Battery Low" \
"Battery is at ''${LEVEL}%" "Battery is at ''${LEVEL}%" 2>/dev/null || true
else else
${pkgs.dunst}/bin/dunstify \ ${pkgs.dunst}/bin/dunstify \
-C 9991 2>/dev/null || true -C 9991 2>/dev/null || true
fi fi
fi
''; '';
in in
{ {
@@ -49,7 +43,8 @@ in
Timer = { Timer = {
OnBootSec = "15s"; OnBootSec = "15s";
OnUnitActiveSec = "15s"; OnUnitInactiveSec = "15s";
AccuracySec = "1s";
}; };
Install = { Install = {