Fix #82: load async if it exists but is not loaded.

This commit is contained in:
Vincent Zhang 2019-01-02 18:27:13 +08:00
parent 26defa1f13
commit 7439d7b927

View file

@ -1573,21 +1573,24 @@ mouse-3: Describe current input method")
(defvar doom-modeline--github-notifications-number 0) (defvar doom-modeline--github-notifications-number 0)
(defun doom-modeline--github-fetch-notifications () (defun doom-modeline--github-fetch-notifications ()
"Fetch github notifications." "Fetch github notifications."
(if (and doom-modeline-github (when (and doom-modeline-github
(fboundp 'async-start)) (fboundp 'async-start))
(async-start ;; load `async' if it's not loaded
`(lambda () (unless (fboundp 'async-inject-variables)
,(async-inject-variables "\\`load-path\\'") (require 'async nil t))
(require 'ghub nil t) (async-start
(when (fboundp 'ghub-get) `(lambda ()
(with-timeout (10) ,(async-inject-variables "\\`load-path\\'")
(ghub-get "/notifications" (require 'ghub nil t)
nil (when (fboundp 'ghub-get)
:query '((notifications . "true")) (with-timeout (10)
:noerror t)))) (ghub-get "/notifications"
(lambda (result) nil
(setq doom-modeline--github-notifications-number :query '((notifications . "true"))
(length result)))))) :noerror t))))
(lambda (result)
(setq doom-modeline--github-notifications-number
(length result))))))
(run-with-timer 30 (run-with-timer 30
doom-modeline-github-interval doom-modeline-github-interval