aboutsummaryrefslogtreecommitdiff
path: root/plugins/notify
blob: 24565ec8e33d03e7fd15fd1f8f3169b61bd9d0a2 (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
#!/bin/sh
[ "$1" = "info" ] && echo "run the notification daemon" && exit 2

. "$core_path/lib"

runtime_dir="$XDG_RUNTIME_DIR/$progname"

mkdir -p "$runtime_dir"
notify_file="$runtime_dir/notify"

pid_file="$runtime_dir/pid"
[ -e "$pid_file" ] && err "$pid_file exists! use \`kill $(cat "$pid_file")\` to stop the other daemon"
echo "$$" > "$pid_file"

update() {
	unset original_state remaining running
	. "$core_path/update"
	touch "$notify_file"
}
update

watch_pid=0

cleanup() {
	trap - TERM
	rm -f "$pid_file"
}
trap cleanup INT TERM EXIT

while inotifywait -qq -e modify "$POMODORO_STATE_PATH/primary" ; do
	update
	if [ $running -eq 1 ] ; then
		if [ $watch_pid = 0 ] ; then
			while :; do
				update &
				sleep 1
			done &
			watch_pid=$!
		fi
	else
		kill -- $watch_pid 2> /dev/null
		watch_pid=0
	fi
done