plugin

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 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).

func RunCommandSync added in v1.12.5

func RunCommandSync(ctx context.Context, name string, args ...string) ([]byte, error)

RunCommandSync executes a system command synchronously and returns its combined output and error. The caller is responsible for applying timeouts via the context.

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) bool

Dispatch routes an incoming packet to the appropriate plugin. Returns true if the packet was processed within the timeout and may be safely returned to the packet pool. Returns false if the plugin timed out — the caller must NOT recycle the packet because the background goroutine may still hold a reference to it.

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