How to create notifications after updates?
mhcerri opened this issue · 2 comments
mhcerri commented
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
Hi Marcello, not sure if this is what you're looking to do, but I
detect when the update has completed by checking
`(elfeed-queue-count-total)` in my update-hook. Something like:
(defun s1pff/elfeed/update-hook (_url)
(when (eq (elfeed-queue-count-total) 0)
(do-the-update-thing)))
hth,
Marcelo Cerri ***@***.***> writes:
… 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)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this
thread.