You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
72 lines
1.8 KiB
4 years ago
|
#!/usr/bin/env sh
|
||
4 years ago
|
trap gracefulexit INT TERM
|
||
4 years ago
|
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
|
||
|
|
||
4 years ago
|
gracefulexit() {
|
||
|
echo "Gracefully exiting $0"
|
||
|
kill -9 0
|
||
|
}
|
||
|
|
||
4 years ago
|
notificationhook() {
|
||
|
if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/notification ]; then
|
||
|
"$XDG_CONFIG_HOME"/sxmo/hooks/notification
|
||
|
else
|
||
4 years ago
|
sxmo_vibratepine 200;
|
||
|
sleep 0.1;
|
||
|
sxmo_vibratepine 200;
|
||
|
sleep 0.1;
|
||
4 years ago
|
fi
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
handlenewnotiffile(){
|
||
|
NOTIFFILE="$1"
|
||
4 years ago
|
|
||
4 years ago
|
if [ "$(wc -l "$NOTIFFILE" | cut -d' ' -f1)" -lt 3 ]; then
|
||
|
echo "Invalid notification file $NOTIFFILE found (<3 lines -- see notif spec in sxmo_notifwrite.sh), deleting!" >&2
|
||
|
rm "$NOTIFFILE"
|
||
|
else
|
||
|
sxmo_setpineled green 1;
|
||
|
notificationhook &
|
||
|
NOTIFACTION="$(awk NR==1 "$NOTIFFILE")"
|
||
|
NOTIFWATCHFILE="$(awk NR==2 "$NOTIFFILE")"
|
||
|
NOTIFMSG="$(tail -n+3 "$NOTIFFILE" | cut -c1-70)"
|
||
|
|
||
|
if dunstify --action="2,open" "$NOTIFMSG" | grep 2; then
|
||
|
eval "$NOTIFACTION"
|
||
4 years ago
|
elif [ -e "$NOTIFWATCHFILE" ]; then
|
||
4 years ago
|
inotifywait "$NOTIFWATCHFILE" && rm -f "$NOTIFFILE" &
|
||
|
fi
|
||
|
fi
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
recreateexistingnotifs() {
|
||
|
for NOTIF in "$NOTIFDIR"/*; do
|
||
|
[ -f "$NOTIF" ] || continue
|
||
|
handlenewnotiffile "$NOTIF"
|
||
|
done
|
||
|
}
|
||
|
|
||
|
monitorforaddordelnotifs() {
|
||
|
while true; do
|
||
4 years ago
|
inotifywait -e create,attrib,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ | (
|
||
4 years ago
|
INOTIFYOUTPUT="$(cat)"
|
||
|
INOTIFYEVENTTYPE="$(echo "$INOTIFYOUTPUT" | cut -d" " -f2)"
|
||
|
case "$INOTIFYEVENTTYPE" in
|
||
4 years ago
|
"CREATE"|"MOVED_TO","ATTRIB")
|
||
4 years ago
|
NOTIFFILE="$NOTIFDIR/$(echo "$INOTIFYOUTPUT" | cut -d" " -f3)"
|
||
|
handlenewnotiffile "$NOTIFFILE"
|
||
|
;;
|
||
|
"DELETE"|"DELETE_SELF"|"MOVED_FROM")
|
||
|
# E.g. if no more notifications unset LED
|
||
|
find "$NOTIFDIR"/ -type f -mindepth 1 | read -r || sxmo_setpineled green 0
|
||
|
;;
|
||
|
esac
|
||
|
) & wait
|
||
4 years ago
|
done
|
||
|
}
|
||
|
|
||
4 years ago
|
pgrep -f "$(command -v sxmo_notificationmonitor.sh)" | grep -Ev "^${$}$" | xargs kill
|
||
4 years ago
|
sxmo_setpineled green 0
|
||
|
recreateexistingnotifs
|
||
|
monitorforaddordelnotifs
|