aboutsummaryrefslogtreecommitdiff
path: root/plugins/notify
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/notify')
-rwxr-xr-xplugins/notify45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/notify b/plugins/notify
new file mode 100755
index 0000000..24565ec
--- /dev/null
+++ b/plugins/notify
@@ -0,0 +1,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
+