Skip to content

Commit

Permalink
Application events, settings, correct targets for SetTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
tystuyfzand committed May 19, 2019
1 parent 7aba07a commit 685c58c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 86 deletions.
64 changes: 32 additions & 32 deletions constants.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
package sdk

const (
CommonAction = "action"
CommonEvent = "event"
CommonContext = "context"
CommonPayload = "payload"
CommonDevice = "device"
CommonAction = "action"
CommonEvent = "event"
CommonContext = "context"
CommonPayload = "payload"
CommonDevice = "device"
CommonDeviceInfo = "deviceInfo"

EventKeyDown = "keyDown"
EventKeyUp = "keyUp"
EventWillAppear = "willAppear"
EventWillDisappear = "willDisappear"
EventDeviceDidConnect = "deviceDidConnect"
EventDeviceDidDisconnect = "deviceDidDisconnect"
EventApplicationDidLaunch = "applicationDidLaunch"
EventApplicationDidTerminate = "applicationDidTerminate"
EventTitleParametersDidChange = "titleParametersDidChange"
EventDidReceiveSettings = "didReceiveSettings"
EventDidReceiveGlobalSettings = "didReceiveGlobalSettings"
EventPropertyInspectorDidAppear = "propertyInspectorDidAppear"
EventKeyDown = "keyDown"
EventKeyUp = "keyUp"
EventWillAppear = "willAppear"
EventWillDisappear = "willDisappear"
EventDeviceDidConnect = "deviceDidConnect"
EventDeviceDidDisconnect = "deviceDidDisconnect"
EventApplicationDidLaunch = "applicationDidLaunch"
EventApplicationDidTerminate = "applicationDidTerminate"
EventTitleParametersDidChange = "titleParametersDidChange"
EventDidReceiveSettings = "didReceiveSettings"
EventDidReceiveGlobalSettings = "didReceiveGlobalSettings"
EventPropertyInspectorDidAppear = "propertyInspectorDidAppear"
EventPropertyInspectorDidDisappear = "propertyInspectorDidDisappear"

EventSetTitle = "setTitle"
EventSetImage = "setImage"
EventShowAlert = "showAlert"
EventShowOK = "showOk"
EventGetSettings = "getSettings"
EventSetSettings = "setSettings"
EventGetGlobalSettings = "getGlobalSettings"
EventSetGlobalSettings = "setGlobalSettings"
EventSetState = "setState"
EventSwitchToProfile = "switchToProfile"
EventSetTitle = "setTitle"
EventSetImage = "setImage"
EventShowAlert = "showAlert"
EventShowOK = "showOk"
EventGetSettings = "getSettings"
EventSetSettings = "setSettings"
EventGetGlobalSettings = "getGlobalSettings"
EventSetGlobalSettings = "setGlobalSettings"
EventSetState = "setState"
EventSwitchToProfile = "switchToProfile"
EventSendToPropertyInspector = "sendToPropertyInspector"
EventSendToPlugin = "sendToPlugin"
EventOpenURL = "openUrl"
EventLogMessage = "logMessage"
EventSendToPlugin = "sendToPlugin"
EventOpenURL = "openUrl"
EventLogMessage = "logMessage"

TargetSoftware = 0
TargetBoth = 0
TargetHardware = 1
TargetBoth = 2
TargetSoftware = 2
)
22 changes: 1 addition & 21 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,10 @@ func handleEvent(t string, i interface{}) {
handle(t, i)
}

// applicationLaunchEventHandler is an event handler for ApplicationLaunchEvent events.
type applicationLaunchEventHandler func(*ApplicationLaunchEvent)

// Type returns the event type for ApplicationLaunchEvent events.
func (eh applicationLaunchEventHandler) Type() string {
return EventApplicationDidLaunch
}

// New returns a new instance of ApplicationLaunchEvent.
func (eh applicationLaunchEventHandler) New() interface{} {
return &ApplicationLaunchEvent{}
}

// Handle is the handler for ApplicationLaunchEvent events.
func (eh applicationLaunchEventHandler) Handle(i interface{}) {
if t, ok := i.(*ApplicationLaunchEvent); ok {
eh(t)
}
}

// onInterface handles all internal events and routes them to the appropriate internal handler.
func onInterface(i interface{}) {
switch t := i.(type) {
case *KeyDownEvent:
handleAction(t.Action, t.Context, t.Payload, t.DeviceId)
}
}
}
48 changes: 47 additions & 1 deletion eventhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,52 @@ func (eh globalSettingsEventHandler) Handle(i interface{}) {
}
}

// receiveSettingsEventHandler is an event handler for ReceiveSettingsEvent events.
type receiveSettingsEventHandler func(*ReceiveSettingsEvent)

// Type returns the event type for ReceiveSettingsEvent events.
func (eh receiveSettingsEventHandler) Type() string {
return EventDidReceiveSettings
}

// New returns a new instance of ReceiveSettingsEvent.
func (eh receiveSettingsEventHandler) New() interface{} {
return &ReceiveSettingsEvent{}
}

// Handle is the handler for ReceiveSettingsEvent events.
func (eh receiveSettingsEventHandler) Handle(i interface{}) {
if t, ok := i.(*ReceiveSettingsEvent); ok {
eh(t)
}
}

// applicationLaunchEventHandler is an event handler for ApplicationLaunchEvent events.
type applicationLaunchEventHandler func(*ApplicationLaunchEvent)

// Type returns the event type for ApplicationLaunchEvent events.
func (eh applicationLaunchEventHandler) Type() string {
return EventApplicationDidLaunch
}

// New returns a new instance of ApplicationLaunchEvent.
func (eh applicationLaunchEventHandler) New() interface{} {
return &ApplicationLaunchEvent{}
}

// Handle is the handler for ApplicationLaunchEvent events.
func (eh applicationLaunchEventHandler) Handle(i interface{}) {
if t, ok := i.(*ApplicationLaunchEvent); ok {
eh(t)
}
}

// applicationTerminateEventHandler is an event handler for ApplicationTerminateEvent events.
type applicationTerminateEventHandler func(*ApplicationTerminateEvent)

// Type returns the event type for ApplicationTerminateEvent events.
func (eh applicationTerminateEventHandler) Type() string {
return EventDidReceiveGlobalSettings
return EventApplicationDidTerminate
}

// New returns a new instance of ApplicationTerminateEvent.
Expand Down Expand Up @@ -200,6 +240,12 @@ func handlerForInterface(handler interface{}) EventHandler {
return sendToPluginEventHandler(v)
case func(*GlobalSettingsEvent):
return globalSettingsEventHandler(v)
case func(*ReceiveSettingsEvent):
return receiveSettingsEventHandler(v)
case func(*ApplicationLaunchEvent):
return applicationLaunchEventHandler(v)
case func(*ApplicationTerminateEvent):
return applicationTerminateEventHandler(v)
}

return nil
Expand Down
24 changes: 16 additions & 8 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sdk

func OpenURL(url string) {
conn.WriteJSON(&sentEvent{
Event: EventOpenURL,
Event: EventOpenURL,
Payload: &openUrlPayload{url},
})
}
Expand All @@ -11,52 +11,60 @@ func GetGlobalSettings() {
conn.WriteJSON(&sentEvent{Event: EventGetGlobalSettings, Context: PluginUUID})
}

func GetSettings(context string) {
conn.WriteJSON(&sentEvent{Event: EventGetSettings, Context: context})
}

func SetGlobalSettings(v interface{}) {
conn.WriteJSON(&sentEvent{Event: EventSetGlobalSettings, Context: PluginUUID, Payload: v})
}

func SetSettings(context string, v interface{}) {
conn.WriteJSON(&sentEvent{Event: EventSetSettings, Context: context, Payload: v})
}

func Log(message string) {
conn.WriteJSON(&sentEvent{
Event: EventLogMessage,
Event: EventLogMessage,
Context: PluginUUID,
Payload: &logMessagePayload{message},
})
}

func SetTitle(context, title string, target int) {
conn.WriteJSON(&sentEvent{
Event: EventSetTitle,
Event: EventSetTitle,
Context: context,
Payload: &setTitlePayload{Title: title, Target: target},
})
}

func SetState(context string, state int) {
conn.WriteJSON(&sentEvent{
Event: EventSetState,
Event: EventSetState,
Context: context,
Payload: &setStatePayload{state},
})
}

func SetImage(context, imageData string, target int) {
conn.WriteJSON(&sentEvent{
Event: EventSetImage,
Event: EventSetImage,
Context: context,
Payload: &setImagePayload{imageData, target},
})
}

func ShowAlert(context string) {
conn.WriteJSON(&sentEvent{
Event: EventShowAlert,
Event: EventShowAlert,
Context: context,
})
}

func ShowOk(context string) {
conn.WriteJSON(&sentEvent{
Event: EventShowOK,
Event: EventShowOK,
Context: context,
})
}
}
55 changes: 31 additions & 24 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import "github.com/valyala/fastjson"
// Sent on socket open to identify the plugin/register it
type openMessage struct {
Event string `json:"event"`
UUID string `json:"uuid"`
UUID string `json:"uuid"`
}

// Sent to the Stream Deck software as a generic event
type sentEvent struct {
Event string `json:"event"`
Context string `json:"context,omitempty"`
Event string `json:"event"`
Context string `json:"context,omitempty"`
Payload interface{} `json:"payload"`
}

Expand All @@ -26,63 +26,70 @@ type logMessagePayload struct {
}

type setTitlePayload struct {
Title string `json:"title"`
Target int `json:"target"`
Title string `json:"title"`
Target int `json:"target"`
}

type setStatePayload struct {
State int `json:"state"`
}

type setImagePayload struct {
Image string `json:"image"`
Target int `json:"target"`
Image string `json:"image"`
Target int `json:"target"`
}

// Events

type KeyDownEvent struct {
Action string
Context string
Payload *fastjson.Value
Action string
Context string
Payload *fastjson.Value
DeviceId string
}

type KeyUpEvent struct {
Action string
Context string
Payload *fastjson.Value
Action string
Context string
Payload *fastjson.Value
DeviceId string
}

type WillAppearEvent struct {
Action string
Context string
Payload *fastjson.Value
Action string
Context string
Payload *fastjson.Value
DeviceId string
}

type WillDisappearEvent struct {
Action string
Context string
Payload *fastjson.Value
Action string
Context string
Payload *fastjson.Value
DeviceId string
}

type DeviceConnectEvent struct {
DeviceId string
Info *fastjson.Value
Info *fastjson.Value
}

type DeviceDisconnectEvent struct {
DeviceId string
}

type SendToPluginEvent struct {
Action string
Context string
Payload *fastjson.Value
Action string
Context string
Payload *fastjson.Value
DeviceId string
}

type ReceiveSettingsEvent struct {
Action string
Context string
DeviceId string
Settings *fastjson.Value
}

type GlobalSettingsEvent struct {
Expand All @@ -95,4 +102,4 @@ type ApplicationLaunchEvent struct {

type ApplicationTerminateEvent struct {
Application string
}
}

0 comments on commit 685c58c

Please sign in to comment.