Skip to content

Commit

Permalink
resolve many notifications issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bkw777 committed May 23, 2020
1 parent 6ed894b commit e85d8dc
Show file tree
Hide file tree
Showing 23 changed files with 883 additions and 954 deletions.
2 changes: 1 addition & 1 deletion .deb_build_number.mak
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This file is generated by Makefile "make deb_build_number"
DEB_PKG_VERSION := 1.0.10
DEB_PKG_VERSION := 1.0.11
DEB_BUILD_NUMBER := 0000
2 changes: 1 addition & 1 deletion BRANDING.mak
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_MICRO = 10
VERSION_MICRO = 11
BRANDING_SHORTNAME = mainline
BRANDING_LONGNAME = Ubuntu Mainline Kernel Installer
BRANDING_AUTHORNAME = Brian K. White
Expand Down
14 changes: 14 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
mainline (1.0.11) unstable; urgency=medium

* Resolved several issues with notifications bacground processes and temp files
* Removed redundant notification setting, since now the desktop notifications are the only kind
* The background notification loop is restarted any time settings are saved in the app
so the settings now take effect immediately.
* When a new notifications is sent which replaces an existing notification,
it no longer adds more dbus monitor processes with each new update.
* Logging out and back in no longer adds more notify.sh processes. It still doesn't exit when you log out,
but at least it kills it's old instance when starting a new instance at logon.
* notify-send.sh and notify-action.sh are completely re-written and refactored to be more efficient and more reliable.

-- Brian K. White <[email protected]> Sat, 23 May 2020 00:05:21 -0400

mainline (1.0.10) unstable; urgency=medium

* Notifications
Expand Down
1 change: 1 addition & 0 deletions lib/notify_send/AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Brian K. White <https://github.com/bkw777>
Vyacheslav Levit <[email protected]>
Max Weller <https://github.com/max-weller>
bsilvereagle <https://github.com/bsilvereagle>
Expand Down
5 changes: 5 additions & 0 deletions lib/notify_send/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# notify-send.sh

----
**This copy has been modified for https://github.com/bkw777/mainline**

----

notify-send.sh is a drop-in replacement for notify-send (from
libnotify) with ability to update and close existing notifications.

Expand Down
126 changes: 67 additions & 59 deletions lib/notify_send/notify-action.sh
Original file line number Diff line number Diff line change
@@ -1,68 +1,76 @@
#!/usr/bin/env bash
#!/bin/bash

GDBUS_MONITOR_PID=/tmp/notify-action-dbus-monitor.$$.pid
GDBUS_MONITOR=(gdbus monitor --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications)
### 20200520 [email protected]
# This is completely re-written for https://github.com/bkw777/mainline
#
# * If REPLACE_ID then find the PID of any previous monitor for the same NOTIFICATION_ID
# and kill that process and replace it, rather than add more and more monitor processes.
# * Run gdbus in {} instead of ()
# * Parse gdbus output without $(sed ...)
# * Close notifcation after receiving any action.
# * Robust pid file and old-job processing
# * Robust cleanup on exit
# * Vastly refactored to use all bash built-in features
# and no child processes except gdbus and the invoked actions
# no more sed to parse output or foo=$(command ...) to collect output etc
# * Use APP_NAME (if present) in place of $0 in pid filename
# * setsid to free ourself from the invoved action process

NOTIFICATION_ID="$1"
if [[ -z "$NOTIFICATION_ID" ]]; then
echo "no notification id passed: $@"
exit 1;
fi
shift
NOTIFY_SEND=${0%/*}/notify-send.sh
GDBUS_ARGS=(monitor --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications)
SELF=${0##*/}
GDBUS_PIDF=/tmp/${APP_NAME:=${SELF}}.${$}.p

ACTION_COMMANDS=("$@")
if [[ -z "$ACTION_COMMANDS" ]]; then
echo "no action commands passed: $@"
exit 1;
fi
set +H
shopt -s extglob

cleanup() {
rm -f "$GDBUS_MONITOR_PID"
}
abrt () { echo "${0}: ${@}" >&2 ; exit 1 ; }

create_pid_file(){
rm -f "$GDBUS_MONITOR_PID"
umask 077
touch "$GDBUS_MONITOR_PID"
}
# consume the command line
typeset -i ID="${1}" ;shift
[[ ${ID} -gt 0 ]] || abrt "no notification id"
declare -A a ;while [[ "${1}" ]] ;do a[${1}]=${2} ;shift 2 ;done
[[ ${#a[@]} -gt 0 ]] || abrt "no actions"

invoke_action() {
invoked_action_id="$1"
local action="" cmd=""
for index in "${!ACTION_COMMANDS[@]}"; do
if [[ $((index % 2)) == 0 ]]; then
action="${ACTION_COMMANDS[$index]}"
else
cmd="${ACTION_COMMANDS[$index]}"
if [[ "$action" == "$invoked_action_id" ]]; then
bash -c "${cmd}" &
fi
fi
done
}
[[ "${DISPLAY}" ]] || abrt "no DISPLAY"
typeset -i i=0 p=0
# start the pid file, no PID or linefeed yet
echo -n "${DISPLAY} ${ID} " > ${GDBUS_PIDF}

monitor() {
# kill any duplicate jobs older than ourself
for f in /tmp/${APP_NAME}.+([0-9]).p ;do
[[ -s "${f}" ]] || continue
[[ ${f} -ot ${GDBUS_PIDF} ]] || continue
read d i p x < "${f}"
[[ "${d}" == "${DISPLAY}" ]] || continue
[[ ${i} == ${ID} ]] || continue
[[ ${p} -gt 0 ]] || continue
rm -f "${f}"
kill ${p}
done

create_pid_file
( "${GDBUS_MONITOR[@]}" & echo $! >&3 ) 3>"$GDBUS_MONITOR_PID" | while read -r line
do
local closed_notification_id="$(sed '/^\/org\/freedesktop\/Notifications: org.freedesktop.Notifications.NotificationClosed (uint32 \([0-9]\+\), uint32 [0-9]\+)$/!d;s//\1/' <<< "$line")"
if [[ -n "$closed_notification_id" ]]; then
if [[ "$closed_notification_id" == "$NOTIFICATION_ID" ]]; then
invoke_action close
break
fi
else
local action_invoked="$(sed '/\/org\/freedesktop\/Notifications: org.freedesktop.Notifications.ActionInvoked (uint32 \([0-9]\+\), '\''\(.*\)'\'')$/!d;s//\1:\2/' <<< "$line")"
IFS=: read invoked_id action_id <<< "$action_invoked"
if [[ "$invoked_id" == "$NOTIFICATION_ID" ]]; then
invoke_action "$action_id"
break
fi
fi
done
kill $(<"$GDBUS_MONITOR_PID")
cleanup
}
# start the dbus monitor
{
gdbus ${GDBUS_ARGS[@]} & echo "${!}" >> ${GDBUS_PIDF}
} |while IFS+=":.()," read x x x x e x i k x ;do
[[ ${i} == ${ID} ]] || continue
k=${k:1} k=${k:0:-1}
case "${e}" in
"NotificationClosed") k="close" ;;
"ActionInvoked") "${NOTIFY_SEND}" -s ${ID} ;;
esac
setsid -f bash -c "${a[${k}]}" >/dev/null 2>&1 &
break
done

monitor
# kill the dbus monitor
# Our gdbus process might be killed by a new instance of ourself (see above)
# while we wait forever for a dbus event that never came. So here, don't treat
# a missing file as an alarming error. Above, we will delete the file before we
# kill the gdbus process so that here, we can't end up trying to kill a random
# unrelated new process that happened to get the same PID after it was freed.
[[ -s ${GDBUS_PIDF} ]] || exit
read d i p x < ${GDBUS_PIDF}
rm -f ${GDBUS_PIDF}
[[ ${p} -gt 0 ]] || exit
kill ${p}
Loading

0 comments on commit e85d8dc

Please sign in to comment.