6 Commits

Author SHA1 Message Date
8abdbb6683 state can be omitted 2024-06-29 14:50:21 +09:30
ffc606ec77 Improve formatting 2024-06-29 11:33:24 +09:30
2eeaae2232 Add more links and a basic example 2024-06-29 11:23:34 +09:30
bfc17b45d4 Fix JSON tag for setImage 2024-06-28 19:07:50 +09:30
4d2ebbd805 This does not need context 2024-06-28 18:59:10 +09:30
5b349724eb Correct func name 2024-06-28 18:56:33 +09:30
3 changed files with 67 additions and 4 deletions

View File

@@ -1,2 +1,65 @@
# Stream Deck plugin library for Go
[![Go Reference](https://pkg.go.dev/badge/github.com/tardisx/streamdeck-plugin.svg)](https://pkg.go.dev/github.com/tardisx/streamdeck-plugin)
You can find fully-formed examples using this library in
[streamdeck-plugin-examples](https://github.com/tardisx/streamdeck-plugin-examples)
## Basic usage
```go
package main
import (
"fmt"
"log/slog"
"time"
"github.com/tardisx/streamdeck-plugin"
"github.com/tardisx/streamdeck-plugin/events"
)
// keep track of instances we've seen
var contexts = map[string]bool{}
func main() {
slog.Info("Starting up")
c := streamdeck.New()
slog.Info("Registering handlers")
c.RegisterHandler(func(e events.ERWillAppear) {
slog.Info(fmt.Sprintf("action %s appeared, context %s", e.Action, e.Context))
contexts[e.Context] = true
})
c.RegisterHandler(func(e events.ERWillDisappear) {
slog.Info(fmt.Sprintf("action %s disappeared, context %s", e.Action, e.Context))
delete(contexts, e.Context)
})
c.RegisterHandler(func(e events.ERKeyDown) {
slog.Info(fmt.Sprintf("action %s appeared, context %s", e.Action, e.Context))
})
slog.Info("Connecting web socket")
err := c.Connect()
if err != nil {
panic(err)
}
// update the title once a second, for all "seen" contexts
go func() {
for {
for context := range contexts {
c.Send(events.NewESSetTitle(
context,
time.Now().Format(time.Kitchen),
events.EventTargetBoth,
0))
}
time.Sleep(time.Second)
}
}()
slog.Info("waiting for the end")
c.WaitForPluginExit()
}
```

View File

@@ -158,12 +158,12 @@ type ESSetImage struct {
}
type ESSetImagePayload struct {
Image string `json:"title"`
Image string `json:"image"`
Target EventTarget `json:"target"`
State int `json:"state"`
State *int `json:"state,omitempty"`
}
func NewESSetImagePayload(context string, imageBase64 string, target EventTarget, state int) ESSetImage {
func NewESSetImage(context string, imageBase64 string, target EventTarget, state *int) ESSetImage {
return ESSetImage{
ESCommon: ESCommon{
Event: "setImage",

View File

@@ -24,6 +24,6 @@ func ImageToPayload(i image.Image) string {
// SVGToPayload create the string necessary to send an SVG
// via a ESSetImage struct
func SVGToPayload(context string, svg string) string {
func SVGToPayload(svg string) string {
return "data:image/svg+xml;charset=utf8," + svg
}