Add config watch to all tools so they are restarted if the config changes

This commit is contained in:
KemoNine 2020-09-06 03:36:35 -04:00
parent c2a21eabd9
commit 13d019cf62
3 changed files with 34 additions and 12 deletions

View file

@ -20,7 +20,18 @@ const (
func main() { func main() {
// Load the config file // Load the config file
pfConfig, _ := config.LoadConfig() pfConfig, configFileProvider := config.LoadConfig()
// Watch for config changes and re-load config if needed
configFileProvider.Watch(func(event interface{}, err error) {
if err != nil {
log.Printf("Error setting up watch of config : %s", err)
return
}
// Bail on slideshow if there is a config change so it restarts with updated config
log.Fatalf("Config file changed! Exiting!")
})
log.Print("========================================") log.Print("========================================")
pfConfig.Print() pfConfig.Print()

View file

@ -38,18 +38,18 @@ func main() {
pfConfig.Print() pfConfig.Print()
// Watch for config changes and re-load config if needed // Watch for config changes and re-load config if needed
// configFileProvider.Watch(func(event interface{}, err error) { configFileProvider.Watch(func(event interface{}, err error) {
// if err != nil { if err != nil {
// log.Printf("Error setting up watch of config : %s", err) log.Printf("Error setting up watch of config : %s", err)
// return return
// } }
// // Give the config UI a chance to save and exit clean // Give the config UI a chance to save and exit clean
// time.Sleep(time.Minute) time.Sleep(time.Minute)
// // Bail on slideshow if there is a config change so it restarts with updated config // Bail on slideshow if there is a config change so it restarts with updated config
// log.Fatalf("Config file changed! Exiting!") log.Fatalf("Config file changed! Exiting!")
// }) })
// Process command line flags // Process command line flags
if err := pfConfig.Load(posflag.Provider(f, ".", pfConfig), nil); err != nil { if err := pfConfig.Load(posflag.Provider(f, ".", pfConfig), nil); err != nil {

View file

@ -18,7 +18,18 @@ const (
func main() { func main() {
// Load the config file // Load the config file
pfConfig, _ := config.LoadConfig() pfConfig, configFileProvider := config.LoadConfig()
// Watch for config changes and re-load config if needed
configFileProvider.Watch(func(event interface{}, err error) {
if err != nil {
log.Printf("Error setting up watch of config : %s", err)
return
}
// Bail on slideshow if there is a config change so it restarts with updated config
log.Fatalf("Config file changed! Exiting!")
})
PATH_PICTURES := pfConfig.String(config.CONFIG_KEY_ALBUMS_ROOT) PATH_PICTURES := pfConfig.String(config.CONFIG_KEY_ALBUMS_ROOT)