aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--worker/lib/watchers/darwin/darwin.go84
-rw-r--r--worker/maildir/worker.go4
-rw-r--r--worker/watcher_darwin.go6
5 files changed, 97 insertions, 0 deletions
diff --git a/go.mod b/go.mod
index 7c3be11e..e939eac4 100644
--- a/go.mod
+++ b/go.mod
@@ -17,6 +17,7 @@ require (
github.com/emersion/go-pgpmail v0.2.0
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac
github.com/emersion/go-smtp v0.15.0
+ github.com/fsnotify/fsevents v0.1.1
github.com/fsnotify/fsnotify v1.5.4
github.com/gatherstars-com/jwz v1.3.2-0.20221104050604-3da8c59aef0a
github.com/gdamore/tcell/v2 v2.5.4
diff --git a/go.sum b/go.sum
index 33881405..428477b0 100644
--- a/go.sum
+++ b/go.sum
@@ -95,6 +95,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=
+github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
diff --git a/worker/lib/watchers/darwin/darwin.go b/worker/lib/watchers/darwin/darwin.go
new file mode 100644
index 00000000..e20761f3
--- /dev/null
+++ b/worker/lib/watchers/darwin/darwin.go
@@ -0,0 +1,84 @@
+//go:build darwin
+// +build darwin
+
+package darwin
+
+import (
+ "time"
+
+ "git.sr.ht/~rjarry/aerc/log"
+ "git.sr.ht/~rjarry/aerc/worker/handlers"
+ "git.sr.ht/~rjarry/aerc/worker/types"
+ "github.com/fsnotify/fsevents"
+)
+
+func init() {
+ handlers.RegisterWatcherFactory("darwin", newDarwinWatcher)
+}
+
+type darwinWatcher struct {
+ ch chan *types.FSEvent
+ w *fsevents.EventStream
+ watcherCh chan []fsevents.Event
+}
+
+func newDarwinWatcher() (types.FSWatcher, error) {
+ watcher := &darwinWatcher{
+ watcherCh: make(chan []fsevents.Event),
+ ch: make(chan *types.FSEvent),
+ w: &fsevents.EventStream{
+ Flags: fsevents.FileEvents | fsevents.WatchRoot,
+ Latency: 500 * time.Millisecond,
+ },
+ }
+ return watcher, nil
+}
+
+func (w *darwinWatcher) watch() {
+ defer log.PanicHandler()
+ for events := range w.w.Events {
+ for _, ev := range events {
+ switch {
+ case ev.Flags&fsevents.ItemCreated > 0:
+ w.ch <- &types.FSEvent{
+ Operation: types.FSCreate,
+ Path: ev.Path,
+ }
+ case ev.Flags&fsevents.ItemRenamed > 0:
+ w.ch <- &types.FSEvent{
+ Operation: types.FSRename,
+ Path: ev.Path,
+ }
+ case ev.Flags&fsevents.ItemRemoved > 0:
+ w.ch <- &types.FSEvent{
+ Operation: types.FSRemove,
+ Path: ev.Path,
+ }
+ }
+ }
+ }
+}
+
+func (w *darwinWatcher) Configure(root string) error {
+ dev, err := fsevents.DeviceForPath(root)
+ if err != nil {
+ return err
+ }
+ w.w.Device = dev
+ w.w.Paths = []string{root}
+ w.w.Start()
+ go w.watch()
+ return nil
+}
+
+func (w *darwinWatcher) Events() chan *types.FSEvent {
+ return w.ch
+}
+
+func (w *darwinWatcher) Add(p string) error {
+ return nil
+}
+
+func (w *darwinWatcher) Remove(p string) error {
+ return nil
+}
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index 11bab4ea..a94792bc 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -313,6 +313,10 @@ func (w *Worker) handleConfigure(msg *types.Configure) error {
return err
}
w.c = c
+ err = w.watcher.Configure(dir)
+ if err != nil {
+ return err
+ }
log.Debugf("configured base maildir: %s", dir)
return nil
}
diff --git a/worker/watcher_darwin.go b/worker/watcher_darwin.go
new file mode 100644
index 00000000..fa1af712
--- /dev/null
+++ b/worker/watcher_darwin.go
@@ -0,0 +1,6 @@
+//go:build darwin
+// +build darwin
+
+package worker
+
+import _ "git.sr.ht/~rjarry/aerc/worker/lib/watchers/darwin"