notifier

Checks current IM messages for different platforms and sends a notification for new messages
git clone https://src.jayvii.de/pub/notifier.git
Log | Files | Refs | README

commit aef20c82aa72bc5d94d018a2b877b9c68bea4623
parent b5bdd6d6d01be0092478fc00a0e4c399883c59f8
Author: JayVii <jayvii@posteo.de>
Date:   Sat, 28 Aug 2021 15:17:32 +0200

Add Signal Listener and Actions

Diffstat:
Mim-notifier.sh | 38+++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/im-notifier.sh b/im-notifier.sh @@ -6,29 +6,30 @@ TIMEOUT=25 # Telegram Settings TELEGRAM=1 -TG_LED=1 TG_NOTIFICATION_ID=0 - +TG_ICON="document-send" # or "telegram", if installed +TG_ACTION="telegram-desktop" # Modules --------------------------------------------------------------------- ## Common function im_notify { - if [[ "$XDG_CURRENT_DESKTOP" == "GNOME:Phosh" ]]; then + if [[ "$XDG_CURRENT_DESKTOP" == "GNOME:Phosh" ]] || + [[ "$XDG_CURRENT_DESKTOP" == "GNOME" ]] || + [[ "$XDG_CURRENT_DESKTOP" == "gnome" ]]; then gdbus call --session \ --dest=org.freedesktop.Notifications \ --object-path=/org/freedesktop/Notifications \ --method=org.freedesktop.Notifications.Notify \ - "$1" $2 "$3" "$1" "$4" '[]' '{"category": <"im.received">}' 3000 + "$1" $2 "$3" "$1" "$4" "$5" \ + '{"category": <"im.received">}' 3000 else # unfortunately, this does not replace old messages notify-send --app-name="$3" --icon="$3" --category="im.received" \ "$1" "$4" echo 0 fi - if [[ $5 != 0 ]]; then - echo 1 > /sys/devices/platform/leds/leds/blue\:indicator/brightness - fi + im_signal_listen & } function im_unnotify { if [[ "$XDG_CURRENT_DESKTOP" == "GNOME:Phosh" ]]; then @@ -40,9 +41,16 @@ function im_unnotify { else echo 0 fi - if [[ $2 != 0 ]]; then - echo 0 > /sys/devices/platform/leds/leds/blue\:indicator/brightness - fi +} +function im_signal_listen { + while :; do + INVOKEDACTION=$(dbus-monitor "type='signal',sender='org.freedesktop.Notifications',interface='org.freedesktop.Notifications'" | \ + head -7 | \ + grep -E "im-notify-*") + if [[ "$INVOKEDACTION" == " string \"im-notify-tg\"" ]]; then + exec "${TG_ACTION}" + fi + done } ## Telegram @@ -58,13 +66,17 @@ function tg_kill { fi } function tg_notify { - im_notify "Telegram" $2 "telegram" "$1" $TG_LED + im_notify "Telegram" $2 "$TG_ICON" "$1" "$3" \ + "['im-notify-tg', 'Open Message']" } # Run Daemon ------------------------------------------------------------------ # Notify user about running state of the daemon -im_notify "IM-Notifier" 0 "gnome-settings" "IM-Notifier is running..." 0 +im_notify "IM-Notifier" 0 "gnome-settings" "IM-Notifier is running..." "[]" + +# Run Signal Listener +im_signal_listen & # Run daemon in endless while-loop while :; do @@ -96,6 +108,6 @@ while :; do done # Notify user about running state of the daemon -im_notify "IM-Notifier" 0 "gnome-settings" "IM-Notifier stopped..." 0 +im_notify "IM-Notifier" 0 "gnome-settings" "IM-Notifier stopped..." "[]" # EOF im-notifier.sh