From e0e386c9dd6075981fe19cc360071a75cb0908fe Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Mon, 22 Feb 2021 12:06:11 +0100 Subject: [PATCH] fix: notification when battery runs low --- .local/bin/statusbar/sb-battery | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery index 58652d8..ea79f4f 100755 --- a/.local/bin/statusbar/sb-battery +++ b/.local/bin/statusbar/sb-battery @@ -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 - NOW!" ;; + 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 - NOW!" ;; esac }