1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-20 17:51:21 +00:00

Signalize errored displays on streamdeck

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-07-10 21:37:47 +02:00
parent 656a4710f0
commit fd6ac1e954
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 34 additions and 4 deletions

View file

@ -235,12 +235,20 @@ func togglePage(page string) error {
}
go func(idx int) {
var kd = activePage.Keys[idx]
if err := callDisplayElement(activePageCtx, idx, kd); err != nil {
log.WithFields(log.Fields{
var (
kd = activePage.Keys[idx]
keyLogger = log.WithFields(log.Fields{
"key": idx,
"page": activePageName,
}).WithError(err).Error("Unable to execute display element")
})
)
if err := callDisplayElement(activePageCtx, idx, kd); err != nil {
keyLogger.WithError(err).Error("Unable to execute display element")
if err := callErrorDisplayElement(activePageCtx, idx); err != nil {
keyLogger.WithError(err).Error("Unable to execute error display element")
}
}
}(idx)
}

View file

@ -9,6 +9,12 @@ import (
log "github.com/sirupsen/logrus"
)
const errorDisplayElementType = "color"
var errorDisplayElementAttributes = map[string]interface{}{
"rgba": []interface{}{0xff, 0x0, 0x0, 0xff},
}
type action interface {
Execute(attributes map[string]interface{}) error
}
@ -80,3 +86,19 @@ func callDisplayElement(ctx context.Context, idx int, kd keyDefinition) error {
return inst.(displayElement).Display(ctx, idx, kd.Display.Attributes)
}
func callErrorDisplayElement(ctx context.Context, idx int) error {
t, ok := registeredDisplayElements[errorDisplayElementType]
if !ok {
return errors.Errorf("Unknown display type %q", errorDisplayElementType)
}
var inst interface{}
if t.Kind() == reflect.Ptr {
inst = reflect.New(t.Elem()).Interface()
} else {
inst = reflect.New(t).Interface()
}
return inst.(displayElement).Display(ctx, idx, errorDisplayElementAttributes)
}