Notifications v3 rewritten, notable changes-
-LED/dunst/ringing logic consolidated to sxmo_notificationmontior.sh
-Notification file format modified to work with newlines instead of tabs
-Applied Maarten van Gompel's fix for shellcheck pass
-Timestamps are no longer written into the notification file's contents.
sxmo_notifications.sh relies on the filename for reading time. Also, if
two notifications have the same description, the timestamp is used to
distinguish one from the other.
-Simplified work done in sxmo_modemmonitor.sh to send a notification.
Fixed issue where two contacts getting caught by grep could cause a
broken notification.
iressa (1):
Notification patch v4
configs/appcfg/dunst.conf | 2 +
scripts/core/sxmo_appmenu.sh | 13 ++++++-
scripts/core/sxmo_notificationmonitor.sh | 48 ++++++++++++++++++++++++
scripts/core/sxmo_notifications.sh | 16 ++++++++
scripts/core/sxmo_notificationwrite.sh | 15 ++++++++
scripts/core/sxmo_xinit.sh | 1 +
scripts/modem/sxmo_modemmonitor.sh | 25 +++++-------
7 files changed, 103 insertions(+), 17 deletions(-)
create mode 100755 scripts/core/sxmo_notificationmonitor.sh
create mode 100755 scripts/core/sxmo_notifications.sh
create mode 100755 scripts/core/sxmo_notificationwrite.sh
--
2.28.0
---
configs/appcfg/dunst.conf | 2 +
scripts/core/sxmo_appmenu.sh | 13 ++++++-
scripts/core/sxmo_notificationmonitor.sh | 48 ++++++++++++++++++++++++
scripts/core/sxmo_notifications.sh | 16 ++++++++
scripts/core/sxmo_notificationwrite.sh | 15 ++++++++
scripts/core/sxmo_xinit.sh | 1 +
scripts/modem/sxmo_modemmonitor.sh | 25 +++++-------
7 files changed, 103 insertions(+), 17 deletions(-)
create mode 100755 scripts/core/sxmo_notificationmonitor.sh
create mode 100755 scripts/core/sxmo_notifications.sh
create mode 100755 scripts/core/sxmo_notificationwrite.sh
diff --git a/configs/appcfg/dunst.conf b/configs/appcfg/dunst.conf
index a7f9323..b2bddee 100644
--- a/configs/appcfg/dunst.conf
+++ b/configs/appcfg/dunst.conf
@@ -32,6 +32,8 @@
title = Dunst
class = Dunst
startup_notification = false
+ mouse_left_click = do_action
+
[shortcuts]
close_all = ctrl+shift+space
diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh
index 639e912..d4a3b5f 100755
--- a/scripts/core/sxmo_appmenu.sh
@@ -1,6 +1,7 @@
#!/usr/bin/env sh
trap gracefulexit INT TERM
WIN=$(xdotool getwindowfocus)
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
gracefulexit() {
echo "Gracefully exiting $0"
@@ -337,8 +338,16 @@ getprogchoices() {
# E.g. sets CHOICES var
programchoicesinit "$@"
+ # Decorate menu at top w/ notifications if they exist
+ NOTIFICATIONS="$(find "$NOTIFDIR"/* -type f | grep -vc "sxmo_incomingcall" || echo 0)"
+ echo "$NOTIFICATIONS" | grep -v 0 &&
+ CHOICES="
+ Notifications ($(echo "$NOTIFICATIONS" | cut -d " " -f1)) ^ 0 ^ sxmo_notifications.sh
+ $CHOICES
+ "
+
# Decorate menu at top w/ incoming call entry if present
- INCOMINGCALL="$(cat /tmp/sxmo_incomingcall || echo NOCALL)"
+ INCOMINGCALL="$(cat "$NOTIFDIR"/sxmo_incomingcall || echo NOCALL)"
if echo "$INCOMINGCALL" | grep -v NOCALL; then
CALLID="$(echo "$INCOMINGCALL" | cut -d: -f1)"
CALLNUM="$(echo "$INCOMINGCALL" | cut -d: -f2)"
@@ -401,4 +410,4 @@ pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "^${$}$" | xargs kill -TERM
DMENUIDX=0
PICKED=""
ARGS="$*"
-mainloop
\ No newline at end of file
+mainloop
diff --git a/scripts/core/sxmo_notificationmonitor.sh b/scripts/core/sxmo_notificationmonitor.sh
new file mode 100755
index 0000000..175a87d
--- /dev/null
+++ b/scripts/core/sxmo_notificationmonitor.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env sh
+
+# This script should be run to initialize the notification watchers.
+
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
+
+handlecreation(){
+ sxmo_setpineled green 1;
+ echo "$1" | grep "sxmo_incomingcall" ||
+ {
+ sxmo_vibratepine 200;
+ sleep 0.1;
+ sxmo_vibratepine 200;
+ sleep 0.1;
+ } &
+
+ # Dunstify / start notification watcher if it matches the sxmo_notificationwrite format
+ grep -c . "$1" | grep 3 &&
+ {
+ inotifywait "$(tail -1 "$1")" && rm -f "$1" &
+
+ DUNST_RETURN="$(dunstify --action="2,open" "$(head -1 "$1" | cut -c1-70)")";
+ # shellcheck disable=SC2091
+ echo "$DUNST_RETURN" | grep -v 2 || { $(head -2 "$1" | tail -1)& }
+ }
+}
+
+sxmo_setpineled green 0
+for NOTIF in "$NOTIFDIR"/*; do
+ [ -f "$NOTIF" ] || continue
+ handlecreation "$NOTIF"
+done
+
+while true; do
+ {
+ DIREVENT="$(inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/)"
+ case "$(echo "$DIREVENT" | cut -d" " -f2)" in
+ "CREATE"|"MOVED_TO")
+ NOTIFFILE="$NOTIFDIR/$(echo "$DIREVENT" | cut -d" " -f3)"
+ handlecreation "$NOTIFFILE"
+ ;;
+
+ "DELETE"|"DELETE_SELF"|"MOVED_FROM")
+ find "$NOTIFDIR"/ -type f -mindepth 1 | read -r || sxmo_setpineled green 0
+ ;;
+ esac
+ }
+done
diff --git a/scripts/core/sxmo_notifications.sh b/scripts/core/sxmo_notifications.sh
new file mode 100755
index 0000000..7ce9eb3
--- /dev/null
+++ b/scripts/core/sxmo_notifications.sh
@@ -0,0 +1,16 @@
+#!/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)
diff --git a/scripts/core/sxmo_notificationwrite.sh b/scripts/core/sxmo_notificationwrite.sh
new file mode 100755
index 0000000..f301f9f
--- /dev/null
+++ b/scripts/core/sxmo_notificationwrite.sh
@@ -0,0 +1,15 @@
+#!/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
+
+mkdir -p "$NOTIFDIR"
+echo "$3" | grep -v . && { echo "Not enough args."; exit 2; }
+
+# Don't send a notification if we're already looking at it!
+lsof | grep "$3" && exit 0
+
+OUTFILE=$NOTIFDIR/$(date "+%Y:%m:%d:%H:%M:%S:%N")
+printf %b "$1\n$2\n$3\n" > "$OUTFILE"
diff --git a/scripts/core/sxmo_xinit.sh b/scripts/core/sxmo_xinit.sh
index ce6f99a..8e9e504 100755
--- a/scripts/core/sxmo_xinit.sh
+++ b/scripts/core/sxmo_xinit.sh
@@ -44,6 +44,7 @@ daemons() {
daemonsneedingdbus() {
dunst -conf /usr/share/sxmo/appcfg/dunst.conf &
+ sxmo_notificationmonitor.sh &
sxmo_lisgdstart.sh &
}
diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh
index 6283df3..0ca91c0 100755
--- a/scripts/modem/sxmo_modemmonitor.sh
+++ b/scripts/modem/sxmo_modemmonitor.sh
@@ -1,6 +1,7 @@
#!/usr/bin/env sh
TIMEOUT=3
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
trap "gracefulexit" INT TERM
err() {
@@ -10,7 +11,6 @@ err() {
gracefulexit() {
echo "gracefully exiting $0!"
- sxmo_setpineled green 0
kill -9 0
}
@@ -28,14 +28,14 @@ checkforincomingcalls() {
)"
if echo "$VOICECALLID" | grep -v .; then
- rm -f /tmp/sxmo_incomingcall
+ rm -f "$NOTIFDIR/sxmo_incomingcall"
return
fi
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/ring"
else
- sxmo_vibratepine 2000 & sxmo_setpineled green 1
+ sxmo_vibratepine 2000 &
fi
# Delete all previous calls which have been terminated calls
@@ -61,7 +61,7 @@ checkforincomingcalls() {
TIME="$(date --iso-8601=seconds)"
mkdir -p "$LOGDIR"
printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv"
- echo "$VOICECALLID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall
+ printf %b "$VOICECALLID:$INCOMINGNUMBER\n" > "$NOTIFDIR/sxmo_incomingcall"
echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)"
}
@@ -74,16 +74,8 @@ checkfornewtexts() {
echo "$TEXTIDS" | grep -v . && return
# Loop each textid received and read out the data into appropriate logfile
- {
- sxmo_setpineled green 1
- sxmo_vibratepine 200;
- sleep 0.1;
- sxmo_vibratepine 200;
- sleep 0.1;
- sxmo_vibratepine 200;
- } &
-
- for TEXTID in $(printf %b "$TEXTIDS") ; do
+ for TEXTID in $TEXTIDS; do
+
TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)"
TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')"
NUM="$(
@@ -97,12 +89,15 @@ checkfornewtexts() {
printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt"
printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv"
mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID"
+
+ CONTACT="$(sxmo_contacts.sh | grep "$NUM" || echo "$NUM")"
+ echo "$CONTACT" | grep -c . | grep 1 || CONTACT="$NUM"
+ ( sxmo_notificationwrite.sh "Message from $CONTACT: $TEXT" "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" "$LOGDIR/$NUM/sms.txt" & ) &
done
}
mainloop() {
while true; do
- sxmo_setpineled green 0
checkforincomingcalls
checkfornewtexts
sleep $TIMEOUT & wait
--
2.28.0
iressa <ian@eonndev.com> wrote:
> ---
> configs/appcfg/dunst.conf | 2 +
> scripts/core/sxmo_appmenu.sh | 13 ++++++-
> scripts/core/sxmo_notificationmonitor.sh | 48 ++++++++++++++++++++++++
> scripts/core/sxmo_notifications.sh | 16 ++++++++
> scripts/core/sxmo_notificationwrite.sh | 15 ++++++++
> scripts/core/sxmo_xinit.sh | 1 +
> scripts/modem/sxmo_modemmonitor.sh | 25 +++++-------
> 7 files changed, 103 insertions(+), 17 deletions(-)
> create mode 100755 scripts/core/sxmo_notificationmonitor.sh
> create mode 100755 scripts/core/sxmo_notifications.sh
> create mode 100755 scripts/core/sxmo_notificationwrite.sh
I finally got around to merging this - thanks for the many passes on
this and addressing feedback.
I took some liberties and built on what you did to make things a bit
more consistent with the existing style we have in other scripts. I
have more details in the git commit log; but the overview of the changes
ontop of your work here was:
- Made the interface consistent to *always* use the sxmo_notificationwrite.sh
script instead of manually writing notification files for modem events.
- Swapped order of notification file spec so content is last (that way multi-line
content doesn't create bugs)
- Made calls consistently use notification system as well :) I think
this is pretty nice because now we can get dunst notifications and pickup
straight from there.
- Made the syle fit existing patterns a bit more (e.g. documentation
in the form of function & variable names)
- Use stat/file datestamp rather then embedding that metadata in
filename; this also allows a more consistent interface so we don't need
extra workarounds for calls
Only thing I think this is missing now is missed call notifications (ok
pun intended :). I think there should be a way to determine in the modem
monitor script if a call was missed and then just write a notification via
the notification write script with an action that just pops ups st with
a huge font that says missed call from X with the metadata etc. Anyway
will sort that out soon I think.
Again thanks for your work on this - I think things are in pretty good
shape now and having a general purpose notifications system is a great
addition.
Miles