Skip to content

Commit e374998

Browse files
committed
fix: show mail count in awseome-tray
1 parent c7bd2d1 commit e374998

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

lisp/init-mu4e.el

+34-3
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,44 @@
3333
(when msg
3434
(or (mu4e-message-contact-field-matches msg :to addr-lex)
3535
(mu4e-message-contact-field-matches msg :cc addr-lex)))))))
36+
37+
;; Most of the time, I merely want mu4e to re-index my local maildir (because
38+
;; I'm running mbsync as a cron job). However, sometimes I want to fetch mails
39+
;; immediately. Do this by changing the meaning of a prefix for
40+
;; mu4e-update-mail-and-index (bound to "U").
41+
;;
42+
;; A prefix usually means run in the background, but I don't think I ever want
43+
;; that. Change things so a prefix means to call mbsync.
44+
(defun rjs/mu4e-update-mail-and-index (orig-fun prefix &rest args)
45+
(interactive "P")
46+
(if prefix (funcall orig-fun nil) (mu4e-update-index)))
47+
48+
(setq my/mu4e-unread-messages-count "Mail: -")
49+
50+
(defcustom my/inbox-count-command "echo -n ( mu find date:1w..now maildir:/INBOX flag:unread 2>/dev/null | wc -l )"
51+
"Command to retrieve count of emails in Inbox."
52+
:type 'string
53+
:group 'inbox)
54+
55+
;; I want to show unread messages count in awesome-tray, so add an advice
56+
;; function to set get it and set it to a global variable.
57+
(defun my/count-mu4e-set-unread-messages ()
58+
(let ((unread (shell-command-to-string my/inbox-count-command)))
59+
(setq my/mu4e-unread-messages-count (format "Mail: %s" (string-trim unread)))))
60+
3661
(use-package mu4e
3762
:straight (:type built-in)
3863
:bind
3964
("C-c c" . mu4e-org-store-and-capture) ;; org-agenda
4065
("C-c c" . mu4e-org-store-and-capture) ;; org-agenda
4166
:commands mu4e
67+
:hook
68+
(mu4e-index-updated . my/count-mu4e-set-unread-messages)
4269
:custom
4370
;; http://pragmaticemacs.com/emacs/fixing-duplicate-uid-errors-when-using-mbsync-and-mu4e/
4471
(mu4e-change-filenames-when-moving t)
45-
;; Update mails every 2 minutes.
46-
(mu4e-update-interval 120)
72+
;; Update mails every 10 minutes.
73+
(mu4e-update-interval 600)
4774
;; Don't save message to Sent Messages, Gmail/IMAP takes care of this
4875
;; Override in context switching for other type of mailboxes
4976
(mu4e-sent-messages-behavior 'delete)
@@ -53,6 +80,10 @@
5380
`( ,(my-make-mu4e-context "main" "[email protected]" nil)))
5481
(message-send-mail-function 'smtpmail-send-it)
5582
(smtpmail-stream-type 'starttls)
83+
84+
(advice-add 'mu4e-update-mail-and-index
85+
:around #'rjs/mu4e-update-mail-and-index)
86+
5687
(starttls-use-gnutls t)
5788
;; Personal info
5889
(user-full-name "Gray King")
@@ -103,7 +134,7 @@
103134
:straight t
104135
:after mu4e
105136
:hook
106-
(after-init mu4e-alert-enable-notifications)
137+
(after-init . mu4e-alert-enable-notifications)
107138
:config
108139
(mu4e-alert-set-default-style 'notifier))))
109140

lisp/init-theme-modus.el

+18-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@
6565
"Buffer-state module face."
6666
:group 'awesome-tray)
6767

68+
69+
(defun my/module-inbox-count-info()
70+
"Show inbox count."
71+
(if (stringp my/mu4e-unread-messages-count)
72+
my/mu4e-unread-messages-count
73+
"Mail: N/A"))
74+
75+
(defface my/module-inbox-count-face
76+
'((((background light))
77+
:foreground "#00796b" :bold t)
78+
(t
79+
:foreground "#8eb89d" :bold t))
80+
"Buffer-state module face."
81+
:group 'awesome-tray)
82+
6883
(use-package awesome-tray
6984
:straight (awesome-tray :host github :repo "manateelazycat/awesome-tray")
7085
:config
@@ -77,7 +92,7 @@
7792
:height 150
7893
:box (face-attribute 'mode-line :box))
7994
;; colors are copied from https://github.com/mclear-tools/bespoke-themes
80-
(setq awesome-tray-active-modules '("location" "buffer-state" "buffer-name" "git" "belong" "mode-name")
95+
(setq awesome-tray-active-modules '("inbox-count" "location" "buffer-state" "buffer-name" "git" "belong" "mode-name")
8196
awesome-tray-info-padding-right 1
8297
awesome-tray-mode-line-active-color "#eceff1"
8398
awesome-tray-mode-line-inactive-color "#282b35"
@@ -92,6 +107,8 @@
92107
:foreground "#8eb89d")
93108
(add-to-list 'awesome-tray-module-alist
94109
'("buffer-state" . (my/module-buffer-state-info my/module-buffer-state-face)))
110+
(add-to-list 'awesome-tray-module-alist
111+
'("inbox-count" . (my/module-inbox-count-info my/module-inbox-count-face)))
95112
(awesome-tray-mode 1))
96113

97114
(provide 'init-theme-modus)

0 commit comments

Comments
 (0)