shell

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowsCommand

func AllowsCommand(capabilities CapabilitySet, kind CommandKind) bool

AllowsCommand reports whether the capability set permits the shell command.

func AllowsRequest

func AllowsRequest(capabilities CapabilitySet, kind RequestKind) bool

AllowsRequest reports whether the capability set permits the shell request.

func IsUnsupported

func IsUnsupported(err error) bool

IsUnsupported reports whether err indicates an unavailable shell operation.

Types

type Bridge

type Bridge interface {
	Surface() surface.Info
	Capabilities() CapabilitySet
	Events() *EventStream
	Dispatch(cmd Command) error
	Request(ctx context.Context, req Request) (Response, error)
}

Bridge normalizes native shell capabilities across surfaces.

func UnavailableBridge

func UnavailableBridge(info surface.Info) Bridge

UnavailableBridge returns a bridge that exposes no capabilities and fails explicitly.

type Capability

type Capability string

Capability identifies a normalized shell feature.

const (
	CapabilityWindowTitle        Capability = "window.title"
	CapabilityWindowDefaultSize  Capability = "window.default_size"
	CapabilityWindowMinimumSize  Capability = "window.minimum_size"
	CapabilityMenu               Capability = "app.menu"
	CapabilityOpenFileDialog     Capability = "dialog.open_file"
	CapabilitySaveFileDialog     Capability = "dialog.save_file"
	CapabilityClipboardReadText  Capability = "clipboard.read_text"
	CapabilityClipboardWriteText Capability = "clipboard.write_text"
	CapabilityNotification       Capability = "notification.show"
	CapabilityOpenExternalURL    Capability = "url.open_external"
	CapabilityRevealFile         Capability = "file.reveal"
	CapabilityDeepLinks          Capability = "deep_link.receive"
)

type CapabilitySet

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

CapabilitySet reports the capabilities offered by a shell bridge.

func NewCapabilitySet

func NewCapabilitySet(capabilities ...Capability) CapabilitySet

NewCapabilitySet constructs a set from the provided capabilities.

func (CapabilitySet) Clone

func (s CapabilitySet) Clone() CapabilitySet

Clone returns a deep copy of the set.

func (CapabilitySet) Has

func (s CapabilitySet) Has(capability Capability) bool

Has reports whether the capability is present.

func (CapabilitySet) Map

func (s CapabilitySet) Map() map[string]bool

Map returns the capability manifest as a bool map suitable for bootstrap payloads.

func (CapabilitySet) Merge

func (s CapabilitySet) Merge(other CapabilitySet) CapabilitySet

Merge returns a new set containing both sets' capabilities.

func (CapabilitySet) Strings

func (s CapabilitySet) Strings() []string

Strings returns the capability names in deterministic order.

type ClipboardTextResult

type ClipboardTextResult struct {
	Text string `json:"text,omitempty"`
}

ClipboardTextResult returns text read from the system clipboard.

type Command

type Command struct {
	Kind    CommandKind     `json:"kind"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Command is a serialized shell command envelope.

func OpenExternalURL

func OpenExternalURL(url string) Command

OpenExternalURL builds an external URL command.

func RevealFile

func RevealFile(path string) Command

RevealFile builds a Finder reveal command.

func SetMenu

func SetMenu(menu Menu) Command

SetMenu builds a menu definition command.

func SetWindowDefaultSize

func SetWindowDefaultSize(size Size) Command

SetWindowDefaultSize builds a default window size command.

func SetWindowMinimumSize

func SetWindowMinimumSize(size Size) Command

SetWindowMinimumSize builds a minimum window size command.

func SetWindowTitle

func SetWindowTitle(title string) Command

SetWindowTitle builds a window title command.

func ShowNotification

func ShowNotification(notification Notification) Command

ShowNotification builds a notification command.

func WriteClipboardText

func WriteClipboardText(text string) Command

WriteClipboardText builds a clipboard write command.

type CommandKind

type CommandKind string

CommandKind identifies a fire-and-forget shell command.

const (
	CommandSetWindowTitle       CommandKind = "window.set_title"
	CommandSetWindowDefaultSize CommandKind = "window.set_default_size"
	CommandSetWindowMinimumSize CommandKind = "window.set_minimum_size"
	CommandSetMenu              CommandKind = "app.set_menu"
	CommandShowNotification     CommandKind = "notification.show"
	CommandWriteClipboardText   CommandKind = "clipboard.write_text"
	CommandOpenExternalURL      CommandKind = "url.open_external"
	CommandRevealFile           CommandKind = "file.reveal"
)
type DeepLink struct {
	URL  string `json:"url"`
	Path string `json:"path,omitempty"`
}

DeepLink reports that the app was opened via a native deep link.

type Event

type Event struct {
	Kind     EventKind   `json:"kind"`
	WindowID string      `json:"windowID,omitempty"`
	Menu     *MenuEvent  `json:"menu,omitempty"`
	DeepLink *DeepLink   `json:"deepLink,omitempty"`
	Files    *FilesEvent `json:"files,omitempty"`
}

Event is delivered from the native host back into Vango app code.

func DeepLinkOpened

func DeepLinkOpened(windowID, rawURL, path string) Event

DeepLinkOpened builds a deep-link event.

func EventFromRelay

func EventFromRelay(msg RelayMessage) (Event, error)

EventFromRelay converts an event relay message into a normalized shell event.

func FilesOpened

func FilesOpened(windowID string, paths []string) Event

FilesOpened builds a file-open event.

func MenuItemSelected(windowID, itemID string) Event

MenuItemSelected builds a menu selection event.

type EventKind

type EventKind string

EventKind identifies a host-originated shell event.

const (
	EventMenuItemSelected EventKind = "menu.item_selected"
	EventDeepLinkOpened   EventKind = "deep_link.opened"
	EventFilesOpened      EventKind = "files.opened"
)

type EventStream

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

EventStream delivers host-originated shell events to subscribers in order.

func NewEventStream

func NewEventStream(capacity int) *EventStream

NewEventStream constructs an event stream with a bounded replay buffer.

func (*EventStream) Publish

func (s *EventStream) Publish(event Event)

Publish records and broadcasts an event.

func (*EventStream) Subscribe

func (s *EventStream) Subscribe(handler func(Event)) (unsubscribe func())

Subscribe registers a handler and replays the recent buffered events in order.

type FileDialogOptions

type FileDialogOptions struct {
	Title             string   `json:"title,omitempty"`
	Prompt            string   `json:"prompt,omitempty"`
	DefaultPath       string   `json:"defaultPath,omitempty"`
	SuggestedName     string   `json:"suggestedName,omitempty"`
	AllowedFileTypes  []string `json:"allowedFileTypes,omitempty"`
	AllowsMultiple    bool     `json:"allowsMultiple,omitempty"`
	AllowsDirectories bool     `json:"allowsDirectories,omitempty"`
	AllowsFiles       bool     `json:"allowsFiles,omitempty"`
	CreateDirectories bool     `json:"createDirectories,omitempty"`
}

FileDialogOptions configures open/save panels.

type FileDialogResult

type FileDialogResult struct {
	Paths []string `json:"paths,omitempty"`
}

FileDialogResult contains file paths chosen by the user.

type FilesEvent

type FilesEvent struct {
	Paths []string `json:"paths,omitempty"`
}

FilesEvent reports that one or more local files were opened via the host shell.

type Menu struct {
	Sections []MenuSection `json:"sections,omitempty"`
}

Menu describes the native application menu.

type MenuEvent struct {
	ID string `json:"id"`
}

MenuEvent reports that a native menu item was selected.

type MenuItem struct {
	ID       string `json:"id"`
	Title    string `json:"title"`
	Shortcut string `json:"shortcut,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
	Checked  bool   `json:"checked,omitempty"`
}

MenuItem describes a single native menu item.

type MenuSection struct {
	Title string     `json:"title,omitempty"`
	Items []MenuItem `json:"items,omitempty"`
}

MenuSection groups menu items under a visible title.

type Notification

type Notification struct {
	Title      string `json:"title"`
	Subtitle   string `json:"subtitle,omitempty"`
	Body       string `json:"body,omitempty"`
	Identifier string `json:"identifier,omitempty"`
}

Notification describes a user-visible native notification.

type RelayError

type RelayError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

RelayError describes a typed relay failure.

func (*RelayError) Error

func (e *RelayError) Error() string

type RelayMessage

type RelayMessage struct {
	ID       string           `json:"id,omitempty"`
	Kind     RelayMessageKind `json:"kind,omitempty"`
	WindowID string           `json:"windowID,omitempty"`
	Name     string           `json:"name,omitempty"`
	Payload  json.RawMessage  `json:"payload,omitempty"`
	Error    *RelayError      `json:"error,omitempty"`
}

RelayMessage is the topology-neutral shell RPC envelope used by hosted shells.

func RelayEvent

func RelayEvent(windowID string, event Event) (RelayMessage, error)

RelayEvent builds a host-originated event relay message.

func RelayFromCommand

func RelayFromCommand(id, windowID string, cmd Command) RelayMessage

RelayFromCommand converts a fire-and-forget shell command into a relay message.

func RelayFromRequest

func RelayFromRequest(id, windowID string, req Request) RelayMessage

RelayFromRequest converts a blocking shell request into a relay message.

func RelayResponse

func RelayResponse(id, windowID, name string, payload json.RawMessage, err *RelayError) RelayMessage

RelayResponse builds a response relay message for the given id/name.

func (RelayMessage) Clone

func (m RelayMessage) Clone() RelayMessage

Clone returns a deep copy of the relay message.

func (RelayMessage) DecodePayload

func (m RelayMessage) DecodePayload(dst any) error

DecodePayload decodes the message payload into dst.

type RelayMessageKind

type RelayMessageKind string

RelayMessageKind identifies the direction and semantics of a shell relay message.

const (
	RelayMessageCommand  RelayMessageKind = "command"
	RelayMessageRequest  RelayMessageKind = "request"
	RelayMessageResponse RelayMessageKind = "response"
	RelayMessageEvent    RelayMessageKind = "event"
)

type RelayReceiver

type RelayReceiver interface {
	HandleRelayMessage(RelayMessage) error
}

RelayReceiver consumes relay responses and host-originated shell events.

type Request

type Request struct {
	Kind    RequestKind     `json:"kind"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Request is a serialized shell request envelope.

func OpenFileDialog

func OpenFileDialog(options FileDialogOptions) Request

OpenFileDialog builds a file open request.

func ReadClipboardText

func ReadClipboardText() Request

ReadClipboardText builds a clipboard read request.

func SaveFileDialog

func SaveFileDialog(options FileDialogOptions) Request

SaveFileDialog builds a file save request.

type RequestKind

type RequestKind string

RequestKind identifies a blocking or user-mediated shell request.

const (
	RequestOpenFileDialog RequestKind = "dialog.open_file"
	RequestSaveFileDialog RequestKind = "dialog.save_file"
	RequestReadClipboard  RequestKind = "clipboard.read_text"
)

type Response

type Response struct {
	Kind    RequestKind     `json:"kind"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Response is a serialized shell response envelope.

func (Response) DecodeClipboardTextResult

func (r Response) DecodeClipboardTextResult() (ClipboardTextResult, error)

DecodeClipboardTextResult decodes a clipboard-read response payload.

func (Response) DecodeFileDialogResult

func (r Response) DecodeFileDialogResult() (FileDialogResult, error)

DecodeFileDialogResult decodes a file-dialog response payload.

func (Response) DecodeJSON

func (r Response) DecodeJSON(dst any) error

DecodeJSON decodes a shell response into the provided destination.

type Size

type Size struct {
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

Size describes a shell-controlled window size in device-independent points.

type UnsupportedError

type UnsupportedError struct {
	Operation string
}

UnsupportedError reports that a shell bridge or capability is unavailable.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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