diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2023-03-02 16:46:00 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-07 16:37:02 +0100 |
commit | a0935a3de0cec483a605df5017307f50a186f5cb (patch) | |
tree | 4caff49e5f44a9e9943fa402b2f89d8f242196b4 /worker/handlers/register.go | |
parent | 182424d279532635cbae6b1a1817f61db64ee37f (diff) | |
download | aerc-a0935a3de0cec483a605df5017307f50a186f5cb.tar.gz |
worker/lib: implement an fswatcher interface
Implement an FSWatcher interface. The interface is used to abstract away
file system watchers, which have implementation specific backends. The
initial interface has one implementation: inotify for linux. Subsequent
commits will add a macOS watcher.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Ben Lee-Cohen <ben@lee-cohen.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/handlers/register.go')
-rw-r--r-- | worker/handlers/register.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/worker/handlers/register.go b/worker/handlers/register.go index c871f07b..c94a256e 100644 --- a/worker/handlers/register.go +++ b/worker/handlers/register.go @@ -2,6 +2,7 @@ package handlers import ( "fmt" + "runtime" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -25,3 +26,18 @@ func GetHandlerForScheme(scheme string, worker *types.Worker) (types.Backend, er } return backend, nil } + +type WatcherFactoryFunc func() (types.FSWatcher, error) + +var watcherFactories map[string]WatcherFactoryFunc = make(map[string]WatcherFactoryFunc) + +func RegisterWatcherFactory(os string, fn WatcherFactoryFunc) { + watcherFactories[os] = fn +} + +func NewWatcher() (types.FSWatcher, error) { + if fn, ok := watcherFactories[runtime.GOOS]; ok { + return fn() + } + return nil, fmt.Errorf("Unsupported OS: %s", runtime.GOOS) +} |