diff --git a/server/common/config.go b/server/common/config.go index 3762b2b0..6a814b42 100644 --- a/server/common/config.go +++ b/server/common/config.go @@ -20,7 +20,7 @@ var ( ) type Configuration struct { - OnChange chan interface{} + onChange []ChangeListener mu sync.Mutex currentElement *FormElement cache KeyValueStore @@ -60,9 +60,9 @@ func init() { func NewConfiguration() Configuration { return Configuration{ - OnChange: make(chan interface{}), - mu: sync.Mutex{}, - cache: NewKeyValueStore(), + onChange: make([]ChangeListener, 0), + mu: sync.Mutex{}, + cache: NewKeyValueStore(), form: []Form{ Form{ Title: "general", @@ -240,7 +240,12 @@ func (this *Configuration) Load() { this.cache.Clear() Log.SetVisibility(this.Get("log.level").String()) - go func() { this.OnChange <- nil }() + + go func() { // Trigger all the event listeners + for i:=0; i= 0 { + close(this.onChange[i].Listener) + this.onChange[i] = this.onChange[len(this.onChange)-1] + this.onChange = this.onChange[:len(this.onChange)-1] + } + break + } + } + this.mu.Unlock() +} + +type ChangeListener struct { + Id string + Listener chan interface{} +} diff --git a/server/model/search.go b/server/model/search.go index 2a2ca93a..d05077bf 100644 --- a/server/model/search.go +++ b/server/model/search.go @@ -148,15 +148,17 @@ func init(){ } INDEXING_EXT() - + onChange := Config.ListenForChange() runner := func() { + startSearch := false for { if SEARCH_ENABLE() == false { select { - case <- Config.OnChange: + case <- onChange.Listener: startSearch = SEARCH_ENABLE() + } + if startSearch == false { continue } - continue } sidx := SProc.Peek() if sidx == nil { diff --git a/server/plugin/index.go b/server/plugin/index.go index 23e3cd90..66975db7 100644 --- a/server/plugin/index.go +++ b/server/plugin/index.go @@ -2,6 +2,7 @@ package plugin import ( _ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_tunnel" + _ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_tor" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_light" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_backblaze" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dav" diff --git a/server/plugin/plg_starter_tor/index.go b/server/plugin/plg_starter_tor/index.go index 2aab417f..7f22150c 100644 --- a/server/plugin/plg_starter_tor/index.go +++ b/server/plugin/plg_starter_tor/index.go @@ -47,17 +47,16 @@ func init() { Hooks.Register.Starter(func (r *mux.Router) { if enable_tor() == false { startTor := false + onChange := Config.ListenForChange() for { select { - case <- Config.OnChange: - if enable_tor() == true { - startTor = true - break - } + case <- onChange.Listener: startTor = enable_tor() } if startTor == true { break } } + Config.UnlistenForChange(onChange) } + Log.Info("[tor] starting ...") t, err := tor.Start(nil, &tor.StartConf{ DataDir: TOR_PATH, diff --git a/server/plugin/plg_starter_tunnel/index.go b/server/plugin/plg_starter_tunnel/index.go index 53ba81ae..9c7731b1 100644 --- a/server/plugin/plg_starter_tunnel/index.go +++ b/server/plugin/plg_starter_tunnel/index.go @@ -65,19 +65,17 @@ func init() { return } }() - Config.Get("features.server.tunnel_url").Set(nil) + Config.Get("features.server.tunnel_url").Set(nil) if tunnel_enable() == false { startTunnel := false + onChange := Config.ListenForChange() for { select { - case <- Config.OnChange: - if tunnel_enable() == true { - startTunnel = true - break - } + case <- onChange.Listener: startTunnel = tunnel_enable() } - if startTunnel == true { break } + if startTunnel == true { break } } + Config.UnlistenForChange(onChange) } Log.Info("[tunnel] starting ...")