~protesilaos/tmr

Define tmr-notify-function and tmr-notifications-notify implementation v1 APPLIED

Christian Tietze: 3
 Define tmr-notify-function and tmr-notifications-notify implementation
 Rename tmr--notify-send to tmr--notify
 Extract tmr--notify-send-notification

 3 files changed, 28 insertions(+), 11 deletions(-)
Hey!
Ok, the patch sending now appears kind of rude since there's no initial
email and the original subject doesn't make sense. Sorry, git send-email
noob here! :)

Probably should've sent an email first with the intention, then used
send-email as replies to that? Hm.
So what's the idea:

`tmr' 0.2 uses D-Bus, which doesn't really work on macOS at all.
1) I extracted the D-BUS notification function call into
   `tmr-notifications-notify'. This way, it could be replaced if the
   reference was configurable. So:

2) I reference `tmr-notifications-notify` from the new custom variable
   `tmr-notify-function'. Now it's configurable.

3) The actual sending of a notification and usage of the function
   reference is implemented in the private function
   `tmr--notify-send-notification'. That accepts the title and message
   of the notification.
For `appt', I had this function already, and could reuse it:

(defun ct/send-notification (title msg)
  (let ((notifier-path (executable-find "alerter")))
       (start-process
           "Appointment Alert"
           "*Appointment Alert*" ;; nil to not capture output
           notifier-path
           "-message" msg
           "-title" title
           "-sender" "org.gnu.Emacs"
           "-activate" "org.gnu.Emacs")))
(setq tmr-notify-function #'ct/send-notification)

And yes, that does display a native macOS notification (using a 3rd
party tool, though).

Considerations:

- "TMR Must Recur" was a confusing default title. I kept it here.
- Function names and the custom variable name could be changed.

Cheers,
Christian
Hi Protesilaos!

Still no news from the FSF, so let's see how far we can get without them :)

Next
> From: Christian Tietze <me@christiantietze.de>
> Date: Thu, 05 May 2022 21:44:47 +0200
Next
Paperwork is finished (I emailed you privately). So do you want me to adjust anything in this patch?

-- Christian
> From: Christian Tietze <me@christiantietze.de>
> Date: Wed, 11 May 2022 09:19:38 +0200
> 
> Paperwork is finished (I emailed you privately).
Got it.  Thank you!
> So do you want me to adjust anything in this patch?
I did install your three patches when you first sent them:

    e4fb57f 2022-04-26 Christian Tietze: Extract tmr--notify-send-notification
    12ac2b0 2022-04-26 Christian Tietze: Rename tmr--notify-send to tmr--notify
    2ecee44 2022-04-26 Christian Tietze: Define tmr-notify-function and tmr-notifications-notify implementation

Now there is no legal constraint: you can send as many patches as you
want.  We discussed earlier how the notifications should be abstracted
to work with different clients/programs.  Maybe you want to make it
happen?  In general, I am happy with whatever you wish to do.

-- 
Protesilaos Stavrou
https://protesilaos.com
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~protesilaos/tmr/patches/31604/mbox | git am -3
Learn more about email & git

[PATCH 1/3] Define tmr-notify-function and tmr-notifications-notify implementation Export this patch

Signed-off-by: Christian Tietze <me@christiantietze.de>
---
 tmr.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tmr.el b/tmr.el
index f1683a5..010d12b 100644
--- a/tmr.el
+++ b/tmr.el
@@ -97,6 +97,12 @@ such notifications."
  :type '(repeat string)
  :group 'tmr)

(defcustom tmr-notify-function #'tmr-notifications-notify
  "Function called to send notification.
It should take two string arguments: the title and the message."
  :type 'function
  :group 'tmr)

(defun tmr--unit (time)
  "Determine common time unit for TIME."
  (cond
@@ -152,6 +158,17 @@ such notifications."
          win))
    (user-error "No *tmr-messages* buffer; have you used `tmr'?")))

(defun tmr-notifications-notify (title message)
  "Dispatch notification titled TITLE with MESSAGE via D-Bus.

Read: (info \"(elisp) Desktop Notifications\") for details."
  (notifications-notify
   :title title
   :body message
   :app-name "GNU Emacs"
   :urgency tmr-notification-urgency
   :sound-file tmr-sound-file))

(defun tmr--notify-send (start &optional description)
  "Send system notification for timer with START time.
Optionally include DESCRIPTION."
-- 
2.36.0

[PATCH 2/3] Rename tmr--notify-send to tmr--notify Export this patch

tmr--notify itself will not send, but delegate sending to another
function. So the "send" verb should be freed.

Signed-off-by: Christian Tietze <me@christiantietze.de>
---
 tmr.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tmr.el b/tmr.el
index 010d12b..475665d 100644
--- a/tmr.el
+++ b/tmr.el
@@ -169,8 +169,8 @@ Read: (info \"(elisp) Desktop Notifications\") for details."
   :urgency tmr-notification-urgency
   :sound-file tmr-sound-file))

(defun tmr--notify-send (start &optional description)
  "Send system notification for timer with START time.
(defun tmr--notify (start &optional description)
Optionally include DESCRIPTION."
  (let ((end (format-time-string "%T"))
        (desc-plain "")
@@ -281,7 +281,7 @@ To cancel the timer, use the `tmr-cancel' command."
           object-desc
           (run-with-timer
            unit nil
            'tmr--notify-send start description))
            'tmr--notify start description))
          tmr--timers)
    (tmr--log-in-buffer object-desc)))

-- 
2.36.0

[PATCH 3/3] Extract tmr--notify-send-notification Export this patch

Signed-off-by: Christian Tietze <me@christiantietze.de>
---
 tmr.el | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/tmr.el b/tmr.el
index 475665d..cd2b8dd 100644
--- a/tmr.el
+++ b/tmr.el
@@ -169,8 +169,12 @@ Read: (info \"(elisp) Desktop Notifications\") for details."
   :urgency tmr-notification-urgency
   :sound-file tmr-sound-file))

  "Send system notification for timer with START time.
(defun tmr--notify-send-notification (title message)
  "Send notification with TITLE and MESSAGE using `tmr-notify-function'."
  (funcall tmr-notify-function title message))

(defun tmr--notify (start &optional description)
  "Send notification for timer with START time.
Optionally include DESCRIPTION."
  (let ((end (format-time-string "%T"))
        (desc-plain "")
@@ -178,14 +182,10 @@ Optionally include DESCRIPTION."
    (when description
      (setq desc-plain (concat "\n" description)
            desc-propertized (concat " [" (propertize description 'face 'bold) "]")))
    ;; Read: (info "(elisp) Desktop Notifications")
    (notifications-notify
     :title "TMR Must Recur"
     :body (format "Time is up!\nStarted: %s\nEnded: %s%s"
                   start end desc-plain)
     :app-name "GNU Emacs"
     :urgency tmr-notification-urgency
     :sound-file tmr-sound-file)
    (tmr--notify-send-notification
     "TMR Must Recur"
     (format "Time is up!\nStarted: %s\nEnded: %s%s"
             start end desc-plain))
    (message
     "TMR %s %s ; %s %s%s"
     (propertize "Start:" 'face 'success) start
-- 
2.36.0
Hey!

Ok, the patch sending now appears kind of rude since there's no initial
email and the original subject doesn't make sense. Sorry, git send-email
noob here! :)

Probably should've sent an email first with the intention, then used
send-email as replies to that? Hm.

So what's the idea:

`tmr' 0.2 uses D-Bus, which doesn't really work on macOS at all.

1) I extracted the D-BUS notification function call into
   `tmr-notifications-notify'. This way, it could be replaced if the
   reference was configurable. So:

2) I reference `tmr-notifications-notify` from the new custom variable
   `tmr-notify-function'. Now it's configurable.

3) The actual sending of a notification and usage of the function
   reference is implemented in the private function
   `tmr--notify-send-notification'. That accepts the title and message
   of the notification.

For `appt', I had this function already, and could reuse it:

(defun ct/send-notification (title msg)
  (let ((notifier-path (executable-find "alerter")))
       (start-process
           "Appointment Alert"
           "*Appointment Alert*" ;; nil to not capture output
           notifier-path
           "-message" msg
           "-title" title
           "-sender" "org.gnu.Emacs"
           "-activate" "org.gnu.Emacs")))
(setq tmr-notify-function #'ct/send-notification)

And yes, that does display a native macOS notification (using a 3rd
party tool, though).


Considerations:

- "TMR Must Recur" was a confusing default title. I kept it here.

- Function names and the custom variable name could be changed.


Cheers,
Christian