init: pristine aerc 0.20.0 source

This commit is contained in:
Mortdecai
2026-04-07 19:54:54 -04:00
commit 083402a548
502 changed files with 68722 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
//go:build darwin
// +build darwin
package watchers
import (
"time"
"git.sr.ht/~rjarry/aerc/lib/log"
"github.com/fsnotify/fsevents"
)
func init() {
RegisterWatcherFactory(newDarwinWatcher)
}
type darwinWatcher struct {
ch chan *FSEvent
w *fsevents.EventStream
watcherCh chan []fsevents.Event
}
func newDarwinWatcher() (FSWatcher, error) {
watcher := &darwinWatcher{
watcherCh: make(chan []fsevents.Event),
ch: make(chan *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 <- &FSEvent{
Operation: FSCreate,
Path: ev.Path,
}
case ev.Flags&fsevents.ItemRenamed > 0:
w.ch <- &FSEvent{
Operation: FSRename,
Path: ev.Path,
}
case ev.Flags&fsevents.ItemRemoved > 0:
w.ch <- &FSEvent{
Operation: 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 *FSEvent {
return w.ch
}
func (w *darwinWatcher) Add(p string) error {
return nil
}
func (w *darwinWatcher) Remove(p string) error {
return nil
}
+74
View File
@@ -0,0 +1,74 @@
//go:build !darwin
// +build !darwin
package watchers
import (
"git.sr.ht/~rjarry/aerc/lib/log"
"github.com/fsnotify/fsnotify"
)
func init() {
RegisterWatcherFactory(newInotifyWatcher)
}
type inotifyWatcher struct {
w *fsnotify.Watcher
ch chan *FSEvent
}
func newInotifyWatcher() (FSWatcher, error) {
watcher := &inotifyWatcher{
ch: make(chan *FSEvent),
}
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
watcher.w = w
go watcher.watch()
return watcher, nil
}
func (w *inotifyWatcher) watch() {
defer log.PanicHandler()
for ev := range w.w.Events {
// we only care about files being created, removed or renamed
switch ev.Op {
case fsnotify.Create:
w.ch <- &FSEvent{
Operation: FSCreate,
Path: ev.Name,
}
case fsnotify.Remove:
w.ch <- &FSEvent{
Operation: FSRemove,
Path: ev.Name,
}
case fsnotify.Rename:
w.ch <- &FSEvent{
Operation: FSRename,
Path: ev.Name,
}
default:
continue
}
}
}
func (w *inotifyWatcher) Configure(root string) error {
return w.w.Add(root)
}
func (w *inotifyWatcher) Events() chan *FSEvent {
return w.ch
}
func (w *inotifyWatcher) Add(p string) error {
return w.w.Add(p)
}
func (w *inotifyWatcher) Remove(p string) error {
return w.w.Remove(p)
}
+44
View File
@@ -0,0 +1,44 @@
package watchers
import (
"fmt"
"runtime"
)
// FSWatcher is a file system watcher
type FSWatcher interface {
Configure(string) error
Events() chan *FSEvent
// Adds a directory or file to the watcher
Add(string) error
// Removes a directory or file from the watcher
Remove(string) error
}
type FSOperation int
const (
FSCreate FSOperation = iota
FSRemove
FSRename
)
type FSEvent struct {
Operation FSOperation
Path string
}
type WatcherFactoryFunc func() (FSWatcher, error)
var watcherFactory WatcherFactoryFunc
func RegisterWatcherFactory(fn WatcherFactoryFunc) {
watcherFactory = fn
}
func NewWatcher() (FSWatcher, error) {
if watcherFactory == nil {
return nil, fmt.Errorf("Unsupported OS: %s", runtime.GOOS)
}
return watcherFactory()
}