~mil/sxmo-devel

Interactive notification/dunst support for SMS v1 SUPERSEDED

This patch adds support for text message notifications with dunst and
read/unread awareness with inotify. A notifications.sh script is added
to show up as a member of the contect menu when there are unread text
messages.

Unread messages are stored on the modem's flash, and they are deleted
when the sender's message log is accessed.

Note that this patch modifies modemmonitor.sh so that the LED should be
green as long as there are unread messages. Dunst notifications can also
be tapped to view the sender message log, and thus dismiss the unread
alert for that message.

iressa (1):
  Interactive notification/dunst support for SMS

 configs/dunst.conf                 |  2 ++
 scripts/core/sxmo_appmenu.sh       | 10 +++++-
 scripts/core/sxmo_notifications.sh | 15 +++++++++
 scripts/modem/sxmo_modemmonitor.sh | 52 ++++++++++++++++++++++--------
 4 files changed, 65 insertions(+), 14 deletions(-)
 create mode 100755 scripts/core/sxmo_notifications.sh

-- 
2.27.0
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/11449/mbox | git am -3
Learn more about email & git

[PATCH 1/1] Interactive notification/dunst support for SMS Export this patch

---
 configs/dunst.conf                 |  2 ++
 scripts/core/sxmo_appmenu.sh       | 10 +++++-
 scripts/core/sxmo_notifications.sh | 15 +++++++++
 scripts/modem/sxmo_modemmonitor.sh | 52 ++++++++++++++++++++++--------
 4 files changed, 65 insertions(+), 14 deletions(-)
 create mode 100755 scripts/core/sxmo_notifications.sh

diff --git a/configs/dunst.conf b/configs/dunst.conf
index a7f9323..b2bddee 100644
--- a/configs/dunst.conf
+++ b/configs/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 7337cb2..ad78fc1 100755
--- a/scripts/core/sxmo_appmenu.sh
+++ b/scripts/core/sxmo_appmenu.sh
@@ -221,6 +221,14 @@ getprogchoices() {
		"
	fi

	# Decorate menu at top w/ notifications if they exist
	NOTIFICATIONS="$(wc -l /tmp/sxmo_notifications.tsv || echo 0)"
	echo $NOTIFICATIONS | grep -v 0 &&
		CHOICES="
			Notifications ($(echo $NOTIFICATIONS | cut -d " " -f1)) ^ 0 ^ sxmo_notifications.sh
			$CHOICES
		"

	# Decorate menu at bottom w/ system menu entry if not system menu
	echo $WINNAME | grep -v Sys && CHOICES="
		$CHOICES
@@ -271,4 +279,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_notifications.sh b/scripts/core/sxmo_notifications.sh
new file mode 100755
index 0000000..dfb7103
--- /dev/null
+++ b/scripts/core/sxmo_notifications.sh
@@ -0,0 +1,15 @@
#!/usr/bin/env sh

NOTIFFILE=/tmp/sxmo_notifications.tsv

#TODO: put calls here as well.
while true; do
	CHOICES="$(printf %b "$(cat $NOTIFFILE | cut -f1)"'\nClose Menu')"
	PICKED="$(echo "$CHOICES" | dmenu -c -fn "Terminus-18" -p "Notifs" -l 10)"
	ENTRY="$(grep -n "$PICKED" $NOTIFFILE | cut -f1 -d:)"

	echo "$PICKED" | grep "Close Menu" && exit 0
	
	st -e tail -n9999 -f "$(sed -n $(echo $ENTRY)p $NOTIFFILE | cut -f2)"
	exit 0
done
diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh
index d515d36..dd972ef 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
NOTIFFILE=/tmp/sxmo_notifications.tsv
trap "gracefulexit" INT TERM

err() {
@@ -20,6 +21,13 @@ modem_n() {
	echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}

notifyd() {
	inotifywait "$LOGDIR/$1/sms.txt" 
	mmcli -m "$(modem_n)" --messaging-delete-sms="$2" 
	ENTRY="$(cut -f3 $NOTIFFILE | grep -n ^"$2"$ | cut -f1 -d:)" 
	sed -i $(echo $ENTRY)d $NOTIFFILE
}

checkforincomingcalls() {
	VOICECALLID="$(
		mmcli -m "$(modem_n)" --voice-list-calls -a |
@@ -62,26 +70,29 @@ checkforincomingcalls() {
}

checkfornewtexts() {
	OLDTEXTIDS="$TEXTIDS"
	TEXTIDS="$(
		mmcli -m "$(modem_n)" --messaging-list-sms |
		grep -Eo '/SMS/[0-9]+ \(received\)' |
		grep -Eo '[0-9]+'
	)"
	echo "$TEXTIDS" | grep -v . && return
	echo "$TEXTIDS" | grep -v . && { sxmo_setpineled green 0 && return; }
	sxmo_setpineled green 1

	# 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 $(printf %b "$TEXTIDS" | grep -Fxv "$OLDTEXTIDS") ; do

		{
			sxmo_vibratepine 200;
			sleep 0.1;
			sxmo_vibratepine 200;
			sleep 0.1;
			sxmo_vibratepine 200;
		} &

		TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)"
		TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')"
		TRUNCATED="$(echo "$TEXT" | sed ':a;N;$!ba;s/\n/ /g' | cut -c1-70)"
		NUM="$(
			echo "$TEXTDATA" | 
			grep sms.content.number | 
@@ -92,13 +103,28 @@ checkfornewtexts() {
		mkdir -p "$LOGDIR/$NUM"
		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)"
		printf %b "Message from $CONTACT\t$LOGDIR/$NUM/sms.txt\t$TEXTID\n" >> $NOTIFFILE

		# Create inotifywait session for logfile and fork to background
		(notifyd $NUM $TEXTID &)

		# Dunstify each message and handle input
		if [ "$TEXT" == "$TRUNCATED" ]; then
			( DUNST_RETURN=$(dunstify --action="2,Read" "Message from $CONTACT: $TEXT") ;
			echo $DUNST_RETURN | grep -v 2 ||
			st -e tail -n9999 -f "$LOGDIR/$NUM/sms.txt" & ) &
		else
			( DUNST_RETURN=$(dunstify --action="2,Read" "Message from $CONTACT: $TRUNCATED...") ;
			echo $DUNST_RETURN | grep -v 2 ||
			st -e tail -n9999 -f "$LOGDIR/$NUM/sms.txt" & ) &
		fi
	done
}

mainloop() {
	while true; do
		sxmo_setpineled green 0
		checkforincomingcalls
		checkfornewtexts
		sleep $TIMEOUT & wait
-- 
2.27.0