Moved payloads out of their own package because it made the API less nice.
This commit is contained in:
parent
8ee19c457a
commit
b94be0cf1e
17
client.go
17
client.go
@ -12,7 +12,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
sdcontext "github.com/samwho/streamdeck/context"
|
sdcontext "github.com/samwho/streamdeck/context"
|
||||||
"github.com/samwho/streamdeck/payload"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type EventHandler func(ctx context.Context, client *Client, event Event) error
|
type EventHandler func(ctx context.Context, client *Client, event Event) error
|
||||||
@ -153,19 +152,19 @@ func (client *Client) GetGlobalSettings(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) OpenURL(ctx context.Context, u url.URL) error {
|
func (client *Client) OpenURL(ctx context.Context, u url.URL) error {
|
||||||
return client.send(NewEvent(ctx, OpenURL, payload.OpenURL{URL: u.String()}))
|
return client.send(NewEvent(ctx, OpenURL, OpenURLPayload{URL: u.String()}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) LogMessage(message string) error {
|
func (client *Client) LogMessage(message string) error {
|
||||||
return client.send(NewEvent(nil, LogMessage, payload.LogMessage{Message: message}))
|
return client.send(NewEvent(nil, LogMessage, LogMessagePayload{Message: message}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) SetTitle(ctx context.Context, title string, target payload.Target) error {
|
func (client *Client) SetTitle(ctx context.Context, title string, target Target) error {
|
||||||
return client.send(NewEvent(ctx, SetTitle, payload.SetTitle{Title: title, Target: target}))
|
return client.send(NewEvent(ctx, SetTitle, SetTitlePayload{Title: title, Target: target}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) SetImage(ctx context.Context, base64image string, target payload.Target) error {
|
func (client *Client) SetImage(ctx context.Context, base64image string, target Target) error {
|
||||||
return client.send(NewEvent(ctx, SetImage, payload.SetImage{Base64Image: base64image, Target: target}))
|
return client.send(NewEvent(ctx, SetImage, SetImagePayload{Base64Image: base64image, Target: target}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) ShowAlert(ctx context.Context) error {
|
func (client *Client) ShowAlert(ctx context.Context) error {
|
||||||
@ -177,11 +176,11 @@ func (client *Client) ShowOk(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) SetState(ctx context.Context, state int) error {
|
func (client *Client) SetState(ctx context.Context, state int) error {
|
||||||
return client.send(NewEvent(ctx, SetState, payload.SetState{State: state}))
|
return client.send(NewEvent(ctx, SetState, SetStatePayload{State: state}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) SwitchToProfile(ctx context.Context, profile string) error {
|
func (client *Client) SwitchToProfile(ctx context.Context, profile string) error {
|
||||||
return client.send(NewEvent(ctx, SwitchToProfile, payload.SwitchProfile{Profile: profile}))
|
return client.send(NewEvent(ctx, SwitchToProfile, SwitchProfilePayload{Profile: profile}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) SendToPropertyInspector(ctx context.Context, payload interface{}) error {
|
func (client *Client) SendToPropertyInspector(ctx context.Context, payload interface{}) error {
|
||||||
|
@ -31,3 +31,11 @@ const (
|
|||||||
SetState = "setState"
|
SetState = "setState"
|
||||||
SwitchToProfile = "switchToProfile"
|
SwitchToProfile = "switchToProfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Target int
|
||||||
|
|
||||||
|
const (
|
||||||
|
HardwareAndSoftware Target = 0
|
||||||
|
OnlyHardware Target = 1
|
||||||
|
OnlySoftware Target = 2
|
||||||
|
)
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/samwho/streamdeck"
|
"github.com/samwho/streamdeck"
|
||||||
"github.com/samwho/streamdeck/payload"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -53,7 +52,7 @@ func setupCounter(client *streamdeck.Client) {
|
|||||||
settings := make(map[string]*Settings)
|
settings := make(map[string]*Settings)
|
||||||
|
|
||||||
action.RegisterHandler(streamdeck.WillAppear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
action.RegisterHandler(streamdeck.WillAppear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||||
p := payload.WillAppear{}
|
p := streamdeck.WillAppearPayload{}
|
||||||
if err := json.Unmarshal(event.Payload, &p); err != nil {
|
if err := json.Unmarshal(event.Payload, &p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -73,11 +72,11 @@ func setupCounter(client *streamdeck.Client) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.SetImage(ctx, bg, payload.HardwareAndSoftware); err != nil {
|
if err := client.SetImage(ctx, bg, streamdeck.HardwareAndSoftware); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.SetTitle(ctx, strconv.Itoa(s.Counter), payload.HardwareAndSoftware)
|
return client.SetTitle(ctx, strconv.Itoa(s.Counter), streamdeck.HardwareAndSoftware)
|
||||||
})
|
})
|
||||||
|
|
||||||
action.RegisterHandler(streamdeck.WillDisappear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
action.RegisterHandler(streamdeck.WillDisappear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||||
@ -97,7 +96,7 @@ func setupCounter(client *streamdeck.Client) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.SetTitle(ctx, strconv.Itoa(s.Counter), payload.HardwareAndSoftware)
|
return client.SetTitle(ctx, strconv.Itoa(s.Counter), streamdeck.HardwareAndSoftware)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/samwho/streamdeck/payload"
|
|
||||||
|
|
||||||
"github.com/samwho/streamdeck"
|
"github.com/samwho/streamdeck"
|
||||||
sdcontext "github.com/samwho/streamdeck/context"
|
sdcontext "github.com/samwho/streamdeck/context"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
@ -88,12 +86,12 @@ func setup(client *streamdeck.Client) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.SetImage(ctx, img, payload.HardwareAndSoftware); err != nil {
|
if err := client.SetImage(ctx, img, streamdeck.HardwareAndSoftware); err != nil {
|
||||||
log.Printf("error setting image: %v\n", err)
|
log.Printf("error setting image: %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.SetTitle(ctx, fmt.Sprintf("CPU\n%d%%", int(r[0])), payload.HardwareAndSoftware); err != nil {
|
if err := client.SetTitle(ctx, fmt.Sprintf("CPU\n%d%%", int(r[0])), streamdeck.HardwareAndSoftware); err != nil {
|
||||||
log.Printf("error setting title: %v\n", err)
|
log.Printf("error setting title: %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1,44 +1,34 @@
|
|||||||
package payload
|
package streamdeck
|
||||||
|
|
||||||
import (
|
import "encoding/json"
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Target int
|
type LogMessagePayload struct {
|
||||||
|
|
||||||
const (
|
|
||||||
HardwareAndSoftware Target = 0
|
|
||||||
OnlyHardware Target = 1
|
|
||||||
OnlySoftware Target = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
type LogMessage struct {
|
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenURL struct {
|
type OpenURLPayload struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetTitle struct {
|
type SetTitlePayload struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Target Target `json:"target"`
|
Target Target `json:"target"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetImage struct {
|
type SetImagePayload struct {
|
||||||
Base64Image string `json:"image"`
|
Base64Image string `json:"image"`
|
||||||
Target Target `json:"target"`
|
Target Target `json:"target"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetState struct {
|
type SetStatePayload struct {
|
||||||
State int `json:"state"`
|
State int `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SwitchProfile struct {
|
type SwitchProfilePayload struct {
|
||||||
Profile string `json:"profile"`
|
Profile string `json:"profile"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DidReceiveSettings struct {
|
type DidReceiveSettingsPayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
Coordinates Coordinates `json:"coordinates,omitempty"`
|
Coordinates Coordinates `json:"coordinates,omitempty"`
|
||||||
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
||||||
@ -49,11 +39,11 @@ type Coordinates struct {
|
|||||||
Row int `json:"row,omitempty"`
|
Row int `json:"row,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DidReceiveGlobalSettings struct {
|
type DidReceiveGlobalSettingsPayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyDown struct {
|
type KeyDownPayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
Coordinates Coordinates `json:"coordinates,omitempty"`
|
Coordinates Coordinates `json:"coordinates,omitempty"`
|
||||||
State int `json:"state,omitempty"`
|
State int `json:"state,omitempty"`
|
||||||
@ -61,7 +51,7 @@ type KeyDown struct {
|
|||||||
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyUp struct {
|
type KeyUpPayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
Coordinates Coordinates `json:"coordinates,omitempty"`
|
Coordinates Coordinates `json:"coordinates,omitempty"`
|
||||||
State int `json:"state,omitempty"`
|
State int `json:"state,omitempty"`
|
||||||
@ -69,21 +59,21 @@ type KeyUp struct {
|
|||||||
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WillAppear struct {
|
type WillAppearPayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
Coordinates Coordinates `json:"coordinates,omitempty"`
|
Coordinates Coordinates `json:"coordinates,omitempty"`
|
||||||
State int `json:"state,omitempty"`
|
State int `json:"state,omitempty"`
|
||||||
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WillDisappear struct {
|
type WillDisappearPayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
Coordinates Coordinates `json:"coordinates,omitempty"`
|
Coordinates Coordinates `json:"coordinates,omitempty"`
|
||||||
State int `json:"state,omitempty"`
|
State int `json:"state,omitempty"`
|
||||||
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
IsInMultiAction bool `json:"isInMultiAction,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TitleParametersDidChange struct {
|
type TitleParametersDidChangePayload struct {
|
||||||
Settings json.RawMessage `json:"settings,omitempty"`
|
Settings json.RawMessage `json:"settings,omitempty"`
|
||||||
Coordinates Coordinates `json:"coordinates,omitempty"`
|
Coordinates Coordinates `json:"coordinates,omitempty"`
|
||||||
State int `json:"state,omitempty"`
|
State int `json:"state,omitempty"`
|
||||||
@ -101,10 +91,10 @@ type TitleParameters struct {
|
|||||||
TitleColor string `json:"titleColor,omitempty"`
|
TitleColor string `json:"titleColor,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApplicationDidLaunch struct {
|
type ApplicationDidLaunchPayload struct {
|
||||||
Application string `json:"application,omitempty"`
|
Application string `json:"application,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApplicationDidTerminate struct {
|
type ApplicationDidTerminatePayload struct {
|
||||||
Application string `json:"application,omitempty"`
|
Application string `json:"application,omitempty"`
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user