Skip to content

Commit

Permalink
fix(daemon): avoid process before file saves done.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljcbaby committed Jan 1, 2025
1 parent 8236f3d commit 7299ff9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion _example/clash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ proxy-groups:
url: http://www.gstatic.com/generate_204
interval: 300
timeout: 2000
max-failed-times: 5
lazy: true
- name: main
type: select
Expand Down
28 changes: 17 additions & 11 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,7 @@ func watch(watcher *fsnotify.Watcher) {
lastEvent[f.Name] = now
sLock.Unlock()

log.L().Sugar().Infof("File %s modified", f.Name)
err := convert.Convert(convert.Task{
Source: conf.Convert.Source,
Target: conf.Convert.Target,
File: f,
})
if err != nil {
log.L().Sugar().Errorf("Convert %s error: %v", f.Name, err)
}

refreshChan <- struct{}{}
go updateFile(f)
}
}
}
Expand All @@ -85,3 +75,19 @@ func watch(watcher *fsnotify.Watcher) {
}
}
}

func updateFile(f conf.File) {
time.Sleep(time.Second)

log.L().Sugar().Infof("File %s modified", f.Name)
err := convert.Convert(convert.Task{
Source: conf.Convert.Source,
Target: conf.Convert.Target,
File: f,
})
if err != nil {
log.L().Sugar().Errorf("Convert %s error: %v", f.Name, err)
}

refreshChan <- struct{}{}
}

0 comments on commit 7299ff9

Please sign in to comment.