Documentation
¶
Overview ¶
Package desktop provides an optional, host-independent desktop frontend bridge. Native Wails packages belong in the application's host module, never here.
Index ¶
- Constants
- Variables
- func Call[T any](parseContext context.Context, parseClient Client, parseMethod string, ...) (T, error)
- func CallWithTimeout[T any](parseContext context.Context, parseClient Client, parseTimeout time.Duration, ...) (T, error)
- func IsDesktopBuild() bool
- func Subscribe[T any](parseContext context.Context, parseClient Client, parseTopic string, ...) (func(), error)
- func SubscribeStorage(parseContext context.Context, parseClient Client, parseName string, ...) (func(), error)
- type Capabilities
- type Client
- func (parseClient Client) ControlWindow(parseContext context.Context, parseRequest WindowRequest) (WindowInfo, error)
- func (parseClient Client) GetCapabilities() (Capabilities, error)
- func (parseClient Client) ListScreens(parseContext context.Context) ([]ScreenInfo, error)
- func (parseClient Client) OpenDirectory(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func (parseClient Client) OpenFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func (parseClient Client) OpenFiles(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func (parseClient Client) ReadClipboard(parseContext context.Context) (string, error)
- func (parseClient Client) Require(parseFeatures ...Feature) error
- func (parseClient Client) SaveFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func (parseClient Client) ShowMessage(parseContext context.Context, parseRequest MessageRequest) (MessageReply, error)
- func (parseClient Client) Supports(parseFeatures ...Feature) bool
- func (parseClient Client) WriteClipboard(parseContext context.Context, parseText string) error
- type ClipboardWriteRequest
- type Feature
- type FeaturePolicy
- type FileDialogBackend
- type FileDialogHost
- type FileDialogOptions
- type FileDialogReply
- type FileDialogRequest
- type FileFilter
- type FileSelection
- func OpenDirectory(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func OpenFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func OpenFiles(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- func SaveFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
- type MessageReply
- type MessageRequest
- type NativeBackend
- type NativeHost
- func (parseHost *NativeHost) ClipboardRead(parseContext context.Context) (string, error)
- func (parseHost *NativeHost) ClipboardWrite(parseContext context.Context, parseRequest ClipboardWriteRequest) error
- func (parseHost *NativeHost) Execute(parseContext context.Context, parseRequest NativeRequest) NativeReply
- func (parseHost *NativeHost) GetFeatures() []Feature
- func (parseHost *NativeHost) GetMethods() []string
- func (parseHost *NativeHost) ListScreens(parseContext context.Context) ([]ScreenInfo, error)
- func (parseHost *NativeHost) Require(parseFeature Feature) error
- func (parseHost *NativeHost) ShowMessage(parseContext context.Context, parseRequest MessageRequest) (MessageReply, error)
- func (parseHost *NativeHost) WindowControl(parseContext context.Context, parseRequest WindowRequest) (WindowInfo, error)
- type NativeReply
- type NativeRequest
- type Reply
- type ScreenInfo
- type StorageBackend
- func (parseBackend StorageBackend) Delete(parseContext context.Context, parseKey string) error
- func (parseBackend StorageBackend) Keys(parseContext context.Context) ([]string, error)
- func (parseBackend StorageBackend) Load(parseContext context.Context, parseKey string) (kvstate.Record, bool, error)
- func (parseBackend StorageBackend) Save(parseContext context.Context, parseRecord kvstate.Record) error
- type StorageCommit
- type StorageWireRecord
- type Transport
- type WindowInfo
- type WindowRequest
Constants ¶
const ( ClipboardWriteMethod = "desktop.clipboard.write" ClipboardReadMethod = "desktop.clipboard.read" MessageMethod = "desktop.message.show" WindowMethod = "desktop.window.control" ScreensMethod = "desktop.screens.list" NativeContractVersion = 1 ReportExportMethod = "desktop.report.export" StorageLoadMethod = "storage.load" StorageSaveMethod = "storage.save" StorageDeleteMethod = "storage.delete" StorageKeysMethod = "storage.keys" )
const FileDialogMethod = "desktop.files.select"
FileDialogMethod is the adapter registration name; application callers use typed methods.
const MaximumRequestTimeout = 10 * time.Minute
MaximumRequestTimeout bounds explicitly extended interactive calls.
const ProtocolVersion = 1
ProtocolVersion identifies the synchronous transport envelope contract.
const RequestTimeout = 30 * time.Second
RequestTimeout is the default call ceiling, including context.Background calls.
Variables ¶
var BootstrapSource string
BootstrapSource is the external ES module to serve as desktop.js before Wasm.
Functions ¶
func Call ¶
func Call[T any](parseContext context.Context, parseClient Client, parseMethod string, parseArgs ...any) (T, error)
Call decodes one registered method's JSON response. Use strings for wide integer identifiers, base64 strings for bytes and RFC3339 strings for time values. Cancellation is cooperative and cannot undo completed native writes.
func CallWithTimeout ¶
func CallWithTimeout[T any](parseContext context.Context, parseClient Client, parseTimeout time.Duration, parseMethod string, parseArgs ...any) (T, error)
CallWithTimeout opts one call into a positive ceiling of at most ten minutes. Earlier context deadlines still win. Use longer waits only for interactive native operations; cancellation cannot dismiss every OS dialog or undo completed writes.
func IsDesktopBuild ¶
func IsDesktopBuild() bool
IsDesktopBuild reports the compile-time target, not permission to use a native API. An ordinary build is web/native-test mode unless gwc_desktop was explicitly set.
func Subscribe ¶
func Subscribe[T any](parseContext context.Context, parseClient Client, parseTopic string, parseHandler func(T, error)) (func(), error)
Subscribe delivers latest-value events at most once per polling tick (16 ms). Bursts coalesce per subscription, so this API is for state/progress, not audit logs. Cancel is idempotent; a handler already executing may finish after cancellation.
func SubscribeStorage ¶
func SubscribeStorage(parseContext context.Context, parseClient Client, parseName string, parseOnError func(error)) (func(), error)
SubscribeStorage reloads all existing kvstate bindings under a logical database name after a storage.changed commit. Reloading all keys makes topic-level burst coalescing safe. It never republishes events. Cancel it on unmount/window close. Backend selection remains explicit through kvstate.Options.Backend. Set Options.ExternalInvalidation=true to avoid browser BroadcastChannel forwarding.
Types ¶
type Capabilities ¶
type Capabilities struct {
Protocol int `json:"protocol"`
Platform string `json:"platform"`
HostVersion string `json:"hostVersion"`
Methods []string `json:"methods"`
Topics []string `json:"topics"`
// Features advertises non-RPC capabilities such as installed native menus.
// It is feature discovery, never authorization; RPC features still require methods.
Features []Feature `json:"features,omitempty"`
}
Capabilities describes an installed bridge, not an authorization credential.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns calls and subscriptions; its zero value is predictably unavailable.
func (Client) ControlWindow ¶
func (parseClient Client) ControlWindow(parseContext context.Context, parseRequest WindowRequest) (WindowInfo, error)
ControlWindow invokes the typed window client method.
func (Client) GetCapabilities ¶
func (parseClient Client) GetCapabilities() (Capabilities, error)
GetCapabilities validates the installed protocol before callers enable controls.
func (Client) ListScreens ¶
func (parseClient Client) ListScreens(parseContext context.Context) ([]ScreenInfo, error)
ListScreens invokes the typed screen client method.
func (Client) OpenDirectory ¶
func (parseClient Client) OpenDirectory(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
OpenDirectory selects one directory through this explicitly injected client.
func (Client) OpenFile ¶
func (parseClient Client) OpenFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
OpenFile selects one file through this explicitly injected client.
func (Client) OpenFiles ¶
func (parseClient Client) OpenFiles(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
OpenFiles selects multiple files through this explicitly injected client.
func (Client) ReadClipboard ¶
ReadClipboard invokes the typed clipboard client method.
func (Client) Require ¶
Require checks a live bridge and every requested feature; it never grants host permission.
func (Client) SaveFile ¶
func (parseClient Client) SaveFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
SaveFile selects a save destination; no file is written by this operation.
func (Client) ShowMessage ¶
func (parseClient Client) ShowMessage(parseContext context.Context, parseRequest MessageRequest) (MessageReply, error)
ShowMessage invokes the typed message client method.
type ClipboardWriteRequest ¶
type ClipboardWriteRequest struct {
Text string `json:"text"`
}
ClipboardWriteRequest carries explicit text to the native clipboard.
type Feature ¶
type Feature string
Feature identifies a portable desktop workflow, not a UI rollout flag.
const Clipboard Feature = "clipboard"
Clipboard identifies explicit text clipboard operations.
const FileDialogs Feature = "file-dialogs"
FileDialogs enables path selection, never reading or writing selected files.
const MessageDialogs Feature = "message-dialogs"
MessageDialogs identifies native information and question dialogs.
const NativeMenus Feature = "native-menus"
NativeMenus identifies native application menu and shortcut callbacks.
const PersistentStorage Feature = "persistent-storage"
PersistentStorage identifies the host-owned durable storage service.
const ReportExport Feature = "report-export"
ReportExport identifies explicit native report export.
const Screens Feature = "screens"
Screens identifies display enumeration.
const WindowControls Feature = "window-controls"
WindowControls identifies caller-owned window inspection and controls.
type FeaturePolicy ¶
type FeaturePolicy struct {
// contains filtered or unexported fields
}
FeaturePolicy is an immutable allowlist parsed from host configuration.
func ParseFeaturePolicy ¶
func ParseFeaturePolicy(parseValue string) (FeaturePolicy, error)
ParseFeaturePolicy parses all, none, or a comma-separated feature allowlist.
func (FeaturePolicy) Allows ¶
func (parsePolicy FeaturePolicy) Allows(parseFeature Feature) bool
Allows reports whether this policy permits one feature.
func (FeaturePolicy) FeatureNames ¶
func (parsePolicy FeaturePolicy) FeatureNames() []Feature
FeatureNames returns a stable copy of allowed feature names.
func (FeaturePolicy) Intersect ¶
func (parsePolicy FeaturePolicy) Intersect(parseFeatures []Feature) FeaturePolicy
Intersect combines policy and backend availability without granting either side new access.
type FileDialogBackend ¶
type FileDialogBackend interface {
SelectPaths(context.Context, FileDialogRequest) (FileSelection, error)
}
FileDialogBackend is implemented by native adapters or application test doubles. Implementations must resolve the invoking window from context, never current focus.
type FileDialogHost ¶
type FileDialogHost struct {
// contains filtered or unexported fields
}
FileDialogHost enforces immutable opt-in before invoking a native backend. Its zero value denies access. This policy covers this service, not unrelated host code.
func NewFileDialogHost ¶
func NewFileDialogHost(parseBackend FileDialogBackend, isEnabled bool) *FileDialogHost
NewFileDialogHost constructs a host service with explicit file-dialog permission.
func (*FileDialogHost) GetMethods ¶
func (parseHost *FileDialogHost) GetMethods() []string
GetMethods advertises only operations enabled in this host configuration.
func (*FileDialogHost) SelectPaths ¶
func (parseHost *FileDialogHost) SelectPaths(parseContext context.Context, parseRequest FileDialogRequest) FileDialogReply
SelectPaths validates every direct native invocation before opening a dialog.
type FileDialogOptions ¶
type FileDialogOptions struct {
Title string `json:"title"`
Directory string `json:"directory"`
Filename string `json:"filename"` // SaveFile only.
Filters []FileFilter `json:"filters"` // File pickers only, not OpenDirectory.
}
FileDialogOptions configures a caller-owned native picker.
type FileDialogReply ¶
type FileDialogReply struct {
Selection FileSelection `json:"selection"`
Code interop.ErrorCode `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
FileDialogReply preserves portable error categories across generated bindings.
type FileDialogRequest ¶
type FileDialogRequest struct {
Version int `json:"version"`
Kind string `json:"kind"`
Options FileDialogOptions `json:"options"`
}
FileDialogRequest is the versioned backend contract used by registered host services.
type FileFilter ¶
FileFilter describes an OS file-picker filter without backend-specific types.
type FileSelection ¶
FileSelection distinguishes operator cancellation from successful path selection. Selecting a save path does not create or overwrite a file.
func OpenDirectory ¶
func OpenDirectory(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
OpenDirectory opens a directory picker using the connected desktop host.
func OpenFile ¶
func OpenFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
OpenFile opens a single-file picker using the connected desktop host.
func OpenFiles ¶
func OpenFiles(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
OpenFiles opens a multiple-file picker using the connected desktop host.
func SaveFile ¶
func SaveFile(parseContext context.Context, parseOptions FileDialogOptions) (FileSelection, error)
SaveFile selects a save destination without creating or overwriting a file.
type MessageReply ¶
type MessageReply struct {
Button string `json:"button"`
}
MessageReply identifies the button selected by the operator.
type MessageRequest ¶
type MessageRequest struct {
Kind string `json:"kind"`
Title string `json:"title"`
Message string `json:"message"`
}
MessageRequest describes a bounded native dialog.
type NativeBackend ¶
type NativeBackend interface {
Features() []Feature
ClipboardWrite(context.Context, ClipboardWriteRequest) error
ClipboardRead(context.Context) (string, error)
ShowMessage(context.Context, MessageRequest) (MessageReply, error)
Window(context.Context, WindowRequest) (WindowInfo, error)
Screens(context.Context) ([]ScreenInfo, error)
}
NativeBackend is implemented by a host adapter and must resolve caller windows from context.
type NativeHost ¶
type NativeHost struct {
// contains filtered or unexported fields
}
NativeHost enforces policy and backend intersection before native work.
func NewNativeHost ¶
func NewNativeHost(parseBackend NativeBackend, parsePolicy FeaturePolicy) *NativeHost
NewNativeHost constructs a host whose effective policy is policy intersected with backend features.
func (*NativeHost) ClipboardRead ¶
func (parseHost *NativeHost) ClipboardRead(parseContext context.Context) (string, error)
ClipboardRead performs an explicitly requested clipboard read.
func (*NativeHost) ClipboardWrite ¶
func (parseHost *NativeHost) ClipboardWrite(parseContext context.Context, parseRequest ClipboardWriteRequest) error
ClipboardWrite performs an explicitly requested clipboard write.
func (*NativeHost) Execute ¶
func (parseHost *NativeHost) Execute(parseContext context.Context, parseRequest NativeRequest) NativeReply
Execute handles one versioned native request and always returns a wire-safe reply.
func (*NativeHost) GetFeatures ¶
func (parseHost *NativeHost) GetFeatures() []Feature
GetFeatures returns the effective immutable feature set.
func (*NativeHost) GetMethods ¶
func (parseHost *NativeHost) GetMethods() []string
GetMethods returns only methods enabled by effective policy.
func (*NativeHost) ListScreens ¶
func (parseHost *NativeHost) ListScreens(parseContext context.Context) ([]ScreenInfo, error)
ListScreens returns typed display information.
func (*NativeHost) Require ¶
func (parseHost *NativeHost) Require(parseFeature Feature) error
Require checks policy and backend support for one feature.
func (*NativeHost) ShowMessage ¶
func (parseHost *NativeHost) ShowMessage(parseContext context.Context, parseRequest MessageRequest) (MessageReply, error)
ShowMessage displays one typed native dialog.
func (*NativeHost) WindowControl ¶
func (parseHost *NativeHost) WindowControl(parseContext context.Context, parseRequest WindowRequest) (WindowInfo, error)
WindowControl performs one typed caller-window operation.
type NativeReply ¶
type NativeReply struct {
Version int `json:"version"`
Data json.RawMessage `json:"data,omitempty"`
Code interop.ErrorCode `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
NativeReply is the structured result envelope; native failures never rely on thrown errors.
type NativeRequest ¶
type NativeRequest struct {
Version int `json:"version"`
Method string `json:"method"`
Args json.RawMessage `json:"args"`
}
NativeRequest is the versioned envelope used by generated host bindings.
type Reply ¶
type Reply struct {
Done bool `json:"done"`
Data json.RawMessage `json:"data"`
Code interop.ErrorCode `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
Reply is a synchronously polled request/event envelope; Data is JSON, not JS handles.
type ScreenInfo ¶
type ScreenInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Primary bool `json:"primary"`
Scale float32 `json:"scale"`
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
}
ScreenInfo reports a display without exposing backend-specific screen objects.
type StorageBackend ¶
type StorageBackend struct {
// contains filtered or unexported fields
}
StorageBackend adapts the named desktop storage methods to kvstate.
func NewStorageBackend ¶
func NewStorageBackend(parseClient Client) StorageBackend
NewStorageBackend constructs a service-backed kvstate persistence backend.
func (StorageBackend) Delete ¶
func (parseBackend StorageBackend) Delete(parseContext context.Context, parseKey string) error
Delete creates a durable tombstone for one key.
func (StorageBackend) Keys ¶
func (parseBackend StorageBackend) Keys(parseContext context.Context) ([]string, error)
Keys returns live keys in the native store.
type StorageCommit ¶
type StorageCommit struct {
Key string `json:"key"`
Version string `json:"version"`
Deleted bool `json:"deleted"`
}
StorageCommit describes a successful durable mutation for event forwarding.
type StorageWireRecord ¶
type StorageWireRecord struct {
Key string `json:"key"`
Value string `json:"value"`
Version string `json:"version"`
UpdatedAt string `json:"updatedAt"`
}
StorageWireRecord is the JSON-safe storage record exchanged with a native host. Wide integers are decimal strings and bytes are base64 strings by contract.
type Transport ¶
type Transport interface {
Capabilities() (Capabilities, error)
Start(string, json.RawMessage) (string, error)
Poll(string) (Reply, error)
Cancel(string) error
Listen(string) (string, error)
Next(string) (Reply, error)
Unlisten(string) error
}
Transport can be injected in native tests. Methods must return promptly and serialize access internally. Cancel must forget requests even if native work stalls.
type WindowInfo ¶
type WindowInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Width int `json:"width"`
Height int `json:"height"`
Maximised bool `json:"maximised"`
Fullscreen bool `json:"fullscreen"`
}
WindowInfo reports stable caller-window metadata.
type WindowRequest ¶
type WindowRequest struct {
Action string `json:"action"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
}
WindowRequest describes one caller-owned window operation.