diff --git a/cmd/streamdeck/display_exec.go b/cmd/streamdeck/display_exec.go index 226616e..6c64b8e 100644 --- a/cmd/streamdeck/display_exec.go +++ b/cmd/streamdeck/display_exec.go @@ -111,6 +111,14 @@ func (d displayElementExec) Display(idx int, attributes map[string]interface{}) return errors.Wrap(sd.FillImage(idx, img), "Unable to set image") } +func (d displayElementExec) NeedsLoop(attributes map[string]interface{}) bool { + if v, ok := attributes["interval"].(int); ok { + return v > 0 + } + + return false +} + func (d *displayElementExec) StartLoopDisplay(idx int, attributes map[string]interface{}) error { d.running = true diff --git a/cmd/streamdeck/registry.go b/cmd/streamdeck/registry.go index 05fc117..c2b0c30 100644 --- a/cmd/streamdeck/registry.go +++ b/cmd/streamdeck/registry.go @@ -5,6 +5,7 @@ import ( "sync" "github.com/pkg/errors" + log "github.com/sirupsen/logrus" ) type action interface { @@ -16,6 +17,7 @@ type displayElement interface { } type refreshingDisplayElement interface { + NeedsLoop(attributes map[string]interface{}) bool StartLoopDisplay(idx int, attributes map[string]interface{}) error StopLoopDisplay() error } @@ -65,7 +67,12 @@ func callDisplayElement(idx int, kd keyDefinition) error { inst = reflect.New(t).Interface() } - if t.Implements(reflect.TypeOf((*refreshingDisplayElement)(nil)).Elem()) { + if t.Implements(reflect.TypeOf((*refreshingDisplayElement)(nil)).Elem()) && + inst.(refreshingDisplayElement).NeedsLoop(kd.Display.Attributes) { + log.WithFields(log.Fields{ + "key": idx, + "display_type": kd.Display.Type, + }).Debug("Starting loop") activeLoops = append(activeLoops, inst.(refreshingDisplayElement)) return inst.(refreshingDisplayElement).StartLoopDisplay(idx, kd.Display.Attributes) }