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 <tsdh@gnu.org>
Suggested-by: Tassilo Horn <tsdh@gnu.org>
Co-authored-by: Tassilo Horn <tsdh@gnu.org>
This commit is contained in:
Adam Porter 2022-09-09 12:40:33 -05:00
parent 82d598a22a
commit 79e8cc51f1
2 changed files with 12 additions and 4 deletions

View file

@ -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

View file

@ -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))