Don't start github timer if doom-modeline-github is nil.

Also watch the change of doom-modeline-github to run or cancel the timer.
This only support 26 and above. Need to restart Emacs to effect in 25.
See https://github.com/seagle0128/doom-modeline/issues/66#issuecomment-451397481.
This commit is contained in:
Vincent Zhang 2019-01-04 22:29:07 +08:00
parent 47bed3c0a4
commit 5adedd5953

View file

@ -1859,9 +1859,26 @@ mouse-3: Describe current input method")
(setq doom-modeline--github-notifications-number
(length result))))))
(run-with-timer 30
doom-modeline-github-interval
#'doom-modeline--github-fetch-notifications)
(defvar doom-modeline--github-timer nil)
(defun doom-modeline-github-timer ()
"Start/Stop the timer for github fetching."
(if (timerp doom-modeline--github-timer)
(cancel-timer doom-modeline--github-timer))
(setq doom-modeline--github-timer
(and doom-modeline-github
(run-with-timer 30
doom-modeline-github-interval
#'doom-modeline--github-fetch-notifications))))
(when (>= emacs-major-version 26)
(add-variable-watcher
'doom-modeline-github
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-github val)
(doom-modeline-github-timer)))))
(doom-modeline-github-timer)
(defun doom-modeline--github-open-notifications ()
"Open GitHub Notifications page."