skeeto/elfeed

How to create notifications after updates?

mhcerri opened this issue · 2 comments

Hi! First of all, thanks for the awesome package!

I'm trying to implement desktop notifications after the feeds are updated showing the number of new entries. However I couldn't find a good way to implement that. An advice around elfeed-update doesn't work since the update is done asynchronously. So far I'm using the elfeed-update-init-hooks and elfeed-update-hooks hooks for that (please check below). But that's more like an workaround because I need a keep a global count and because elfeed-update-hooks runs for every feed.

Do you see a better way for doing that? Thank you very much!

  (setq ~elfeed-count 0)

  (defun ~elfeed-save-count ()
    "Save the number of entries before an update."
    (elfeed-db-ensure)
    (setq ~elfeed-count (elfeed-db-size)))
  (add-hook 'elfeed-update-init-hooks #'~elfeed-save-count)

  (defun ~elfeed-notify-new (url)
    "Show a notification after an update if there are new entries."
    (let* ((count (elfeed-db-size))
           (new (- count ~elfeed-count)))
      (when (> new 0)
        (alert (format "From %s" url)
               :title (format "Elfeed: %d new %s"
                              new (if (= new 1) "entry" "entries"))
	       :icon "internet-chat"))
      (setq ~elfeed-count count)))
  (add-hook 'elfeed-update-hooks #'~elfeed-notify-new)
sp1ff commented

Thanks, @sp1ff! That will be very helpful!