feat: changes to battery warning
This commit is contained in:
@@ -37,8 +37,10 @@ let
|
|||||||
capacity=$(cat "$cap_file")
|
capacity=$(cat "$cap_file")
|
||||||
status=$(cat "$status_file" 2>/dev/null || echo "Unknown")
|
status=$(cat "$status_file" 2>/dev/null || echo "Unknown")
|
||||||
|
|
||||||
|
stamp="/run/user/$(id -u)/.battery_swaynag_stamp"
|
||||||
|
pidfile="/run/user/$(id -u)/.battery_swaynag_pid"
|
||||||
|
|
||||||
if [[ "$capacity" -lt 20 && "$status" != "Charging" && "$status" != "Full" ]]; then
|
if [[ "$capacity" -lt 20 && "$status" != "Charging" && "$status" != "Full" ]]; then
|
||||||
stamp="/run/user/$(id -u)/.battery_swaynag_stamp"
|
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
last=0
|
last=0
|
||||||
if [[ -f "$stamp" ]]; then
|
if [[ -f "$stamp" ]]; then
|
||||||
@@ -46,10 +48,27 @@ let
|
|||||||
fi
|
fi
|
||||||
# Avoid spamming: at most once every 5 minutes
|
# Avoid spamming: at most once every 5 minutes
|
||||||
if (( now - last >= 300 )); then
|
if (( now - last >= 300 )); then
|
||||||
|
# Kill previous battery swaynag if still running
|
||||||
|
if [[ -f "$pidfile" ]]; then
|
||||||
|
old_pid=$(cat "$pidfile" 2>/dev/null || echo "")
|
||||||
|
if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then
|
||||||
|
kill "$old_pid" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
echo "$now" > "$stamp"
|
echo "$now" > "$stamp"
|
||||||
swaynag -t warning -m "Battery low: ''${capacity}% - plug in the charger." -b "Dismiss" "true" &
|
swaynag -t warning -m "Battery low: ''${capacity}% - plug in the charger." -b "Dismiss" "true" &
|
||||||
|
echo $! > "$pidfile"
|
||||||
disown || true
|
disown || true
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Charging or battery OK - close any existing warning bar
|
||||||
|
if [[ -f "$pidfile" ]]; then
|
||||||
|
old_pid=$(cat "$pidfile" 2>/dev/null || echo "")
|
||||||
|
if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then
|
||||||
|
kill "$old_pid" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
rm -f "$pidfile" "$stamp"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user