From b7c5168e977b38cd360f9894200cc26f282aba30 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 17 Aug 2021 16:17:11 +0300 Subject: Fixed battery status sending multiple notifications --- battery-status.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/battery-status.sh b/battery-status.sh index f0a829f..d796568 100755 --- a/battery-status.sh +++ b/battery-status.sh @@ -1,11 +1,9 @@ #!/bin/bash battery_notify () { - if [ ${__bat_per} -eq $1 ] && [[ ${__bat_power} = $2 ]] && ! [[ -f "/tmp/battery.tmp" ]]; then + if [ ${__bat_per} -eq $1 ] && ! grep -q $1 "/tmp/battery.tmp" && [[ ${__bat_power} = $2 ]]; then notify-send -u critical -i battery-low "$3" - touch /tmp/battery.tmp - elif ! [ ${__bat_per} -eq $1 ] && [[ -f "/tmp/battery.tmp" ]]; then - rm /tmp/battery.tmp + echo $1 >> /tmp/battery.tmp fi } @@ -30,8 +28,12 @@ if command -v upower > /dev/null 2>&1 ; then echo " ${__time_full}" fi + if [ ! -f "/tmp/battery.tmp" ]; then + touch /tmp/battery.tmp + fi + battery_notify 100 'fully-charged' 'Battery charged!' - battery_notify 15 'discharging' 'Battery low!' - battery_notify 10 'discharging' 'Battery lower!!' - battery_notify 5 'discharging' 'Battery critical!!!' + battery_notify 15 'discharging' 'Battery low (15%)!' + battery_notify 10 'discharging' 'Battery lower (10%)!!' + battery_notify 5 'discharging' 'Battery critical (5%)!!!' fi -- cgit v1.2.3