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
|
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
handlenewnotiffile(){
NOTIFFILE="$1"
if [ "$(wc -l "$NOTIFFILE" | cut -d' ' -f1)" -lt 3 ]; then
sxmo_log "Invalid notification file $NOTIFFILE found (<3 lines -- see notif spec in sxmo_notifwrite.sh), deleting!"
rm -f "$NOTIFFILE"
else
sxmo_hook_notification.sh "$NOTIFFILE" &
NOTIFACTION="$(awk NR==1 "$NOTIFFILE")"
NOTIFWATCHFILE="$(awk NR==2 "$NOTIFFILE")"
NOTIFMSG="$(tail -n+3 "$NOTIFFILE" | cut -c1-70)"
(
dunstify --action="2,open" "$NOTIFMSG" | grep 2 && (
rm -f "$NOTIFFILE"
eval "$NOTIFACTION"
)
) &
if lsof | grep -q "$NOTIFWATCHFILE"; then # Already viewing watchfile
rm -f "$NOTIFFILE"
return
fi
[ -e "$NOTIFWATCHFILE" ] && (
inotifywait -q "$NOTIFWATCHFILE" && \
rm -f "$NOTIFFILE" && \
syncled
) &
fi
}
recreateexistingnotifs() {
for NOTIF in "$SXMO_NOTIFDIR"/*; do
[ -f "$NOTIF" ] || continue
handlenewnotiffile "$NOTIF"
done
}
syncled() {
if [ "$(find "$SXMO_NOTIFDIR"/ -type f | wc -l)" -gt 0 ]; then
sxmo_uniq_exec.sh sxmo_led.sh set green 100
else
sxmo_uniq_exec.sh sxmo_led.sh set green 0
fi
sxmo_hook_statusbar.sh notifications
}
monitorforaddordelnotifs() {
mkdir -p "$SXMO_NOTIFDIR"
FIFO="$(mktemp -u)"
mkfifo "$FIFO"
inotifywait -mq -e attrib,move,delete "$SXMO_NOTIFDIR" >> "$FIFO" &
NOTIFYPID=$!
finish() {
kill "$NOTIFYPID"
rm "$FIFO"
exit
}
trap 'finish' TERM INT EXIT
while read -r NOTIFFOLDER INOTIFYEVENTTYPE NOTIFFILE; do
if echo "$INOTIFYEVENTTYPE" | grep -E "CREATE|MOVED_TO|ATTRIB"; then
handlenewnotiffile "$NOTIFFOLDER/$NOTIFFILE"
fi
syncled
done < "$FIFO"
wait "$NOTIFYPID"
}
rm -f "$SXMO_NOTIFDIR"/incomingcall
recreateexistingnotifs
syncled
monitorforaddordelnotifs
|