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:
parent
16a04cbfdf
commit
131d09b78c
2 changed files with 36 additions and 7 deletions
17
cmd/streamdeck/action_reload.go
Normal file
17
cmd/streamdeck/action_reload.go
Normal 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)
|
||||||
|
}
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue