summaryrefslogtreecommitdiffhomepage
path: root/lib/eos/jao-notify.el
blob: 8389b3aa1540757879e16d7eff2ef7da4d26f08c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;; jao-notify.el -- Interacting with notification daemon

;; Copyright (c) 2017, 2019, 2020, 2021, 2024, 2025 Jose Antonio Ortega Ruiz

;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Sun Jan 08, 2017 20:24


;;; Comentary:

;; Simple notifications using echo or dbus notifications

;;; Code:

(defvar jao-notify-use-messages nil)
(defvar jao-notify-timeout 5000)
(defvar jao-notify-audio-icon (jao-data-file "music-player-icon.png"))

(declare-function notifications-notify "notifications")
(declare-function alert "alert")
(declare-function jao-mac-notify "jao-mac")

;; "/usr/share/icons/Papirus/64x64/mimetypes/audio-x-generic.svg"
;; "/usr/share/icons/Tango/scalable/mimetypes/audio-x-generic.svg"

(defun jao-notify (msg &optional title icon subtitle)
  (let ((title (when (and title (not (string-blank-p title))) title)))
    (cond ((eq jao-notify-use-messages t)
           (message "%s%s%s" (or title "") (if title ": " "") (or msg "")))
          ((eq jao-notify-use-messages 'notification)
           (let* ((args `(:timeout ,jao-notify-timeout))
                  (args (append args
                                (if title
                                    `(:title ,title :body ,msg)
                                  `(:title ,msg))))
                  (args (if (and (stringp icon) (file-exists-p icon))
                            (append args `(:app-icon ,(format "%s" icon)))
                          args)))
             (apply 'notifications-notify args)))
          ((eq jao-notify-use-messages 'alert)
           (alert msg :title title :icon icon :never-persist t))
          ((eq jao-notify-use-messages 'mac)
           (jao-mac-notify title subtitle msg)))))


(provide 'jao-notify)
;;; jao-notify.el ends here