From a38aaf57efb7caa1588146ff721c3754635a1029 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 22 Dec 2020 19:47:22 +0100 Subject: [PATCH] Fix battery notification --- dotfiles/.config/sway/bin/battery.sh | 25 ++++++++++++------------- dotfiles/.config/sway/config | 1 + 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dotfiles/.config/sway/bin/battery.sh b/dotfiles/.config/sway/bin/battery.sh index 314b940..f93cdb9 100755 --- a/dotfiles/.config/sway/bin/battery.sh +++ b/dotfiles/.config/sway/bin/battery.sh @@ -1,19 +1,18 @@ #!/usr/bin/env bash -# I run this in crontab every five minutes warning=10 error=5 -battery_percent="$(cat /sys/class/power_supply/BAT0/capacity)" - -if [[ ${battery_percent} -gt ${warning} ]]; then - exit 0 -fi -if [[ ${battery_percent} -lt ${warning} ]]; then - mtype="warning" -fi -if [[ ${battery_percent} -lt ${error} ]]; then - mtype="error" -fi -swaynag -s "Dismiss" -e bottom -t ${mtype} -m "WARNING: Battery at ${battery_percent}%" +while true; do + battery_status=$(cat /sys/class/power_supply/BAT0/status) + battery_percent=$(cat /sys/class/power_supply/BAT0/capacity) + if [[ "${battery_status}" == "Discharging" ]] && [[ ${battery_percent} -lt ${warning} ]]; then + mtype="warning" + if [[ ${battery_percent} -lt ${error} ]]; then + mtype="error" + fi + /usr/bin/swaynag -o eDP-1 -s "Dismiss" -e bottom -t ${mtype} -m "${mtype^^}: Battery at ${battery_percent}%" + fi + sleep 60 +done exit 0 diff --git a/dotfiles/.config/sway/config b/dotfiles/.config/sway/config index c33564c..cc5a390 100644 --- a/dotfiles/.config/sway/config +++ b/dotfiles/.config/sway/config @@ -300,6 +300,7 @@ exec --no-startup-id autotiling exec --no-startup-id appimagelauncherd exec --no-startup-id nextcloud exec --no-startup-id foot -s +exec --no-startup-id ~/.config/sway/bin/battery.sh exec --no-startup-id /usr/lib/x86_64-linux-gnu/ukui-polkit/polkit-ukui-authentication-agent-1 # Manual autostart graphical exec foot /usr/bin/fish