diff options
author | Reto Brunner <reto@labrat.space> | 2020-02-15 14:14:47 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-02-16 10:41:19 -0500 |
commit | 78dd043057af9ccf82d1d7ea1f316f2d55b769c2 (patch) | |
tree | d745dd8e30d399a7fed1757d35cec4dfed0ea140 /worker | |
parent | 8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3 (diff) | |
download | aerc-78dd043057af9ccf82d1d7ea1f316f2d55b769c2.tar.gz |
notmuch: refresh dirlist in background
Diffstat (limited to 'worker')
-rw-r--r-- | worker/notmuch/eventhandlers.go | 15 | ||||
-rw-r--r-- | worker/notmuch/events.go | 4 | ||||
-rw-r--r-- | worker/notmuch/worker.go | 9 |
3 files changed, 27 insertions, 1 deletions
diff --git a/worker/notmuch/eventhandlers.go b/worker/notmuch/eventhandlers.go index 39027b6..e279dbc 100644 --- a/worker/notmuch/eventhandlers.go +++ b/worker/notmuch/eventhandlers.go @@ -2,8 +2,21 @@ package notmuch func (w *worker) handleNotmuchEvent(et eventType) error { switch ev := et.(type) { + case *updateDirCounts: + return w.handleUpdateDirCounts(ev) default: - _ = ev return errUnsupported } } + +func (w *worker) handleUpdateDirCounts(ev eventType) error { + for name, query := range w.nameQueryMap { + info, err := w.gatherDirectoryInfo(name, query) + if err != nil { + w.w.Logger.Printf("could not gather DirectoryInfo: %v\n", err) + continue + } + w.w.PostMessage(info, nil) + } + return nil +} diff --git a/worker/notmuch/events.go b/worker/notmuch/events.go index df35b21..896befa 100644 --- a/worker/notmuch/events.go +++ b/worker/notmuch/events.go @@ -3,3 +3,7 @@ package notmuch type eventType interface{} type event struct{} + +type updateDirCounts struct { + event +} diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 7480124..dfcfa77 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "strings" + "time" "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib/uidstore" @@ -26,6 +27,8 @@ func init() { var errUnsupported = fmt.Errorf("unsupported command") +const backgroundRefreshDelay = 1 * time.Minute + type worker struct { w *types.Worker nmEvents chan eventType @@ -168,6 +171,12 @@ func (w *worker) handleConnect(msg *types.Connect) error { } w.done(msg) w.emitLabelList() + go func() { + for { + w.nmEvents <- &updateDirCounts{} + time.Sleep(backgroundRefreshDelay) + } + }() return nil } |