Add watch option

This commit is contained in:
Joe Lim committed 2024-03-30 19:29:15 +11:00
1 parent 1e10e95f4d
commit 7c3cfa8865
5 files changed
+45

No files matched your search

+31
View File
@@ -16,6 +16,7 @@ import (
"time"
"github.com/djherbis/times"
"github.com/fsnotify/fsnotify"
)
type linkState byte
@@ -466,6 +467,8 @@ type nav struct {
previewLoading bool
jumpList []string
jumpListInd int
watcher *fsnotify.Watcher
watcherEvents <-chan fsnotify.Event
}
func (nav *nav) loadDirInternal(path string) *dir {
@@ -2065,3 +2068,31 @@ func (nav *nav) calcDirSize() error {
return nil
}
func (nav *nav) startWatcher() {
if nav.watcher != nil {
return
}
log.Printf("start watch")
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Printf("start watcher: %s", err)
return
}
nav.watcher = watcher
nav.watcherEvents = watcher.Events
}
func (nav *nav) stopWatcher() {
if nav.watcher == nil {
return
}
log.Printf("stop watch")
nav.watcher.Close()
nav.watcher = nil
nav.watcherEvents = nil
}