Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add low battery notification #1445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .local/bin/statusbar/sb-battery
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ case $BLOCK_BUTTON in
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac

# Flag file to track if low battery notification has been sent
NOTIFY_FLAG="/tmp/low_battery_notified"

# Loop through all attached batteries and format the info
for battery in /sys/class/power_supply/BAT?*; do
# If non-first battery, print a space separator.
Expand All @@ -34,4 +37,8 @@ for battery in /sys/class/power_supply/BAT?*; do
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
# Prints the info
printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
# Remove the flag file if the status changes from discharging to something else
[ "$status" != "🔋" ] && rm -f "$NOTIFY_FLAG"
# Send critical notification if battery is low and discharging
[ -f "$NOTIFY_FLAG" ] || { [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && notify-send -u critical "Battery Warning" "🔋❗ Battery is low: $capacity%" && touch "$NOTIFY_FLAG"; }
done && printf "\\n"