plugin

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package plugin calls native code: a method of a plugin registered in the iOS or Android host, written in Swift or Kotlin. Arguments and results travel as JSON, so a plugin needs no generated code on either side.

type token struct{ Value string `json:"value"` }
t, err := plugin.Call[token](ctx, "secureStorage", "get", map[string]string{"key": "token"})

Call blocks until the native side answers, so call it where blocking is fine: in ui.UseQuery, ui.UseAction, an effect or your own goroutine, not in Render. The host runs every plugin method on its main thread.

Plugins are registered in the host:

Plugins.register("battery") { call in call.resolve(UIDevice.current.batteryLevel) }   // Swift
Plugins.register("battery") { call -> call.resolve(level) }                           // Kotlin

Index

Constants

View Source
const (
	Unavailable = "unavailable"
	Cancelled   = "cancelled"
	Denied      = "denied"
	NotFound    = "not_found"
	Failed      = "failed"
)

Codes of Error.

Variables

View Source
var OnBackground func(name string)

OnBackground is called with the name of each background task the host starts; plugins/backgroundtasks sets it.

Functions

func Call

func Call[Resp any](ctx context.Context, name, method string, args any) (Resp, error)

Call runs method on the named plugin with args (any JSON-encodable value, or nil) and decodes the answer into Resp. Use struct{} or any for a method with no useful answer.

func CallJSON

func CallJSON(ctx context.Context, name, method string, args any) (json.RawMessage, error)

CallJSON is Call with the raw JSON answer.

func Deliver

func Deliver(r *render.PluginResult)

Deliver hands a plugin's outcome to the waiting Call. The UI runtime calls it for every PluginResult the host sends.

func IsCode

func IsCode(err error, code string) bool

IsCode reports whether err is a plugin Error with the given code.

func RunBackground added in v0.0.13

func RunBackground(name string)

RunBackground starts a background task. The UI runtime calls it.

Types

type Error

type Error struct {
	Plugin, Method string
	// Code says what kind of failure: "unavailable" (no such plugin or
	// method here), "cancelled" (the user backed out), "denied" (no
	// permission), "not_found", or "failed".
	Code    string
	Message string
}

Error is a failed plugin call.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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