iqbalansari / mu4e-alert

Desktop notifications and modeline display for mu4e
GNU General Public License v3.0
155 stars 22 forks source link

Help to get desktop notifications every X minutes #42

Open fabriziojpiva opened 3 years ago

fabriziojpiva commented 3 years ago

Hi everyone. I have installed mu4e-alert correctly and set up the configuration in my .emacs as follow:

;; mu4e alert for notifications
(require 'mu4e-alert)

(setq mu4e-alert-interesting-mail-query
      (concat
       "flag:unread AND maildir:/google/INBOX "
       "OR "
       "flag:unread AND maildir:/outlook/Inbox "
       "OR "
       "flag:unread AND maildir:/work/INBOX"
       ))

(mu4e-alert-set-default-style 'libnotify)
(add-hook 'after-init-hook #'mu4e-alert-enable-notifications)
(add-hook 'after-init-hook #'mu4e-alert-enable-mode-line-display)

(defun refresh-mu4e-alerts ()
  (interactive)
  (mu4e~proc-kill)
  (mu4e-alert-enable-mode-line-display)
  )

(run-with-timer 0 60 'refresh-mu4e-alerts)

However, the desktop notifications only work when I open Emacs, in that exact moment I get the notifications of the unread emails correctly. But after that, when Emacs is already open for a couple of minutes and I receive a new email, I only get the line-display icon updated but without any desktop notification. Is it possible to configure the desktop notifications to also work when Emacs is already running?

archer-65 commented 2 years ago

Hi everyone. I have installed mu4e-alert correctly and set up the configuration in my .emacs as follow:

;; mu4e alert for notifications
(require 'mu4e-alert)

(setq mu4e-alert-interesting-mail-query
      (concat
       "flag:unread AND maildir:/google/INBOX "
       "OR "
       "flag:unread AND maildir:/outlook/Inbox "
       "OR "
       "flag:unread AND maildir:/work/INBOX"
       ))

(mu4e-alert-set-default-style 'libnotify)
(add-hook 'after-init-hook #'mu4e-alert-enable-notifications)
(add-hook 'after-init-hook #'mu4e-alert-enable-mode-line-display)

(defun refresh-mu4e-alerts ()
  (interactive)
  (mu4e~proc-kill)
  (mu4e-alert-enable-mode-line-display)
  )

(run-with-timer 0 60 'refresh-mu4e-alerts)

However, the desktop notifications only work when I open Emacs, in that exact moment I get the notifications of the unread emails correctly. But after that, when Emacs is already open for a couple of minutes and I receive a new email, I only get the line-display icon updated but without any desktop notification. Is it possible to configure the desktop notifications to also work when Emacs is already running?

Same problem. I can't live without notifications.

PiotrBosak commented 1 year ago

Hi, I had the same problem and I've come up with a hack to solve it.

(require 'mu4e-alert)
(add-hook 'mu4e-index-updated-hook (lambda ()
(mu4e-alert--get-mu-unread-mails (lambda (mails)
                                         (mu4e-alert-notify-unread-messages-count (length (mu4e-alert-filter-repeated-mails mails)))))))

I added that hook and it shows a notification whenever you index your mail(which mu4e does on its own when it synchronizes, to modify how often mu4e synchronizes, use (setq mu4e-update-interval <seconds>)

You can look at the mu4e-alert source to come up with something better, this will only print how many mails you got.