streamdeck-sdk/main.go

62 lines
1.3 KiB
Go
Raw Normal View History

2019-07-12 10:35:01 -06:00
package main
import (
2019-07-12 16:39:12 -06:00
"context"
2019-07-12 10:35:01 -06:00
"flag"
2019-07-12 16:39:12 -06:00
"log"
"os"
"github.com/samwho/streamdeck-livesplit/streamdeck"
)
const (
logFile = "C:\\Users\\samwh\\AppData\\Roaming\\Elgato\\StreamDeck\\logs\\streamdeck-livesplit.log"
)
var (
port = flag.Int("port", -1, "")
pluginUUID = flag.String("pluginUUID", "", "")
registerEvent = flag.String("registerEvent", "", "")
info = flag.String("info", "", "")
2019-07-12 10:35:01 -06:00
)
func main() {
2019-07-12 16:39:12 -06:00
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
2019-07-12 10:35:01 -06:00
flag.Parse()
2019-07-12 16:39:12 -06:00
params := streamdeck.RegistrationParams{
Port: *port,
PluginUUID: *pluginUUID,
RegisterEvent: *registerEvent,
Info: *info,
}
log.Printf("registration params: %v\n", params)
ctx := context.Background()
if err := run(ctx, params); err != nil {
log.Fatalf("%v\n", err)
}
}
func run(ctx context.Context, params streamdeck.RegistrationParams) error {
client, err := streamdeck.NewClient(ctx, params)
if err != nil {
return err
}
client.RegisterHandler(streamdeck.KeyDown, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) {
return client.Log("key down!")
})
log.Println("waiting for connection to close...")
client.Join()
return nil
2019-07-12 10:35:01 -06:00
}