Refactor notifications work to use 1 interface for writing notifs & use dates

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 fixes
master
Miles Alan 4 years ago
parent e6635ba7ef
commit faf9bfc48d
  1. 25
      scripts/core/sxmo_appmenu.sh
  2. 67
      scripts/core/sxmo_notificationmonitor.sh
  3. 16
      scripts/core/sxmo_notifications.sh
  4. 32
      scripts/core/sxmo_notificationsmenu.sh
  5. 30
      scripts/core/sxmo_notificationwrite.sh
  6. 2
      scripts/core/sxmo_xinit.sh
  7. 23
      scripts/modem/sxmo_modemmonitor.sh

@ -340,27 +340,26 @@ getprogchoices() {
# E.g. sets CHOICES var # E.g. sets CHOICES var
programchoicesinit "$@" programchoicesinit "$@"
# Decorate menu at top w/ notifications if they exist # Decorate menu at top *always* w/ incoming call entry if present
NOTIFICATIONS="$(find "$NOTIFDIR"/* -type f | grep -vc "sxmo_incomingcall" || echo 0)" if [ -e "$NOTIFDIR"/incomingcall ]; then
echo "$NOTIFICATIONS" | grep -v 0 && INCOMINGCALLMSG="$(tail -n+3 "$NOTIFDIR"/incomingcall)"
INCOMINGCALLPICKUPACTION="$(head -n1 "$NOTIFDIR"/incomingcall)"
CHOICES=" CHOICES="
Notifications ($(echo "$NOTIFICATIONS" | cut -d " " -f1)) ^ 0 ^ sxmo_notifications.sh $INCOMINGCALLMSG ^ sh -c "rm "$NOTIFDIR"/incomingcall; "$INCOMINGCALLPICKUPACTION""
$CHOICES $CHOICES
" "
fi
# Decorate menu at top w/ incoming call entry if present # For the Sys menu decorate at top with notifications if >1 notification
INCOMINGCALL="$(cat "$NOTIFDIR"/sxmo_incomingcall || echo NOCALL)" if [ "$WINNAME" = "Sys" ]; then
if echo "$INCOMINGCALL" | grep -v NOCALL; then NNOTIFICATIONS="$(find "$NOTIFDIR" -type f | wc -l)"
CALLID="$(echo "$INCOMINGCALL" | cut -d: -f1)" if [ "$NNOTIFICATIONS" -gt 0 ]; then
CALLNUM="$(echo "$INCOMINGCALL" | cut -d: -f2)"
CALLCONTACT="$(sxmo_contacts.sh | grep -v "Unknown Number" | grep -m1 "$CALLNUM" | cut -d: -f2)"
CHOICES=" CHOICES="
Pickup: $( Notifications ($NNOTIFICATIONS) ^ 0 ^ sxmo_notificationsmenu.sh
[ -n "$CALLCONTACT" ] && echo "$CALLCONTACT" || echo "$CALLNUM"
) ^ 0 ^ sxmo_modemcall.sh pickup $CALLID
$CHOICES $CHOICES
" "
fi fi
fi
# Decorate menu at bottom w/ system menu entry if not system menu # Decorate menu at bottom w/ system menu entry if not system menu
echo $WINNAME | grep -v Sys && CHOICES=" echo $WINNAME | grep -v Sys && CHOICES="

@ -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
}
monitorforaddordelnotifs() {
while true; do while true; do
{ INOTIFYOUTPUT="$(
DIREVENT="$(inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/)" inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/
case "$(echo "$DIREVENT" | cut -d" " -f2)" in )"
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"
# Don't send a notification if we're already looking at it! writenotification() {
lsof | grep "$3" && exit 0 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"
}
OUTFILE=$NOTIFDIR/$(date "+%Y:%m:%d:%H:%M:%S:%N") [ "$#" -lt 4 ] && echo "Need >=4 args to create a notification" && exit 1
printf %b "$1\n$2\n$3\n" > "$OUTFILE" writenotification

@ -43,7 +43,7 @@ daemons() {
daemonsneedingdbus() { daemonsneedingdbus() {
dunst -conf /usr/share/sxmo/appcfg/dunst.conf & dunst -conf /usr/share/sxmo/appcfg/dunst.conf &
sxmo_notificationmonitor.sh & #sxmo_notificationmonitor.sh &
sxmo_lisgdstart.sh & sxmo_lisgdstart.sh &
} }

@ -26,11 +26,7 @@ checkforincomingcalls() {
grep -Eo '[0-9]+ incoming \(ringing-in\)' | grep -Eo '[0-9]+ incoming \(ringing-in\)' |
grep -Eo '[0-9]+' grep -Eo '[0-9]+'
)" )"
echo "$VOICECALLID" | grep -v . && rm -f "$NOTIFDIR/incomingcall" && return
if echo "$VOICECALLID" | grep -v .; then
rm -f "$NOTIFDIR/sxmo_incomingcall"
return
fi
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/ring" "$XDG_CONFIG_HOME/sxmo/hooks/ring"
@ -61,7 +57,13 @@ checkforincomingcalls() {
TIME="$(date --iso-8601=seconds)" TIME="$(date --iso-8601=seconds)"
mkdir -p "$LOGDIR" mkdir -p "$LOGDIR"
printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv" printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv"
printf %b "$VOICECALLID:$INCOMINGNUMBER\n" > "$NOTIFDIR/sxmo_incomingcall"
sxmo_notificationwrite.sh \
"$NOTIFDIR/incomingcall" \
"sxmo_modemcall.sh pickup $VOICECALLID" \
"$NOTIFDIR/incomingcall" \
"Pickup $(sxmo_contacts.sh | grep -E "^$INCOMINGNUMBER")" &
echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)" echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)"
} }
@ -75,7 +77,6 @@ checkfornewtexts() {
# Loop each textid received and read out the data into appropriate logfile # Loop each textid received and read out the data into appropriate logfile
for TEXTID in $TEXTIDS; do for TEXTID in $TEXTIDS; do
TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)" TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)"
TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')"
NUM="$( NUM="$(
@ -90,9 +91,11 @@ checkfornewtexts() {
printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv" printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv"
mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID" mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID"
CONTACT="$(sxmo_contacts.sh | grep "$NUM" || echo "$NUM")" sxmo_notificationwrite.sh \
echo "$CONTACT" | grep -c . | grep 1 || CONTACT="$NUM" random \
( sxmo_notificationwrite.sh "Message from $CONTACT: $TEXT" "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" "$LOGDIR/$NUM/sms.txt" & ) & "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" \
"$LOGDIR/$NUM/sms.txt" \
"Message from $(sxmo_contacts.sh | grep -E "^$NUM:"): $TEXT" &
done done
} }

Loading…
Cancel
Save