This adds interactive notification support through a set of separate
notification watcher scripts, with an implementation added for SMS
messages in modemmonitor.sh. Any script that wants to send notifications
should do it through sxmo_notificationwrite.sh. This allows for a
general and hackable interface for notifications. There are a few key
parts to a "notification":
sxmo_notifications.sh: This is a menu application that appears in the
appmenu.sh context menu when it detects that there are files in the
NOTIFDIR directory. Accessing a notification through this will launch
whatever program the notification-sender intended.
sxmo_notificationwrite.sh: This is what applications can use to write
notifications to the system. Notifications are first fed through Dunst
(which provides a tappable pop-up), and then assigned a generated notif
file / an inotifywait session if not interacted with. Notifications are
stored in the NOTIFDIR directory and contain some metadata about what to
do when it's interacted with.
sxmo_notificationwatch.sh: This is an inotify wrapper for
sxmo_notificationwrite.sh and sxmo_notificationstart.sh. The inotify
session watches a "watch file" provided by the notification sender
through sxmo_notificationwrite.sh, and then removes the notification
when the watch file has been accessed.
sxmo_notificationstart.sh: This script looks at the NOTIFDIR directory
and starts inotify sessions for each notification. This is meant to be
used when the phone starts to keep inotify sessions persistent through
reboots. To use this, you can just put it in xinit.
TODO:
-Add compatibility with other things like RSS subscriptions or missed
calls.
-There might be compatibility issues with other applications that mess
with the green element of the LED.
-Need to start sxmo_notificationstart.sh when the phone wakes from deep
sleep to preserve inotify sessions.
-Put timestamps in notifications.sh. Dmenu doesn't play nice with tab
characters.
iressa (1):
Interactive notification support with inotify
configs/appcfg/dunst.conf | 2 ++
scripts/core/sxmo_appmenu.sh | 11 ++++++++-
scripts/core/sxmo_notifications.sh | 13 ++++++++++
scripts/core/sxmo_notificationstart.sh | 10 ++++++++
scripts/core/sxmo_notificationwatch.sh | 11 +++++++++
scripts/core/sxmo_notificationwrite.sh | 33 ++++++++++++++++++++++++++
scripts/modem/sxmo_modemmonitor.sh | 23 +++++++++---------
7 files changed, 91 insertions(+), 12 deletions(-)
create mode 100755 scripts/core/sxmo_notifications.sh
create mode 100755 scripts/core/sxmo_notificationstart.sh
create mode 100755 scripts/core/sxmo_notificationwatch.sh
create mode 100755 scripts/core/sxmo_notificationwrite.sh
--
2.27.0
---
configs/appcfg/dunst.conf | 2 ++
scripts/core/sxmo_appmenu.sh | 11 ++++++++-
scripts/core/sxmo_notifications.sh | 13 ++++++++++
scripts/core/sxmo_notificationstart.sh | 10 ++++++++
scripts/core/sxmo_notificationwatch.sh | 11 +++++++++
scripts/core/sxmo_notificationwrite.sh | 33 ++++++++++++++++++++++++++
scripts/modem/sxmo_modemmonitor.sh | 23 +++++++++---------
7 files changed, 91 insertions(+), 12 deletions(-)
create mode 100755 scripts/core/sxmo_notifications.sh
create mode 100755 scripts/core/sxmo_notificationstart.sh
create mode 100755 scripts/core/sxmo_notificationwatch.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 5e357f2..9cb4d3f 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"
@@ -252,6 +253,14 @@ getprogchoices() {
"
fi
+ # Decorate menu at top w/ notifications if they exist
+ NOTIFICATIONS="$(ls $NOTIFDIR/ | wc -l || 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
@@ -302,4 +311,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..9f54b27
--- /dev/null
+++ b/scripts/core/sxmo_notifications.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env sh
+
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
+
+while true; do
+ CHOICES="$(cat $NOTIFDIR/*)"
+ 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
+
+ $(printf %b "$CHOICES" | grep "$PICKED" | cut -f3)
+ exit 0
+done
diff --git a/scripts/core/sxmo_notificationstart.sh b/scripts/core/sxmo_notificationstart.sh
new file mode 100755
index 0000000..6bd385b
--- /dev/null
+++ b/scripts/core/sxmo_notificationstart.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env sh
+
+# This script should be run to initialize the notification watchers.
+
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
+
+ for NOTIF in $(ls $NOTIFDIR/); do
+ ( sxmo_notificationwatch.sh "$(cut -f4 "$NOTIFDIR"/"$NOTIF")" "$NOTIFDIR/$NOTIF" & )
+ done
+exit 0
diff --git a/scripts/core/sxmo_notificationwatch.sh b/scripts/core/sxmo_notificationwatch.sh
new file mode 100755
index 0000000..a6e461a
--- /dev/null
+++ b/scripts/core/sxmo_notificationwatch.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env sh
+
+# This script is basically just a inotify wrapper for sxmo_notificationwrite.sh and sxmo_notificationstart.sh. Takes 2 arguments, (1) The watch file, and (2) the notification file.
+
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
+echo $2 | grep -v . && { echo "Not enough args."; exit 2; }
+
+echo "$(ls $NOTIFDIR/ | wc -l || echo 0)" | grep -v 0 && sxmo_setpineled green 1
+inotifywait $1
+rm -f $2
+echo "$(ls $NOTIFDIR/ | wc -l || echo 0)" | grep 0 && sxmo_setpineled green 0
diff --git a/scripts/core/sxmo_notificationwrite.sh b/scripts/core/sxmo_notificationwrite.sh
new file mode 100755
index 0000000..ffe043f
--- /dev/null
+++ b/scripts/core/sxmo_notificationwrite.sh
@@ -0,0 +1,33 @@
+#!/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.
+# The message will first be fed to Dunst, and then will be handled based on whether the user interacts with the notification or not.
+# A notification file has 4 different fields, (1) a timestamp, (2) a fuzzy description, (3) the selection action, and (4) the watch file.
+
+NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
+TIMEFORMAT="$(date "+%a %m/%d %T")"
+
+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
+
+{
+ sxmo_vibratepine 200;
+ sleep 0.1;
+ sxmo_vibratepine 200;
+ sleep 0.1;
+ sxmo_vibratepine 200;
+} &
+
+# Dunstify and handle input
+DUNST_RETURN=$(dunstify --action="2,open" "$1");
+ echo $DUNST_RETURN | grep -v 2 || { $2& exit 0; }
+ OUTFILE=$NOTIFDIR/$(date "+%Y_%m_%d_%H_%M_%S_%N").tsv
+ printf %b "$(echo $TIMEFORMAT)\t$1\t$2\t$3\n" > $OUTFILE
+
+# Start inotify session
+ ( sxmo_notificationwatch.sh $3 $OUTFILE & )
+
+exit 0
diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh
index 6283df3..ee0e24a 100755
--- a/scripts/modem/sxmo_modemmonitor.sh
+++ b/scripts/modem/sxmo_modemmonitor.sh
@@ -74,18 +74,11 @@ 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+//')"
+ TRUNCATED="$(echo "$TEXT" | sed ':a;N;$!ba;s/\n/ /g' | cut -c1-70)"
NUM="$(
echo "$TEXTDATA" |
grep sms.content.number |
@@ -97,12 +90,20 @@ 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)"
+
+ # Send a notice of each message to a notification file / watcher
+ if [ "$TEXT" == "$TRUNCATED" ]; then
+ ( sxmo_notificationwrite.sh "Message from $CONTACT: $TEXT" "st -e tail -n9999 -f "$LOGDIR/$NUM/sms.txt"" "$LOGDIR/$NUM/sms.txt" & ) &
+ else
+ ( sxmo_notificationwrite.sh "Message from $CONTACT: $TRUNCATED..." "st -e tail -n9999 -f "$LOGDIR/$NUM/sms.txt"" "$LOGDIR/$NUM/sms.txt" & ) &
+ fi
done
}
mainloop() {
while true; do
- sxmo_setpineled green 0
checkforincomingcalls
checkfornewtexts
sleep $TIMEOUT & wait
--
2.27.0