diff --git a/config/impl.go b/config/impl.go index 1d28de8..914fffb 100644 --- a/config/impl.go +++ b/config/impl.go @@ -6,6 +6,7 @@ import "sync" import "slices" import "path/filepath" import "github.com/fsnotify/fsnotify" +import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo/event" // Goroutine model: @@ -67,15 +68,19 @@ func (this *config) lockAndProcessEvent (event fsnotify.Event) { if _, ok := this.paths.watching[event.Name]; !ok { return } if event.Name == this.paths.user { + previousUser := this.data.user this.reloadUser() + newUser := this.data.user + this.processUserDiff(newUser.Diff(previousUser)) } else { index := slices.Index(this.paths.system, event.Name) if index > 0 { + previousSystem := this.data.system[index] this.reloadSystem(index) + newSystem := this.data.system[index] + this.processSystemDiff(index, diffValueMaps(newSystem, previousSystem)) } } - - // TODO diff and call event handler if changed } func (this *config) init () error { @@ -178,7 +183,7 @@ func (this *config) processSystemDiff (index int, changed map[string] struct { } func (this *config) broadcastChange (key string) { for _, listener := range this.on.change.Listeners() { - listener(key) + tomo.Do(func () { listener(key) }) } }