mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
* Fix: Low Battery notification returning empty value on reboot * Simplify the check * Double paste --------- Co-authored-by: David Heinemeier Hansson <david@hey.com>
24 lines
765 B
Bash
Executable File
24 lines
765 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Designed to be run by systemd timer every 30 seconds and alerts if battery is low
|
|
|
|
BATTERY_THRESHOLD=10
|
|
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
|
|
BATTERY_LEVEL=$(omarchy-battery-remaining)
|
|
BATTERY_STATE=$(upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}')
|
|
|
|
send_notification() {
|
|
notify-send -u critical " Time to recharge!" "Battery is down to ${1}%" -i battery-caution -t 30000
|
|
}
|
|
|
|
if [[ -n "$BATTERY_LEVEL" && "$BATTERY_LEVEL" =~ ^[0-9]+$ ]]; then
|
|
if [[ $BATTERY_STATE == "discharging" && $BATTERY_LEVEL -le $BATTERY_THRESHOLD ]]; then
|
|
if [[ ! -f $NOTIFICATION_FLAG ]]; then
|
|
send_notification $BATTERY_LEVEL
|
|
touch $NOTIFICATION_FLAG
|
|
fi
|
|
else
|
|
rm -f $NOTIFICATION_FLAG
|
|
fi
|
|
fi
|