Final commit before Phase II enhancements

This commit is contained in:
2026-07-21 23:25:07 -04:00
parent 19594ff8b3
commit 60fe219ff7
7 changed files with 60 additions and 39 deletions
+11 -8
View File
@@ -20,23 +20,26 @@ while true; do
if [ "$STATUS" == "Discharging" ] && [ "$CAPACITY" -le 5 ]; then
if [ ! -f "/run/user/${UID}/battery_low" ]; then
logger "Low power! Triggering notification...."
dunstify --urgency=critical \
# -p returns the ID so we can close it later
NOTIF_ID=$(dunstify --urgency=critical \
-p \
--icon=/usr/share/icons/breeze-dark/emblems/16/emblem-warning.svg \
"LOW BATTERY!" \
"Battery level is at ${CAPACITY}%, plug power quick!"
touch "/run/user/${UID}/battery_low"
"Battery level is at ${CAPACITY}%, plug power quick!")
echo "$NOTIF_ID" > "/run/user/${UID}/battery_low"
fi
# Clear the notification if we plug back in and rise above 5%
elif [ "$STATUS" == "Charging" ] && [ "$CAPACITY" -gt 5 ]; then
if [ -f "/run/user/${UID}/battery_low" ]; then
logger "Power reconnected and above 5 percent, clearing notification state."
rm -f "/run/user/${UID}/battery_low"
# Find and close the specific dunst notification by ID
for id in $(dunstctl history | jq '.data[0][] | select(.summary.data == "LOW BATTERY!") | .id.data'); do
dunstify --close=${id}
done
NOTIF_ID=$(cat "/run/user/${UID}/battery_low")
if [ -n "$NOTIF_ID" ]; then
dunstify --close=$NOTIF_ID
fi
rm -f "/run/user/${UID}/battery_low"
fi
fi