fix: notification when battery runs low

This commit is contained in:
David JULIEN 2021-02-22 12:06:11 +01:00
parent d773272331
commit e0e386c9dd
1 changed files with 12 additions and 3 deletions

View File

@ -16,9 +16,18 @@
# Also sends a notification if battery running low
notify() { \
case "$(cat "$x")" in
1[0-9]) notify-send -u "normal" "Battery is $status and running low ($capacity%)" "Please plug your computer to a power source" ;;
[0-9]) notify-send -u "critical" "Battery is $status and dangerously low ($capacity%)" "Please plug your computer to a power source - <b>NOW!</b>" ;;
now=$(date +%s)
if [ -e $XDG_CONFIG_HOME/batteryupdate ]; then
old=$(cat $XDG_CONFIG_HOME/batteryupdate)
delta=$(expr $now - $old)
else
delta=$now
fi
[ 300 -gt $delta ] && return;
echo $now > $XDG_CONFIG_HOME/batteryupdate
case "$capacity" in
1[0-9]) notify-send -u "normal" "Battery is running low ($capacity%)" "Please plug your computer to a power source" ;;
[0-9]) notify-send -u "critical" "Battery is dangerously low ($capacity%)" "Please plug your computer to a power source - <b>NOW!</b>" ;;
esac
}