notmuch: refresh dirlist in background
This commit is contained in:
parent
8d216ab10e
commit
78dd043057
|
@ -2,8 +2,21 @@ package notmuch
|
||||||
|
|
||||||
func (w *worker) handleNotmuchEvent(et eventType) error {
|
func (w *worker) handleNotmuchEvent(et eventType) error {
|
||||||
switch ev := et.(type) {
|
switch ev := et.(type) {
|
||||||
|
case *updateDirCounts:
|
||||||
|
return w.handleUpdateDirCounts(ev)
|
||||||
default:
|
default:
|
||||||
_ = ev
|
|
||||||
return errUnsupported
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -3,3 +3,7 @@ package notmuch
|
||||||
type eventType interface{}
|
type eventType interface{}
|
||||||
|
|
||||||
type event struct{}
|
type event struct{}
|
||||||
|
|
||||||
|
type updateDirCounts struct {
|
||||||
|
event
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc/config"
|
"git.sr.ht/~sircmpwn/aerc/config"
|
||||||
"git.sr.ht/~sircmpwn/aerc/lib/uidstore"
|
"git.sr.ht/~sircmpwn/aerc/lib/uidstore"
|
||||||
|
@ -26,6 +27,8 @@ func init() {
|
||||||
|
|
||||||
var errUnsupported = fmt.Errorf("unsupported command")
|
var errUnsupported = fmt.Errorf("unsupported command")
|
||||||
|
|
||||||
|
const backgroundRefreshDelay = 1 * time.Minute
|
||||||
|
|
||||||
type worker struct {
|
type worker struct {
|
||||||
w *types.Worker
|
w *types.Worker
|
||||||
nmEvents chan eventType
|
nmEvents chan eventType
|
||||||
|
@ -168,6 +171,12 @@ func (w *worker) handleConnect(msg *types.Connect) error {
|
||||||
}
|
}
|
||||||
w.done(msg)
|
w.done(msg)
|
||||||
w.emitLabelList()
|
w.emitLabelList()
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
w.nmEvents <- &updateDirCounts{}
|
||||||
|
time.Sleep(backgroundRefreshDelay)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue