Removed gawk extensions, added test for XDG_STATE_HOME env var

This commit is contained in:
Andrew Scott 2024-02-25 11:06:26 -05:00
parent 37a45f2075
commit 6ee3946a3d
Signed by: a
GPG key ID: 7CD5A5977E4931C1

View file

@ -1,22 +1,24 @@
#!/bin/sh
time=$(date +"%b %d, %Y %T")
if test -n "$XDG_STATE_HOME"; then
log_file=$XDG_STATE_HOME/idle.log
echo "--- $time ---" > "$log_file"
else
log_file=$HOME/.local/state/idle.log
fi
echo "--- $(date +"%Y-%m-%d %T") ---" > "$log_file"
# kill process if already running
user=$(id -u)
pid=$(ps -u "$user" | awk '/\<swayidle\>/ {print $1}')
pid=$(ps -o pid,comm -u "$user" | awk '$2=="swayidle" {print $1}')
if [ "$pid" != "" ]; then
echo "Sending SIGTERM to swayidle." >> "$log_file"
echo "Restarting... Sending SIGTERM." >> "$log_file"
kill "$pid"
sleep 1
fi
pid=$(ps -u "$user" | awk '/\<swayidle\>/ {print $1}')
pid=$(ps -o pid,comm -p "$pid" | awk '$2=="swayidle" {print $1}')
if [ "$pid" != "" ]; then
echo "Sending SIGKILL to swayidle." >> "$log_file"
echo "Restarting... Sending SIGKILL." >> "$log_file"
kill -9 "$pid"
sleep 1
fi
@ -26,7 +28,7 @@ fi
brightness="/sys/class/backlight/amdgpu_bl1/brightness"
prev_brightness="${XDG_STATE_HOME}/prev_brightness"
swayidle -w \
timeout 120 "cat $brightness > $prev_brightness && echo 1 > $brightness" \
timeout 120 "cat $brightness > $prev_brightness && echo 0 > $brightness" \
resume "cat $prev_brightness > $brightness" \
timeout 300 'waylock-launcher' \
resume "cat $prev_brightness > $brightness" \