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:
parent
f3b71d12c9
commit
2059647373
3 changed files with 11 additions and 9 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue