[emacs] Harden org-reminders: host guard, bell titles, high priority

This commit is contained in:
2026-08-09 15:41:18 -04:00
parent d48ebfb11a
commit 24d2c2b1bb
2 changed files with 24 additions and 5 deletions

View File

@ -29,6 +29,9 @@
(defvar org-reminder-ntfy-topic "reminders" (defvar org-reminder-ntfy-topic "reminders"
"ntfy topic to publish task reminders to.") "ntfy topic to publish task reminders to.")
(defvar org-reminder-ntfy-priority "4"
"ntfy priority for task reminders (1 min, 2 low, 3 default, 4 high, 5 urgent).")
(defvar org-reminder-state-file "~/.cache/org-reminders.el" (defvar org-reminder-state-file "~/.cache/org-reminders.el"
"File persisting already-sent reminders.") "File persisting already-sent reminders.")
@ -49,6 +52,17 @@ Set to \"none\" to disable the default entirely.")
(defvar org-reminder-last-refresh 0 (defvar org-reminder-last-refresh 0
"Timestamp of the last org-agenda-files refresh.") "Timestamp of the last org-agenda-files refresh.")
(defvar org-reminder-run-hosts nil
"Hostnames (as reported by `system-name') allowed to send reminders.
nil means run on every host. Set to a list like (\"mundilfari\") to
restrict reminder delivery to specific machines.")
(defun org-reminder-host-enabled-p ()
"Return non-nil if this host is allowed to send reminders."
(or (null org-reminder-run-hosts)
(member (downcase (system-name))
(mapcar #'downcase org-reminder-run-hosts))))
(defun org-reminder-parse-intervals (str) (defun org-reminder-parse-intervals (str)
"Parse reminder offset string STR into a list of (LABEL . SECONDS). "Parse reminder offset string STR into a list of (LABEL . SECONDS).
STR looks like \"2d 3h 30m\" (also accepts commas or semicolons). STR looks like \"2d 3h 30m\" (also accepts commas or semicolons).
@ -176,6 +190,7 @@ Uses an mtime cache so unchanged files are not re-parsed."
"-s" "-f" "-s" "-f"
"-H" (format "Title: %s" (substring-no-properties title)) "-H" (format "Title: %s" (substring-no-properties title))
"-H" "Tags: bell" "-H" "Tags: bell"
"-H" (format "Priority: %s" org-reminder-ntfy-priority)
"-d" body "-d" body
url))) url)))
(unless (zerop exit) (unless (zerop exit)
@ -216,6 +231,7 @@ Uses an mtime cache so unchanged files are not re-parsed."
(defun org-reminder-check () (defun org-reminder-check ()
"Send any due org task reminders via ntfy." "Send any due org task reminders via ntfy."
(interactive) (interactive)
(if (org-reminder-host-enabled-p)
(condition-case err (condition-case err
(let ((now (float-time))) (let ((now (float-time)))
(dolist (spec (org-reminder-collect)) (dolist (spec (org-reminder-collect))
@ -226,7 +242,7 @@ Uses an mtime cache so unchanged files are not re-parsed."
(< now (+ fire (* org-reminder-grace-minutes 60))) (< now (+ fire (* org-reminder-grace-minutes 60)))
(not (gethash key org-reminder-state))) (not (gethash key org-reminder-state)))
(org-reminder-send (org-reminder-send
(format "Reminder: %s" heading) (format "🔔 %s" heading)
(format "Due %s — %s away" (format "Due %s — %s away"
(format-time-string "%a %b %e %H:%M" (+ fire secs)) (format-time-string "%a %b %e %H:%M" (+ fire secs))
(org-reminder-human-delta (- (+ fire secs) now)))) (org-reminder-human-delta (- (+ fire secs) now))))
@ -234,12 +250,14 @@ Uses an mtime cache so unchanged files are not re-parsed."
(org-reminder-state-save) (org-reminder-state-save)
(message "org-reminders: sent '%s' (%s)" heading label))))) (message "org-reminders: sent '%s' (%s)" heading label)))))
(org-reminder-prune-state now))) (org-reminder-prune-state now)))
(error (message "org-reminders: check failed: %S" err)))) (error (message "org-reminders: check failed: %S" err)))
(message "org-reminders: host %s not enabled for reminders, skipping" (system-name))))
(defun org-reminder-start () (defun org-reminder-start ()
"Load state and start the periodic reminder check." "Load state and start the periodic reminder check on this host."
(org-reminder-state-load) (org-reminder-state-load)
(run-with-timer 60 60 #'org-reminder-check)) (when (org-reminder-host-enabled-p)
(run-with-timer 60 60 #'org-reminder-check)))
(provide '+org-reminders) (provide '+org-reminders)

View File

@ -43,6 +43,7 @@
(load! "+agenda-fix") (load! "+agenda-fix")
(load! "+org-reminders") (load! "+org-reminders")
(setq org-reminder-run-hosts '("mundilfari"))
(defun vulpea-agenda-files-update (&rest _) (defun vulpea-agenda-files-update (&rest _)
(setq org-agenda-files vulpea-project-files)) (setq org-agenda-files vulpea-project-files))