repaired the battery notification warnings

This commit is contained in:
Tomas Rivera
2026-03-28 18:01:59 +01:00
parent 8a04ab0e9c
commit 16c76a53e4
3 changed files with 38 additions and 48 deletions
+2 -2
View File
@@ -38,8 +38,8 @@ in
# Runs full time in background
x=0
while true; do
Battery_Status="$(cat /sys/class/power_supply/BAT*/status)"
Battery_Capacity=$(cat /sys/class/power_supply/BAT*/capacity)
Battery_Status="$(\cat /sys/class/power_supply/BAT*/status)"
Battery_Capacity=$(\cat /sys/class/power_supply/BAT*/capacity)
case "$Battery_Status" in
"Discharging")
+36 -45
View File
@@ -1,57 +1,48 @@
# taken and adapted https://github.com/miniMinn24/Battery_Notify with MIT License
{
writeShellApplication,
mplayer,
brightnessctl,
...
writeShellApplication,
mplayer,
brightnessctl,
...
}: let
NotifySound = ../../assets/battery_notify.mp3;
NotifySound = ../../assets/battery_notify.mp3;
in
writeShellApplication {
name = "custom-batterywarning";
runtimeInputs = [
mplayer
brightnessctl
];
text = ''
writeShellApplication {
name = "custom-batterywarning";
runtimeInputs = [
mplayer
brightnessctl
];
text = ''
# Delay for startup
sleep 5
# Delay for startup
sleep 5
# Change your sound path here
playsound() {
mplayer ${NotifySound}
}
playsound() {
mplayer ${NotifySound}
}
sendNotification() {
local message="$1"
notify-send -h string:x-canonical-private-synchronous:sys-notify -e -u critical "Battery Low!" "$message"
}
notify_count=0
while true; do
Battery_Status="$(cat /sys/class/power_supply/BAT*/status)"
Battery_Capacity=$(cat /sys/class/power_supply/BAT*/capacity)
while true; do
Battery_Status="$(cat /sys/class/power_supply/BAT*/status)"
Battery_Capacity="$(cat /sys/class/power_supply/BAT*/capacity)"
if [ "$Battery_Status" == "Discharging" ] && [ "$Battery_Capacity" -le 14 ]; then
if [ "$notify_count" -eq 0 ]; then
sendNotification "Power running out: <b>''${Battery_Capacity}%</b>"
playsound
notify_count=$((notify_count + 1))
sleep 180
if [ "$Battery_Status" == "Discharging" ]; then
if [ "$Battery_Capacity" -le 20 ] && [ "$Battery_Capacity" -ge 10 ]; then
notify-send -e -u critical "Battery Low!" "Power running out: <b>''${Battery_Capacity}%</b>"
playsound
sleep 180
elif [ "$notify_count" -eq 1 ]; then
sendNotification "<b>Save your works</b> before immediate shutdown."
playsound
notify_count=$((notify_count - 1))
sleep 180
fi
else
notify_count=0
sleep 120
fi
done
'';
}
elif [ "$Battery_Capacity" -lt 10 ]; then
notify-send -e -u critical "Battery Low!" "<b>Save your works</b> before immediate shutdown."
playsound
sleep 180
fi
else
sleep 120
fi
done
'';
}