1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-20 09:41:19 +00:00

Allow multi-actions

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-11-21 16:30:16 +01:00
parent f3b71d12c9
commit 2059647373
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 11 additions and 9 deletions

View file

@ -11,9 +11,9 @@ type page struct {
}
type keyDefinition struct {
Display dynamicElement `yaml:"display"`
Action dynamicElement `yaml:"action"`
On string `yaml:"on"`
Display dynamicElement `yaml:"display"`
Actions []dynamicElement `yaml:"actions"`
On string `yaml:"on"`
}
type dynamicElement struct {

View file

@ -125,8 +125,10 @@ func togglePage(page string) error {
}
func triggerAction(kd keyDefinition) error {
if kd.Action.Type != "" {
return callAction(kd)
for _, a := range kd.Actions {
if a.Type != "" {
return callAction(a)
}
}
return nil

View file

@ -36,15 +36,15 @@ func registerDisplayElement(name string, handler displayElement) {
registeredDisplayElements[name] = reflect.TypeOf(handler)
}
func callAction(kd keyDefinition) error {
t, ok := registeredActions[kd.Action.Type]
func callAction(a dynamicElement) error {
t, ok := registeredActions[a.Type]
if !ok {
return errors.Errorf("Unknown action type %q", kd.Action.Type)
return errors.Errorf("Unknown action type %q", a.Type)
}
inst := reflect.New(t).Interface().(action)
return inst.Execute(kd.Action.Attributes)
return inst.Execute(a.Attributes)
}
func callDisplayElement(idx int, kd keyDefinition) error {