Summary of changes: 1. Always use the sxmo_notificationwrite.sh script to write notifications rather then sometimes using echo to the DIR 2. Reorder args for notiffile spec to be action as 1st line, watchfile 2nd, and rest as msg; this way msg can be multiple lines without propogating bugs 3. Write calls as a standard notification via sxmo_notificationwrite.sh 4. Use datestamps from notification files instead of filename, this way (3) works without extra logic 5. Various style fixesmaster
parent
e6635ba7ef
commit
faf9bfc48d
7 changed files with 130 additions and 85 deletions
@ -1,48 +1,65 @@ |
|||||||
#!/usr/bin/env sh |
#!/usr/bin/env sh |
||||||
|
|
||||||
# This script should be run to initialize the notification watchers. |
|
||||||
|
|
||||||
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications |
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications |
||||||
|
|
||||||
handlecreation(){ |
notificationhook() { |
||||||
sxmo_setpineled green 1; |
if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/notification ]; then |
||||||
echo "$1" | grep "sxmo_incomingcall" || |
"$XDG_CONFIG_HOME"/sxmo/hooks/notification |
||||||
{ |
else |
||||||
sxmo_vibratepine 200; |
sxmo_vibratepine 200; |
||||||
sleep 0.1; |
sleep 0.1; |
||||||
sxmo_vibratepine 200; |
sxmo_vibratepine 200; |
||||||
sleep 0.1; |
sleep 0.1; |
||||||
} & |
fi |
||||||
|
} |
||||||
|
|
||||||
# Dunstify / start notification watcher if it matches the sxmo_notificationwrite format |
handlenewnotiffile(){ |
||||||
grep -c . "$1" | grep 3 && |
NOTIFFILE="$1" |
||||||
{ |
|
||||||
inotifywait "$(tail -1 "$1")" && rm -f "$1" & |
|
||||||
|
|
||||||
DUNST_RETURN="$(dunstify --action="2,open" "$(head -1 "$1" | cut -c1-70)")"; |
if [ "$(wc -l "$NOTIFFILE" | cut -d' ' -f1)" -lt 3 ]; then |
||||||
# shellcheck disable=SC2091 |
echo "Invalid notification file $NOTIFFILE found (<3 lines -- see notif spec in sxmo_notifwrite.sh), deleting!" >&2 |
||||||
echo "$DUNST_RETURN" | grep -v 2 || { $(head -2 "$1" | tail -1)& } |
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" |
||||||
|
else |
||||||
|
inotifywait "$NOTIFWATCHFILE" && rm -f "$NOTIFFILE" & |
||||||
|
fi |
||||||
|
fi |
||||||
} |
} |
||||||
|
|
||||||
sxmo_setpineled green 0 |
recreateexistingnotifs() { |
||||||
for NOTIF in "$NOTIFDIR"/*; do |
for NOTIF in "$NOTIFDIR"/*; do |
||||||
[ -f "$NOTIF" ] || continue |
[ -f "$NOTIF" ] || continue |
||||||
handlecreation "$NOTIF" |
handlenewnotiffile "$NOTIF" |
||||||
done |
done |
||||||
|
} |
||||||
while true; do |
|
||||||
{ |
monitorforaddordelnotifs() { |
||||||
DIREVENT="$(inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/)" |
while true; do |
||||||
case "$(echo "$DIREVENT" | cut -d" " -f2)" in |
INOTIFYOUTPUT="$( |
||||||
|
inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ |
||||||
|
)" |
||||||
|
INOTIFYEVENTTYPE="$(echo "$INOTIFYOUTPUT" | cut -d" " -f2)" |
||||||
|
|
||||||
|
case "$INOTIFYEVENTTYPE" in |
||||||
"CREATE"|"MOVED_TO") |
"CREATE"|"MOVED_TO") |
||||||
NOTIFFILE="$NOTIFDIR/$(echo "$DIREVENT" | cut -d" " -f3)" |
NOTIFFILE="$NOTIFDIR/$(echo "$INOTIFYOUTPUT" | cut -d" " -f3)" |
||||||
handlecreation "$NOTIFFILE" |
handlenewnotiffile "$NOTIFFILE" |
||||||
;; |
;; |
||||||
|
|
||||||
"DELETE"|"DELETE_SELF"|"MOVED_FROM") |
"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 |
find "$NOTIFDIR"/ -type f -mindepth 1 | read -r || sxmo_setpineled green 0 |
||||||
;; |
;; |
||||||
esac |
esac |
||||||
} |
done |
||||||
done |
} |
||||||
|
|
||||||
|
sxmo_setpineled green 0 |
||||||
|
recreateexistingnotifs |
||||||
|
monitorforaddordelnotifs |
||||||
|
@ -1,16 +0,0 @@ |
|||||||
#!/usr/bin/env sh |
|
||||||
|
|
||||||
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications |
|
||||||
|
|
||||||
FILES="$(find "$NOTIFDIR"/ -type f -not -name 'sxmo_incomingcall')" |
|
||||||
for FILE in $FILES; do |
|
||||||
CHOICES="$(printf %b "$FILE\t$(echo "$FILE" | cut -d: -f4-6) $(head -1 "$FILE")\n$CHOICES")" |
|
||||||
done |
|
||||||
PICKED="$(printf %b "$CHOICES\nClose Menu" | cut -f2 | dmenu -c -i -fn "Terminus-18" -p "Notifs" -l 10)" |
|
||||||
|
|
||||||
echo "$PICKED" | grep "Close Menu" && exit 0 |
|
||||||
TIMESTAMP="$(echo "$PICKED" | cut -d" " -f1 | cut -d: -f4-6)" |
|
||||||
FILE="$(printf %b "$CHOICES" | grep "$PICKED" | cut -f1 | grep "$TIMESTAMP")" |
|
||||||
|
|
||||||
# shellcheck disable=SC2091 |
|
||||||
$(head -2 "$FILE" | tail -1) |
|
@ -0,0 +1,32 @@ |
|||||||
|
#!/usr/bin/env sh |
||||||
|
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications |
||||||
|
|
||||||
|
notificationmenu() { |
||||||
|
CHOICES="Close Menu" |
||||||
|
for NOTIFFILE in "$NOTIFDIR"/*; do |
||||||
|
NOTIFMSG="$(tail -n+3 "$NOTIFFILE" | tr "\n^" " ")" |
||||||
|
NOTIFHRANDMIN="$(stat --printf %y "$NOTIFFILE" | grep -oE '[0-9]{2}:[0-9]{2}')" |
||||||
|
CHOICES=" |
||||||
|
$CHOICES |
||||||
|
$NOTIFHRANDMIN - $NOTIFMSG ^ $NOTIFFILE |
||||||
|
" |
||||||
|
done |
||||||
|
|
||||||
|
PICKEDCONTENT="$( |
||||||
|
printf "%b" "$CHOICES" | |
||||||
|
xargs -0 echo | |
||||||
|
sed '/^[[:space:]]*$/d' | |
||||||
|
awk '{$1=$1};1' | |
||||||
|
cut -d^ -f1 | |
||||||
|
dmenu -c -i -fn "Terminus-18" -p "Notifs" -l 10 |
||||||
|
)" |
||||||
|
|
||||||
|
[ "$PICKEDCONTENT" = "Close Menu" ] && exit 1 |
||||||
|
|
||||||
|
PICKEDNOTIFFILE="$(echo "$CHOICES" | grep "$PICKEDCONTENT" | cut -d^ -f2 | tr -d ' ')" |
||||||
|
NOTIFACTION="$(head -n1 "$PICKEDNOTIFFILE")" |
||||||
|
eval "$NOTIFACTION" & |
||||||
|
rm "$PICKEDNOTIFFILE" |
||||||
|
} |
||||||
|
|
||||||
|
notificationmenu |
@ -1,15 +1,25 @@ |
|||||||
#!/usr/bin/env sh |
#!/usr/bin/env sh |
||||||
|
|
||||||
# This script takes 3 arguments, (1) a fuzzy description of the notification, (2) the action that the notification invokes upon selecting, and (3) the file to watch for deactivation. |
|
||||||
# A notification file has 3 different fields, (1) a fuzzy description, (2) the selection action, and (3) the watch file. |
|
||||||
|
|
||||||
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications |
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications |
||||||
|
|
||||||
mkdir -p "$NOTIFDIR" |
# Takes 4 args: |
||||||
echo "$3" | grep -v . && { echo "Not enough args."; exit 2; } |
# (1) the filepath of the notification to write (or random to generate a random id) |
||||||
|
# (2) action notification invokes upon selecting |
||||||
|
# (3) the file to watch for deactivation. |
||||||
|
# (4) description of notification |
||||||
|
NOTIFFILEPATHTOWRITE="$1" |
||||||
|
ACTION="$2" |
||||||
|
WATCHFILE="$3" |
||||||
|
NOTIFMSG="$4" |
||||||
|
|
||||||
|
writenotification() { |
||||||
|
lsof | grep "$WATCHFILE" && exit 0 # Already viewing watchfile, nops |
||||||
|
mkdir -p "$NOTIFDIR" |
||||||
|
if [ "$NOTIFFILEPATHTOWRITE" = "random" ]; then |
||||||
|
NOTIFFILEPATHTOWRITE="$NOTIFDIR/$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 10)" |
||||||
|
fi |
||||||
|
rm -f "$NOTIFFILEPATHTOWRITE" |
||||||
|
printf %b "$ACTION\n$WATCHFILE\n$NOTIFMSG\n" > "$NOTIFFILEPATHTOWRITE" |
||||||
|
} |
||||||
|
|
||||||
# Don't send a notification if we're already looking at it! |
[ "$#" -lt 4 ] && echo "Need >=4 args to create a notification" && exit 1 |
||||||
lsof | grep "$3" && exit 0 |
writenotification |
||||||
|
|
||||||
OUTFILE=$NOTIFDIR/$(date "+%Y:%m:%d:%H:%M:%S:%N") |
|
||||||
printf %b "$1\n$2\n$3\n" > "$OUTFILE" |
|
Loading…
Reference in new issue