branch: externals/dtache commit 94f207eeeb57c2ca82598dd0434e3b9aa00c01b1 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Make dtache utilize notifications library This patch implements a notification message function which relies on the notifications library. This is made the default notifiction function, users have possibility to change to the function that uses the echo area instead. Or to use a custom function with alert, as specified in the README. --- CHANELOG.org | 1 + README.org | 2 +- dtache.el | 24 ++++++++++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANELOG.org b/CHANELOG.org index 6829cf3f88..50eca3a1e9 100644 --- a/CHANELOG.org +++ b/CHANELOG.org @@ -4,6 +4,7 @@ * Development +- =dtache= now uses =notifications= library to issue notifications by default. - =dtache= now uses =filenotify= for notifications except on local macOS hosts. * Version 0.3 (2022-01-15) diff --git a/README.org b/README.org index 1b2d678986..13383fadef 100644 --- a/README.org +++ b/README.org @@ -208,7 +208,7 @@ The user have the possibility to integrate =dtache= with the package [[https://g *** Alert -By default =dtache= uses the echo area to notify the user when a session has finished. An alternative is to utilize the [[https://github.com/jwiegley/alert][alert]] package to get a system notification instead. +By default =dtache= uses the built in =notifications= library to issue a notification. This solution uses =dbus= but if that doesn't work for the user there is the possibility to set the =dtache-notification-function= to =dtache-state-transitionion-echo-message= to use the echo area instead. If that doesn't suffice there is the possibility to use the [[https://github.com/jwiegley/alert][alert]] package to get a system notification instead. #+begin_src elisp :lexical t :results none (defun my/dtache-state-transition-notification (session) diff --git a/dtache.el b/dtache.el index 398bb16bc0..874f889db9 100644 --- a/dtache.el +++ b/dtache.el @@ -43,6 +43,7 @@ ;;;; Requirements (require 'autorevert) +(require 'notifications) (require 'filenotify) (require 'simple) (require 'tramp) @@ -119,7 +120,7 @@ :type '(repeat (regexp :format "%v")) :group 'dtache) -(defcustom dtache-notification-function #'dtache-state-transition-notification +(defcustom dtache-notification-function #'dtache-state-transition-notifications-message "Variable to set which function to use to issue a notification." :type 'function :group 'dtache) @@ -628,13 +629,28 @@ If session is not valid trigger an automatic cleanup on SESSION's host." 'success 'failure)))) -(defun dtache-state-transition-notification (session) - "Send a notification when SESSION transitions from active to inactive." +(defun dtache-state-transitionion-echo-message (session) + "Issue a notification when SESSION transitions from active to inactive. +This function uses the echo area." (let ((status (pcase (dtache--session-status session) ('success "Dtache finished") - ('failure "Dtache failed")) )) + ('failure "Dtache failed") + ('unknown "Dtache finished")) )) (message "%s: %s" status (dtache--session-command session)))) +(defun dtache-state-transition-notifications-message (session) + "Issue a notification when SESSION transitions from active to inactive. +This function uses the `notifications' library." + (let ((status (dtache--session-status session))) + (notifications-notify + :title (pcase status + ('success "Dtache finished!") + ('failure "Dtache failed!")) + :body (dtache--session-command session) + :urgency (pcase status + ('success 'normal) + ('failure 'critical))))) + (defun dtache-view-dwim (session) "View SESSION in a do what I mean fashion." (cond ((eq 'success (dtache--session-status session))