diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-21 11:35:42 -0200 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-22 10:46:42 -0200 |
commit | b854489549490a53713f0777ac4c22096920e19f (patch) | |
tree | 70a82baef9071afbf3484da8d69ed67d5078b1f7 /sx-notify.el | |
parent | 0a3a9540b3033e9e93927c92fb6df39a3785563d (diff) |
Timer logic
Diffstat (limited to 'sx-notify.el')
-rw-r--r-- | sx-notify.el | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/sx-notify.el b/sx-notify.el index bc88ceb..05babad 100644 --- a/sx-notify.el +++ b/sx-notify.el @@ -27,20 +27,28 @@ ;;; mode-line notification -(defvar sx-notify--unread-inbox nil +(defvar sx-notify--unread-inbox nil "List of inbox items still unread.") -(defvar sx-notify--unread-notifications nil +(defvar sx-notify--unread-notifications nil "List of notifications items still unread.") +(defvar sx-notify--read-inbox nil + "List of inbox items which are read. +These are identified by their links.") + +(defvar sx-notify--read-notifications nil + "List of notification items which are read. +These are identified by their links.") + (defvar sx-notify--mode-line - '((sx-notify--unread-inbox (sx-notify--unread-notifications "[")) + '((sx-notify--unread-inbox (sx-notify--unread-notifications " [")) (sx-notify--unread-inbox (:propertize (:eval (format "i:%s" (length sx-notify--unread-inbox))) face mode-line-buffer-id mouse-face mode-line-highlight)) - (sx-notify--unread-inbox (sx-notify--unread-notifications ",")) + (sx-notify--unread-inbox (sx-notify--unread-notifications " ")) (sx-notify--unread-notifications (:propertize (:eval (format "n:%s" (length sx-notify--unread-notifications))) @@ -51,12 +59,38 @@ ;;; minor-mode definition -(define-minor-mode sx-notify-mode nil nil "sx" nil +(defcustom sx-notify-timer-delay (* 60 5) + "Idle time, in seconds, before querying for inbox items." + :type 'integer + :group 'sx-notify) + +(defvar sx-notify--timer nil + "Timer used for fetching notifications.") + +(define-minor-mode sx-notify-mode nil nil nil nil + :global t (if sx-notify-mode - (add-to-list 'global-mode-string '(t sx-notify--mode-line) 'append) + (progn + (add-to-list 'global-mode-string '(t sx-notify--mode-line) 'append) + (setq sx-notify--timer + (run-with-idle-timer sx-notify-timer-delay 'repeat + #'sx-notify--update-unread))) + (when (timerp sx-notify--timer) + (cancel-timer sx-notify--timer) + (setq sx-notify--timer nil)) (setq global-mode-string (delete '(t sx-notify--mode-line) global-mode-string)))) +(defun sx-notify--update-unread () + "Update the lists of unread notifications." + (setq sx-notify--unread-inbox + (cl-remove-if + (lambda (x) (member (cdr (assq 'link x)) sx-notify--read-inbox)) + (append (sx-inbox-get) nil))) + (setq sx-notify--unread-notifications + (cl-remove-if + (lambda (x) (member (cdr (assq 'link x)) sx-notify--read-notifications)) + (append (sx-inbox-get t) nil)))) (provide 'sx-notify) ;;; sx-notify.el ends here |