Look for ATTRIB events for notifications updates; remove "Pickup" menu
Picking up call can be done from both dunst notification & notifications menu; so for more consistency / less bugs the Pickup menu entry has been removed.
This commit is contained in:
parent
7559984430
commit
c5b665ca4f
5 changed files with 5 additions and 15 deletions
71
scripts/notifications/sxmo_notificationmonitor.sh
Executable file
71
scripts/notifications/sxmo_notificationmonitor.sh
Executable file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env sh
|
||||
trap gracefulexit INT TERM
|
||||
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
|
||||
|
||||
gracefulexit() {
|
||||
echo "Gracefully exiting $0"
|
||||
kill -9 0
|
||||
}
|
||||
|
||||
notificationhook() {
|
||||
if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/notification ]; then
|
||||
"$XDG_CONFIG_HOME"/sxmo/hooks/notification
|
||||
else
|
||||
sxmo_vibratepine 200;
|
||||
sleep 0.1;
|
||||
sxmo_vibratepine 200;
|
||||
sleep 0.1;
|
||||
fi
|
||||
}
|
||||
|
||||
handlenewnotiffile(){
|
||||
NOTIFFILE="$1"
|
||||
|
||||
if [ "$(wc -l "$NOTIFFILE" | cut -d' ' -f1)" -lt 3 ]; then
|
||||
echo "Invalid notification file $NOTIFFILE found (<3 lines -- see notif spec in sxmo_notifwrite.sh), deleting!" >&2
|
||||
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"
|
||||
elif [ -e "$NOTIFWATCHFILE" ]; then
|
||||
inotifywait "$NOTIFWATCHFILE" && rm -f "$NOTIFFILE" &
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
recreateexistingnotifs() {
|
||||
for NOTIF in "$NOTIFDIR"/*; do
|
||||
[ -f "$NOTIF" ] || continue
|
||||
handlenewnotiffile "$NOTIF"
|
||||
done
|
||||
}
|
||||
|
||||
monitorforaddordelnotifs() {
|
||||
while true; do
|
||||
inotifywait -e create,attrib,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ | (
|
||||
INOTIFYOUTPUT="$(cat)"
|
||||
INOTIFYEVENTTYPE="$(echo "$INOTIFYOUTPUT" | cut -d" " -f2)"
|
||||
case "$INOTIFYEVENTTYPE" in
|
||||
"CREATE"|"MOVED_TO","ATTRIB")
|
||||
NOTIFFILE="$NOTIFDIR/$(echo "$INOTIFYOUTPUT" | cut -d" " -f3)"
|
||||
handlenewnotiffile "$NOTIFFILE"
|
||||
;;
|
||||
"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
|
||||
;;
|
||||
esac
|
||||
) & wait
|
||||
done
|
||||
}
|
||||
|
||||
pgrep -f "$(command -v sxmo_notificationmonitor.sh)" | grep -Ev "^${$}$" | xargs kill
|
||||
sxmo_setpineled green 0
|
||||
recreateexistingnotifs
|
||||
monitorforaddordelnotifs
|
32
scripts/notifications/sxmo_notificationsmenu.sh
Executable file
32
scripts/notifications/sxmo_notificationsmenu.sh
Executable file
|
@ -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
|
25
scripts/notifications/sxmo_notificationwrite.sh
Executable file
25
scripts/notifications/sxmo_notificationwrite.sh
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env sh
|
||||
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
|
||||
|
||||
# Takes 4 args:
|
||||
# (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"
|
||||
|
||||
writenotification() {
|
||||
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
|
||||
touch "$NOTIFFILEPATHTOWRITE"
|
||||
printf %b "rm -f $NOTIFFILEPATHTOWRITE; $ACTION\n$WATCHFILE\n$NOTIFMSG\n" > "$NOTIFFILEPATHTOWRITE"
|
||||
}
|
||||
|
||||
[ "$#" -lt 4 ] && echo "Need >=4 args to create a notification" && exit 1
|
||||
writenotification
|
Loading…
Add table
Add a link
Reference in a new issue