summaryrefslogtreecommitdiff
path: root/hypridle.sh
blob: d2f25d33aaa4e749284440848b553980676eedef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/bash

renice -n 19 $$
ionice -c 3 -p $$

XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}

# arguments with signal trap
#trap idle SIGQUIT
#trap stopidle SIGILL
#trap "kill $$" SIGINT

# usr-def vars
mutev=true  # stop volume/sound(mute) - comment or un-comment
pmusic=true # stop/start music from playing - command or un-comment

function idle() {
	/sbin/echo "User is idle(afk) in $(date)"

	# script -c "$HOME/scripts/update.sh" /var/log/sysupdate.log -a --force
	# script -c 'topgrade -y --no-retry' /var/log/sysupdate.log -a --force
	# topgrade -y --no-retry &
	checkupdates --download &
	# killall -STOP hyprpaper.sh
	# killall -STOP swww.sh
	brillo -O
	brillo -S 0
	# turn off debug overlay just in case we forget
	hyprctl keyword debug:overlay false
	killall -STOP mpvpaper.sh mpvpaper $(pgrep -P $(pgrep mpvpaper.sh)) video-guard video-guard-helper

	# sleep 30
	if [ $mutev ] && [[ "$(wpctl get-volume @DEFAULT_AUDIO_SINK@)" != *"[MUTED]" ]]; then
		wpctl set-mute @DEFAULT_AUDIO_SINK@ 1
	elif [ $mutev ] && [[ "$(wpctl get-volume @DEFAULT_AUDIO_SINK@)" == *"[MUTED]" ]]; then
		notify-send "Warning: Volume is already muted"
	elif [ $mutev ]; then
		notify-send -u critical "Unable to get volume(sound) status: $(wpctl get-volume @DEFAULT_AUDIO_SINK@)"
	fi

	if [ $pmusic ]; then
		PLAYERS_FILE="$XDG_CACHE_HOME/players"
		>"$PLAYERS_FILE" # Clear/create the file
		for player in $(playerctl --list-all); do
			if [[ $(playerctl -p "$player" status 2>/dev/null) == "Playing" ]]; then
				echo "$player" >>"$PLAYERS_FILE"
			fi
		done
		playerctl --all-players pause
	fi
}

function stopidle() {
	/sbin/echo "User is back from idle(afk) in $(date)"
	#if [ $mutev ] && [ $soundlevel ]; then
	#    amixer set Master $soundlevel
	#    unset $soundlevel
	#elif [ $mutev ] && [ ! $soundlevel ]; then
	#    notify-send "ERROR: \$soundlevel is not set, unknown sound level..."
	#fi
	# killall wallust mpvpaper.sh & $HOME/scripts/mpvpaper.sh &
	killall wallust &
	killall -CONT mpvpaper.sh mpvpaper $(pgrep -P $(pgrep mpvpaper.sh)) video-guard video-guard-helper
	if [ $mutev ] && [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
		wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 &
		# elif [ $mutev ] && [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: no" ]]; then
		# notify-send -e -u critical "ERROR: Volume is not muted" &
		# elif [ $mutev ] && [[ ! $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: no" ]] && [[ ! $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
		# notify-send -e -u critical "Unable to get volume status: $(pactl get-sink-mute @DEFAULT_SINK@)" &
	fi
	/sbin/killall update.sh yay &
	if [ $pmusic ]; then
		PLAYERS_FILE="$XDG_CACHE_HOME/players"
		if [ -f "$PLAYERS_FILE" ]; then
			while IFS= read -r player; do
				playerctl -p "$player" play 2>/dev/null
			done <"$PLAYERS_FILE"
			rm -f "$PLAYERS_FILE"
		fi
	fi
	# killall -CONT hyprpaper.sh || $HOME/scripts/hyprpaper.sh &
	# killall -CONT swww.sh || $HOME/scripts/swww.sh &
	rm -f $XDG_CACHE_HOME/playing-music
	brillo -I
	if [[ "$(swaync-client --get-dnd)" == "true" ]]; then
		# notify-send -e 'Do not Disturb' 'Do not Disturb is still enabled'
		hyprctl notify 2 3000 0 "Do not Disturb is still enabled"
	fi
}

if [ "$1" ]; then
	if [[ "$1" == '--pause' || "$1" == '--idle' ]]; then
		idle
		exit 0
	elif [[ "$1" == '--continue' || "$1" == '--stopidle' ]]; then
		stopidle
		exit 0
	fi
fi

/sbin/echo -e "Un-recornized option: '$@', Please use options:\n\t-d|--daemon\tTo start daemon(auto idle actions)\n\t--idle|--pause\tTo call \`idle\` function\n\t--continue|--stopidle\tTo call \`stopidle\` function"
exit 1