From c6536b76cd72ec3b0f6ed05a80ce2c12f8a27bf5 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Mon, 4 May 2026 22:13:56 -0700 Subject: [PATCH] Harden Emacs notification startup --- dotfiles/emacs.d/README.org | 32 ++++++++++++++++++++++++++++++-- dotfiles/emacs.d/org-config.org | 6 +++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 6529dd6d..049f0768 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -986,7 +986,12 @@ I keep it around just in case I need it. (shell-command (format "grownotify -t %s -m %s" title message))) (defun notify-send (title message) - (shell-command (format "notify-send -u critical %s %s" title message))) + (when-let ((program (executable-find "notify-send"))) + (let ((process-connection-type nil)) + (start-process "notify-send" nil program + "-u" "critical" + (or title "No title") + (or message "No message"))))) (defvar notify-function (cond ((eq system-type 'darwin) 'notification-center) @@ -3836,13 +3841,36 @@ This is useful with server mode when editing gmail messages. I think that it is (use-package alert :defer t :preface + (defun imalison:linux-notifications-available-p () + (and (eq system-type 'gnu/linux) + (executable-find "notify-send"))) + (defun imalison:notify-send-urgency (severity) + (pcase severity + ((or 'urgent 'high) "critical") + ('low "low") + (_ "normal"))) + (defun imalison:alert-notify-send (info) + (when-let ((program (executable-find "notify-send"))) + (let ((process-connection-type nil)) + (start-process "alert-notify-send" nil program + "-u" (imalison:notify-send-urgency + (plist-get info :severity)) + (or (plist-get info :title) "Emacs") + (or (plist-get info :message) ""))))) (defun imalison:windows-toast-notify (info) (let ((message (plist-get info :message)) (title (plist-get info :title))) (shell-command (format "windows_toast '%s' '%s'" (or title "No title") (or message "No message"))))) :config (progn - (setq alert-default-style 'libnotify) + (alert-define-style + 'notify-send + :title "notify-send" + :notifier 'imalison:alert-notify-send) + (setq alert-default-style + (if (imalison:linux-notifications-available-p) + 'notify-send + 'message)) (when (not (string-empty-p (shell-command-to-string "grep -i microsoft /proc/version"))) (alert-define-style 'windows-toast diff --git a/dotfiles/emacs.d/org-config.org b/dotfiles/emacs.d/org-config.org index 948a38c7..9e6e380a 100644 --- a/dotfiles/emacs.d/org-config.org +++ b/dotfiles/emacs.d/org-config.org @@ -1117,7 +1117,11 @@ alphanumeric characters only." (org-wild-notifier--apply-whitelist) (org-wild-notifier--apply-blacklist) (-map 'org-wild-notifier--gather-info)))) - (org-wild-notifier-mode +1) + (condition-case err + (org-wild-notifier-mode +1) + (error + (message "org-wild-notifier disabled during startup: %s" + (error-message-string err)))) (defun org-wild-notify-check-at-time () (interactive) (imalison:org-at-time