1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-21 02:01:24 +00:00

Add "reload_config" action

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-11-22 00:16:25 +01:00
parent 16a04cbfdf
commit 131d09b78c
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 36 additions and 7 deletions

View file

@ -0,0 +1,17 @@
package main
import "github.com/pkg/errors"
func init() {
registerAction("reload_config", actionReloadConfig{})
}
type actionReloadConfig struct{}
func (actionReloadConfig) Execute(attributes map[string]interface{}) error {
if err := loadConfig(); err != nil {
return errors.Wrap(err, "Unable to reload config")
}
return togglePage(userConfig.DefaultPage)
}

View file

@ -51,18 +51,30 @@ func init() {
} }
} }
func main() { func loadConfig() error {
// Load config
userConfFile, err := os.Open(cfg.Config) userConfFile, err := os.Open(cfg.Config)
if err != nil { if err != nil {
log.WithError(err).Fatal("Unable to open config") return errors.Wrap(err, "Unable to open config")
}
defer userConfFile.Close()
var tempConf config
if err = yaml.NewDecoder(userConfFile).Decode(&tempConf); err != nil {
return errors.Wrap(err, "Unable to parse config")
} }
if err = yaml.NewDecoder(userConfFile).Decode(&userConfig); err != nil { userConfig = tempConf
log.WithError(err).Fatal("Unable to parse config")
}
userConfFile.Close() return nil
}
func main() {
var err error
// Load config
if err = loadConfig(); err != nil {
log.WithError(err).Fatal("Unable to load config")
}
// Initalize control devices // Initalize control devices
kbd, err = uinput.CreateKeyboard() kbd, err = uinput.CreateKeyboard()