diff --git a/widget.go b/widget.go index 60764b1..bda3752 100644 --- a/widget.go +++ b/widget.go @@ -122,6 +122,9 @@ func NewWidget(dev *streamdeck.Device, base string, kc KeyConfig, bg image.Image case "command": return NewCommandWidget(bw, kc.Widget), nil + case "imageCommand": + return NewCommandImageWidget(bw, kc.Widget), nil + case "weather": return NewWeatherWidget(bw, kc.Widget) } diff --git a/widget_command_image.go b/widget_command_image.go new file mode 100644 index 0000000..71f3d11 --- /dev/null +++ b/widget_command_image.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "image" + "os" + "time" +) + +type CommandImageWidget struct { + *BaseWidget + commands []string +} + +// NewCommandImageWidget returns a new CommandImageWidget. +func NewCommandImageWidget(bw *BaseWidget, opts WidgetConfig) *CommandImageWidget { + bw.setInterval(time.Duration(opts.Interval)*time.Millisecond, time.Second) + + var commands []string + _ = ConfigValue(opts.Config["command"], &commands) + + return &CommandImageWidget{ + BaseWidget: bw, + commands: commands, + } +} + +func (w *CommandImageWidget) Update() error { + size := int(w.dev.Pixels) + margin := size / 18 + height := size - (margin * 2) + img := image.NewRGBA(image.Rect(0, 0, size, size)) + + str, err3 := runCommand(w.commands[0]) + if err3 != nil { + fmt.Fprintf(os.Stderr, "Running command failed: %s\n", err3) + + return err3 + } + icon, err := loadImage(str) + if err != nil { + fmt.Fprintf(os.Stderr, "Loading Image failed: %s\n", err) + } else { + err2 := drawImage(img, + icon, + height, + image.Pt(-1, -1)) + if err2 != nil { + return w.render(w.dev, img) + } + } + + return w.render(w.dev, img) +}