Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.142]) by mail-b.sr.ht (Postfix) with ESMTPS id D82D8FF111 for <~mil/sxmo-devel@lists.sr.ht>; Sat, 4 Jul 2020 11:28:23 +0000 (UTC) Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 8199A24059C for <~mil/sxmo-devel@lists.sr.ht>; Sat, 4 Jul 2020 13:28:21 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49zV2D4FKRz9rxG; Sat, 4 Jul 2020 13:28:20 +0200 (CEST) From: iressa To: ~mil/sxmo-devel@lists.sr.ht Cc: iressa Subject: [PATCH 1/1] Interactive notification/dunst support for SMS Date: Sat, 4 Jul 2020 07:28:06 -0400 Message-Id: <20200704112806.26106-2-ian@eonndev.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200704112806.26106-1-ian@eonndev.com> References: <20200704112806.26106-1-ian@eonndev.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable --- 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 =3D Dunst class =3D Dunst startup_notification =3D false + mouse_left_click =3D do_action + [shortcuts] close_all =3D ctrl+shift+space =20 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 =20 + # Decorate menu at top w/ notifications if they exist + NOTIFICATIONS=3D"$(wc -l /tmp/sxmo_notifications.tsv || echo 0)" + echo $NOTIFICATIONS | grep -v 0 && + CHOICES=3D" + Notifications ($(echo $NOTIFICATIONS | cut -d " " -f1)) ^ 0 ^ sxmo_no= tifications.sh + $CHOICES + " + # Decorate menu at bottom w/ system menu entry if not system menu echo $WINNAME | grep -v Sys && CHOICES=3D" $CHOICES @@ -271,4 +279,4 @@ pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "= ^${$}$" | xargs kill -TERM DMENUIDX=3D0 PICKED=3D"" ARGS=3D"$*" -mainloop \ No newline at end of file +mainloop diff --git a/scripts/core/sxmo_notifications.sh b/scripts/core/sxmo_notif= ications.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=3D/tmp/sxmo_notifications.tsv + +#TODO: put calls here as well. +while true; do + CHOICES=3D"$(printf %b "$(cat $NOTIFFILE | cut -f1)"'\nClose Menu')" + PICKED=3D"$(echo "$CHOICES" | dmenu -c -fn "Terminus-18" -p "Notifs" -l= 10)" + ENTRY=3D"$(grep -n "$PICKED" $NOTIFFILE | cut -f1 -d:)" + + echo "$PICKED" | grep "Close Menu" && exit 0 +=09 + 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_mode= mmonitor.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=3D3 LOGDIR=3D"$XDG_CONFIG_HOME"/sxmo/modem +NOTIFFILE=3D/tmp/sxmo_notifications.tsv trap "gracefulexit" INT TERM =20 err() { @@ -20,6 +21,13 @@ modem_n() { echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 } =20 +notifyd() { + inotifywait "$LOGDIR/$1/sms.txt"=20 + mmcli -m "$(modem_n)" --messaging-delete-sms=3D"$2"=20 + ENTRY=3D"$(cut -f3 $NOTIFFILE | grep -n ^"$2"$ | cut -f1 -d:)"=20 + sed -i $(echo $ENTRY)d $NOTIFFILE +} + checkforincomingcalls() { VOICECALLID=3D"$( mmcli -m "$(modem_n)" --voice-list-calls -a | @@ -62,26 +70,29 @@ checkforincomingcalls() { } =20 checkfornewtexts() { + OLDTEXTIDS=3D"$TEXTIDS" TEXTIDS=3D"$( 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 =20 # Loop each textid received and read out the data into appropriate logf= ile - { - 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=3D"$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)" TEXT=3D"$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.c= ontent\.text\s+:\s+//')" + TRUNCATED=3D"$(echo "$TEXT" | sed ':a;N;$!ba;s/\n/ /g' | cut -c1-70)" NUM=3D"$( echo "$TEXTDATA" |=20 grep sms.content.number |=20 @@ -92,13 +103,28 @@ checkfornewtexts() { mkdir -p "$LOGDIR/$NUM" printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/s= ms.txt" printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modeml= og.tsv" - mmcli -m "$(modem_n)" --messaging-delete-sms=3D"$TEXTID" + + CONTACT=3D"$(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" =3D=3D "$TRUNCATED" ]; then + ( DUNST_RETURN=3D$(dunstify --action=3D"2,Read" "Message from $CONTAC= T: $TEXT") ; + echo $DUNST_RETURN | grep -v 2 || + st -e tail -n9999 -f "$LOGDIR/$NUM/sms.txt" & ) & + else + ( DUNST_RETURN=3D$(dunstify --action=3D"2,Read" "Message from $CONTAC= T: $TRUNCATED...") ; + echo $DUNST_RETURN | grep -v 2 || + st -e tail -n9999 -f "$LOGDIR/$NUM/sms.txt" & ) & + fi done } =20 mainloop() { while true; do - sxmo_setpineled green 0 checkforincomingcalls checkfornewtexts sleep $TIMEOUT & wait --=20 2.27.0