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(-) 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 lue='author'>author
path: root/apps/rpn.mu
blob: bd0d721f4556a5f7ec0fb82ad4a93741ef999b1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149