From 79e8cc51f104b35246e73c434a024f5635ddca5f Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Fri, 9 Sep 2022 12:40:33 -0500 Subject: [PATCH] Fix: (ement-notify) Ensure D-Bus is available Adds (ement-notify-dbus-p). Fixes #83. Thanks to Tassilo Horn (@tsdh) for reporting and providing the predicate code. Reported-by: Tassilo Horn Suggested-by: Tassilo Horn Co-authored-by: Tassilo Horn --- README.org | 1 + ement-notify.el | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.org b/README.org index 62ea2ab..dae3b70 100644 --- a/README.org +++ b/README.org @@ -264,6 +264,7 @@ Note that, while ~matrix-client~ remains usable, and probably will for some time *Fixed* + Function ~ement-room-sync~ correctly updates room-list buffers. (Thanks to [[https://github.com/vizs][Visuwesh]].) ++ Only send D-Bus notifications when supported. (Fixes [[https://github.com/alphapapa/ement.el/issues/83][#83]]. Thanks to [[https://github.com/tsdh][Tassilo Horn]].) ** 0.1.1 diff --git a/ement-notify.el b/ement-notify.el index 6107531..2b00160 100644 --- a/ement-notify.el +++ b/ement-notify.el @@ -48,6 +48,13 @@ (make-composed-keymap (list map button-buffer-map) 'view-mode-map)) "Map for Ement notification buffers.") +(defvar ement-notify-dbus-p + (and (featurep 'dbusbind) + (require 'dbus nil :no-error) + (dbus-ignore-errors (dbus-get-unique-name :session)) + (dbus-ping :session "org.freedesktop.Notifications")) + "Whether D-Bus notifications are usable.") + ;;;; Customization (defgroup ement-notify nil @@ -160,13 +167,13 @@ margins in Emacs. But it's useful, anyway." (defun ement-notify (event room session) "Send notifications for EVENT in ROOM on SESSION. -Calls functions in `ement-notify-functions' if all of -`ement-notify-ignore-predicates' return nil. Does not do -anything if session hasn't finished initial sync." +Sends if all of `ement-notify-ignore-predicates' return nil. +Does not do anything if session hasn't finished initial sync." (when (and (ement-session-has-synced-p session) (cl-loop for pred in ement-notify-ignore-predicates never (funcall pred event room session))) - (when (run-hook-with-args-until-success 'ement-notify-notification-predicates event room session) + (when (and ement-notify-dbus-p + (run-hook-with-args-until-success 'ement-notify-notification-predicates event room session)) (ement-notify--notifications-notify event room session)) (when (run-hook-with-args-until-success 'ement-notify-log-predicates event room session) (ement-notify--log-to-buffer event room session))