Config impl now diffs files and broadcasts events
This commit is contained in:
parent
1f5cb683fb
commit
a952490188
@ -6,6 +6,7 @@ import "sync"
|
|||||||
import "slices"
|
import "slices"
|
||||||
import "path/filepath"
|
import "path/filepath"
|
||||||
import "github.com/fsnotify/fsnotify"
|
import "github.com/fsnotify/fsnotify"
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
|
|
||||||
// Goroutine model:
|
// Goroutine model:
|
||||||
@ -67,15 +68,19 @@ func (this *config) lockAndProcessEvent (event fsnotify.Event) {
|
|||||||
if _, ok := this.paths.watching[event.Name]; !ok { return }
|
if _, ok := this.paths.watching[event.Name]; !ok { return }
|
||||||
|
|
||||||
if event.Name == this.paths.user {
|
if event.Name == this.paths.user {
|
||||||
|
previousUser := this.data.user
|
||||||
this.reloadUser()
|
this.reloadUser()
|
||||||
|
newUser := this.data.user
|
||||||
|
this.processUserDiff(newUser.Diff(previousUser))
|
||||||
} else {
|
} else {
|
||||||
index := slices.Index(this.paths.system, event.Name)
|
index := slices.Index(this.paths.system, event.Name)
|
||||||
if index > 0 {
|
if index > 0 {
|
||||||
|
previousSystem := this.data.system[index]
|
||||||
this.reloadSystem(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 {
|
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) {
|
func (this *config) broadcastChange (key string) {
|
||||||
for _, listener := range this.on.change.Listeners() {
|
for _, listener := range this.on.change.Listeners() {
|
||||||
listener(key)
|
tomo.Do(func () { listener(key) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user