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"
|
2019-07-13 14:26:08 -06:00
|
|
|
"strconv"
|
2019-07-12 16:39:12 -06:00
|
|
|
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2019-07-13 14:26:08 -06:00
|
|
|
counter := 0
|
|
|
|
client.RegisterHandler(streamdeck.KeyDown, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
|
|
|
counter++
|
|
|
|
log.Printf("key down! counter: %d\n", counter)
|
|
|
|
return client.SetTitle(ctx, strconv.Itoa(counter), streamdeck.HardwareAndSoftware)
|
2019-07-12 16:39:12 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
log.Println("waiting for connection to close...")
|
|
|
|
client.Join()
|
|
|
|
|
|
|
|
return nil
|
2019-07-12 10:35:01 -06:00
|
|
|
}
|