plugin

package
v0.0.0-...-351e1a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package plugin provides an event based sdk of the TouchPortal api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsepluginEvent

func ParsepluginEvent(s string) (pluginEvent, error)

Types

type Plugin

type Plugin struct {
	ID                 string
	TouchPortalVersion string
	SdkVersion         int
	PluginVersion      int
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin(ctx context.Context, id string) *Plugin

NewPlugin creates, initialises and returns a TouchPortal plugin instance

func NewPluginWithClient

func NewPluginWithClient(ctx context.Context, cli pluginClient, id string) *Plugin

NewPluginWithClient creates, initialises and returns a TouchPortal plugin instance allowing the usage of a custom client instance

func (*Plugin) Done

func (p *Plugin) Done() <-chan bool

Done provides an unbuffered, blocking, channel that can be used to verify that the Plugin has finished it's run and cleaned up used resources.

func (*Plugin) OnAction

func (p *Plugin) OnAction(handler func(event client.ActionMessage), actionID string)

OnAction allows the registration of an event handler to the "action" TouchPortal message. The matching of the actionId parameter to the one sent by TouchPortal is handled for you and your passed handler function will only be executed if it matches.

func (*Plugin) OnClosePlugin

func (p *Plugin) OnClosePlugin(handler func(event client.ClosePluginMessage))

OnClosePlugin allows the registration of an event handler to the "closePlugin" TouchPortal message. A default handler is already in place to close down the plugin itself but you may wish to add an additional hook so you can carry out other shutdown tasks.

func (*Plugin) OnInfo

func (p *Plugin) OnInfo(handler func(event client.InfoMessage))

OnInfo allows the registration of an event handler to the "info" TouchPortal message. As the "info" message is only sent as a part of the registration process it is necessary to register any custom handlers before plugin.Register function is called.

func (*Plugin) Register

func (p *Plugin) Register() error

Register asks the TouchPortal plugin instance to handle the registration process with TouchPortal. It ensures that any settings are synced to the SDK and registers a handler that allows the SDK to deal with shutdown requests.

func (*Plugin) Settings

func (p *Plugin) Settings(s interface{})

Settings allows you to provide a reference to a struct that will be populated by TouchPortal when the plugin registers itself or a settings update occurs.

It works in a similar way to standard json Marshal/Unmarshal and is even driven by the same struct tags.

Currently only string and int types are supported

type settings struct {
    Host string `json:"Host"`
    Port int    `json:"Port,string"`
}

func main() {
    p := NewPlugin(...)
    s := &settings{}

    p.Settings(s)
    p.Register()
    // p will now contain any settings that TouchPortal returned
}

Interestingly it's important to note that TouchPortal string encodes both string and integer values so when Unmarshaling to an int you will need to ensure you mark it as ",string" as shown above.

func (*Plugin) UpdateState

func (p *Plugin) UpdateState(id string, value string) error

UpdateState allows you to send state update messages to TouchPortal

type SettingsUpdated

type SettingsUpdated interface {
	IsUpdated()
}

SettingsUpdated implemented on the struct you use to power your plugins settings will allow you to be made aware when the settings have been updated by TouchPortal.

Directories

Path Synopsis
Package mock_plugin is a generated GoMock package.
Package mock_plugin is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL