plugin

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunCommandAsync

func RunCommandAsync(logger *zap.Logger, name string, args ...string)

RunCommandAsync executes a system command in a goroutine so it doesn't block the plugin handler. It logs a warning if the command fails, aiding in debugging missing dependencies (like notify-send, xclip).

Types

type Plugin

type Plugin interface {
	// Name returns the unique human-readable name of the plugin (e.g. "Battery").
	Name() string

	// IncomingTypes returns a list of packet type strings this plugin handles.
	IncomingTypes() []string

	// OutgoingTypes returns a list of packet type strings this plugin may send.
	OutgoingTypes() []string

	// Timeout returns the maximum duration allowed for this plugin's Handle execution.
	// Return 0 for no timeout (or a global default).
	Timeout() time.Duration

	// OnConnect is called when the device connects.
	OnConnect(dev device.Sender)

	// OnDisconnect is called when the device disconnects.
	OnDisconnect(dev device.Sender)
	Handle(ctx context.Context, dev device.Sender, pkt *protocol.Packet) error
}

Plugin represents a KDE Connect functionality module. Implementations must not import other plugins, and must not block in Handle.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages the set of active plugins and routes packets to them.

func NewRegistry

func NewRegistry(logger *zap.Logger) *Registry

NewRegistry creates a new plugin registry.

func (*Registry) All

func (r *Registry) All() []Plugin

All returns a slice of all registered plugins.

func (*Registry) Capabilities

func (r *Registry) Capabilities() (incoming []string, outgoing []string)

Capabilities returns the aggregated incoming and outgoing capabilities of all registered plugins, suitable for sending in an Identity packet.

func (*Registry) Dispatch

func (r *Registry) Dispatch(ctx context.Context, dev device.Sender, pkt *protocol.Packet)

Dispatch routes an incoming packet to the appropriate plugin.

func (*Registry) GetByName

func (r *Registry) GetByName(name string) (Plugin, bool)

GetByName returns a registered plugin by its Name().

func (*Registry) OnConnect

func (r *Registry) OnConnect(dev device.Sender)

OnConnect is called when a device connects. It calls OnConnect on all registered plugins.

func (*Registry) OnDisconnect

func (r *Registry) OnDisconnect(dev device.Sender)

OnDisconnect is called when a device disconnects. It calls OnDisconnect on all registered plugins.

func (*Registry) Register

func (r *Registry) Register(p Plugin)

Register adds a plugin to the registry and indexes it by its incoming types.

Jump to

Keyboard shortcuts

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