From 78dd043057af9ccf82d1d7ea1f316f2d55b769c2 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sat, 15 Feb 2020 14:14:47 +0100 Subject: notmuch: refresh dirlist in background --- worker/notmuch/eventhandlers.go | 15 ++++++++++++++- worker/notmuch/events.go | 4 ++++ worker/notmuch/worker.go | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'worker/notmuch') 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 } -- cgit 1.4.1-2-gfad0