forked from samwho/streamdeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistration.go
110 lines (91 loc) · 2.82 KB
/
registration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package streamdeck
import (
"encoding/json"
"flag"
"fmt"
)
// RegistrationParams Params for registering streamdeck plugin.
type RegistrationParams struct {
Port int
PluginUUID string
RegisterEvent string
Info Info
}
type Application struct {
Font string `json:"font"`
Language string `json:"language"`
Platform string `json:"platform"`
PlatformVersion string `json:"platformVersion"`
Version string `json:"version"`
}
type Plugin struct {
UUID string `json:"uuid"`
Version string `json:"version"`
}
type Colors struct {
ButtonPressedBackgroundColor string `json:"buttonPressedBackgroundColor"`
ButtonPressedBorderColor string `json:"buttonPressedBorderColor"`
ButtonPressedTextColor string `json:"buttonPressedTextColor"`
DisabledColor string `json:"disabledColor"`
HighlightColor string `json:"highlightColor"`
MouseDownColor string `json:"mouseDownColor"`
}
type Size struct {
Columns int `json:"columns"`
Rows int `json:"rows"`
}
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
Size Size `json:"size"`
Type int `json:"type"`
}
type ActionInfoPayload[SettingsT any] struct {
Coordinates Coordinates `json:"coordinates,omitempty"`
Settings SettingsT `json:"settings,omitempty"`
}
type ActionInfo[SettingsT any] struct {
Action string `json:"action"`
Context string `json:"context"`
Device string `json:"device"`
Payload ActionInfoPayload[SettingsT] `json:"payload"`
}
type Info struct {
Application Application `json:"application"`
Plugin Plugin `json:"plugin"`
DevicePixelRatio int `json:"devicePixelRatio"`
Colors Colors `json:"colors"`
Devices []Device `json:"devices"`
}
// ParseRegistrationParams Parse parameters. Normally you should use os.Args .
func ParseRegistrationParams(args []string) (RegistrationParams, error) {
f := flag.NewFlagSet("registration_params", flag.ContinueOnError)
ret := RegistrationParams{}
port := f.Int("port", -1, "")
pluginUUID := f.String("pluginUUID", "", "")
registerEvent := f.String("registerEvent", "", "")
info := f.String("info", "", "")
if err := f.Parse(args[1:]); err != nil {
return ret, err
}
if *port == -1 {
return ret, fmt.Errorf("missing -port flag")
}
ret.Port = *port
if *pluginUUID == "" {
return ret, fmt.Errorf("missing -pluginUUID flag")
}
ret.PluginUUID = *pluginUUID
if *registerEvent == "" {
return ret, fmt.Errorf("missing -registerEvent flag")
}
ret.RegisterEvent = *registerEvent
if *info == "" {
return ret, fmt.Errorf("missing -info flag")
}
infob := []byte(*info)
if err := json.Unmarshal(infob, &ret.Info); err != nil {
return ret, err
}
return ret, nil
}