Throttle write updates
This commit is contained in:
2 files changed
+14
-3
No files matched your search
@@ -477,14 +477,19 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) {
|
if ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) {
|
||||||
app.updateFile(ev.Name, true)
|
app.nav.watcherWrites[ev.Name] = true
|
||||||
|
}
|
||||||
|
case <-app.nav.watcherTicker.C:
|
||||||
|
for path := range app.nav.watcherWrites {
|
||||||
|
app.updateFile(path, true)
|
||||||
currFile, err := app.nav.currFile()
|
currFile, err := app.nav.currFile()
|
||||||
if err == nil && currFile.path == ev.Name {
|
if err == nil && currFile.path == path {
|
||||||
app.nav.startPreview()
|
app.nav.startPreview()
|
||||||
app.nav.previewChan <- ev.Name
|
app.nav.previewChan <- path
|
||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
|
app.nav.watcherWrites = make(map[string]bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -467,6 +467,8 @@ type nav struct {
|
|||||||
jumpListInd int
|
jumpListInd int
|
||||||
watcher *fsnotify.Watcher
|
watcher *fsnotify.Watcher
|
||||||
watcherEvents <-chan fsnotify.Event
|
watcherEvents <-chan fsnotify.Event
|
||||||
|
watcherWrites map[string]bool
|
||||||
|
watcherTicker *time.Ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDirInternal(path string) *dir {
|
func (nav *nav) loadDirInternal(path string) *dir {
|
||||||
@@ -604,6 +606,8 @@ func newNav(height int) *nav {
|
|||||||
previewTimer: time.NewTimer(0),
|
previewTimer: time.NewTimer(0),
|
||||||
jumpList: make([]string, 0),
|
jumpList: make([]string, 0),
|
||||||
jumpListInd: -1,
|
jumpListInd: -1,
|
||||||
|
watcherWrites: make(map[string]bool),
|
||||||
|
watcherTicker: new(time.Ticker),
|
||||||
}
|
}
|
||||||
|
|
||||||
return nav
|
return nav
|
||||||
@@ -2080,6 +2084,7 @@ func (nav *nav) startWatcher() {
|
|||||||
|
|
||||||
nav.watcher = watcher
|
nav.watcher = watcher
|
||||||
nav.watcherEvents = watcher.Events
|
nav.watcherEvents = watcher.Events
|
||||||
|
nav.watcherTicker = time.NewTicker(10 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) stopWatcher() {
|
func (nav *nav) stopWatcher() {
|
||||||
@@ -2091,6 +2096,7 @@ func (nav *nav) stopWatcher() {
|
|||||||
|
|
||||||
nav.watcher = nil
|
nav.watcher = nil
|
||||||
nav.watcherEvents = nil
|
nav.watcherEvents = nil
|
||||||
|
nav.watcherTicker.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) setWatches() {
|
func (nav *nav) setWatches() {
|
||||||
|
|||||||
Reference in new issue
Block a user