hostui

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 35 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostui provides the desktop system tray, pairing window and permission guide for a standalone Host process.

Index

Constants

View Source
const MinimumFontSize float32 = 14

MinimumFontSize is the floor for every text element in Host desktop windows.

Variables

View Source
var SupportedLanguages = []string{"en", "zh-CN", "zh-TW", "ja", "ko", "fr", "de", "es", "pt-BR", "ru"}

SupportedLanguages lists all 10 locales shipped for standalone Host tray and windows.

Functions

func AppRevealTarget

func AppRevealTarget(executable string) string

AppRevealTarget returns the enclosing .app bundle on macOS when present, or the executable itself.

func Available

func Available(goos string, getenv func(string) string) bool

Available reports whether the current OS and environment have a desktop GUI session where a system tray can be presented.

func BindLocale

func BindLocale(c *ui.Context)

BindLocale attaches the Host UI catalog to a window frame.

func BuildMenu

func BuildMenu(state MenuState) *mygo.Menu

BuildMenu wraps BuildMenuItems into a native *mygo.Menu.

func BuildMenuItems

func BuildMenuItems(state MenuState) []*mygo.MenuItem

BuildMenuItems constructs the right-click context menu items for the standalone Host tray.

func DisplayName

func DisplayName(product identity.Desktop) string

DisplayName derives the standalone Host display name from the product identity.

func FormatPeerLatency

func FormatPeerLatency(lang string, online bool, rttMS *uint64) string

FormatPeerLatency formats a peer's live RTT in milliseconds or an em-dash placeholder.

func FormatPeerProtocol

func FormatPeerProtocol(lang string, online bool, route string) string

FormatPeerProtocol formats a peer's live route for display.

func RenderPermissionGuide

func RenderPermissionGuide(c *ui.Context, m *PermissionGuideModel)

RenderPermissionGuide draws the Permission Guide Window using >=14px typography, multi-tone vector illustrations, solid borders, and semantic theme tokens.

func RenderShareWindow

func RenderShareWindow(c *ui.Context, m *ShareWindowModel)

RenderShareWindow draws the Share Window using >=14px typography, solid borders, multi-tone vector illustrations, node selection cards, and 32px PIN digit tiles.

func Run

func Run(ctx context.Context, cfg Options) error

Run starts the standalone Host system tray, Share Window, and automatic Permission Guide Window on the main goroutine, blocking until ctx cancels or the user chooses Quit from the tray menu.

func Supported

func Supported(goos string, getenv func(string) string) bool

Supported reports whether an explicit --tray launch is supported in this environment.

func Text

func Text(c *ui.Context, key string, args ...any) string

Text resolves a localized string inside a window frame.

func TextIn

func TextIn(lang, key string, args ...any) string

TextIn resolves a localized string for a BCP 47 language tag.

func TrayIconPNG

func TrayIconPNG(product identity.Desktop, goos string) ([]byte, bool, error)

TrayIconPNG renders a crisp native tray icon PNG and reports whether macOS should treat it as a monochrome menu-bar template image.

Types

type Autostart

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

Autostart inspects and toggles OS login startup for the standalone Host.

func NewAutostart

func NewAutostart(cfg AutostartConfig) *Autostart

NewAutostart constructs an Autostart manager using OS defaults for omitted fields.

func (*Autostart) Enabled

func (a *Autostart) Enabled() bool

Enabled reports whether standalone Host launch-at-login (or an active managed user Host service from service.sh) is enabled.

func (*Autostart) SetEnabled

func (a *Autostart) SetEnabled(enable bool) error

SetEnabled enables or disables login startup for the standalone Host.

type AutostartConfig

type AutostartConfig struct {
	GOOS            string
	HomeDir         string
	ConfigHome      string
	Executable      string
	Profile         string
	ExplicitProfile bool
	Product         identity.Desktop
	WindowsRun      WindowsRunStore
}

AutostartConfig configures login autostart management for a standalone Host.

type MenuState struct {
	Language           string
	AppName            string
	Peers              []PeerStatus
	AutostartEnabled   bool
	ShowPermissions    bool
	PermissionsReady   int
	PermissionsTotal   int
	OnShare            func()
	OnPermissions      func()
	OnToggleAutostart  func(next bool)
	OnRemovePeer       func(id protocol.NodeID)
	OnQuit             func()
	IncludeStatusIcons bool
}

MenuState describes the data and callbacks used to build the Host tray context menu.

type Options

type Options struct {
	Identity        identity.Desktop
	Profile         string
	ExplicitProfile bool
	Node            *node.Node
	PairingOrigin   string
}

Options configures the standalone Host desktop tray and companion windows.

type PeerMonitor

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

PeerMonitor tracks paired peers, live connection routes/RTTs, and host removal.

func NewPeerMonitor

func NewPeerMonitor(parent context.Context, endpoint *link.Link, controller *client.Client, onChange func()) *PeerMonitor

NewPeerMonitor starts watching paired peers and their live connections.

func (*PeerMonitor) Close

func (m *PeerMonitor) Close()

Close stops all background peer watches and waits for workers to exit.

func (*PeerMonitor) Refresh

func (m *PeerMonitor) Refresh()

Refresh triggers an immediate peer discovery pass.

func (*PeerMonitor) RemovePeer

func (m *PeerMonitor) RemovePeer(id protocol.NodeID, done func(error))

RemovePeer revokes trust and disconnects a paired peer using client.RemoveHost and the durable revoke_device identity command.

func (*PeerMonitor) Snapshot

func (m *PeerMonitor) Snapshot() []PeerStatus

Snapshot returns the sorted list of currently paired peers.

type PeerStatus

type PeerStatus struct {
	ID      protocol.NodeID
	Address link.EndpointAddress
	Name    string
	Online  bool
	// Route is "lan", "p2p", "relay", or "" when disconnected.
	Route string
	RTTMS *uint64
}

PeerStatus describes one paired peer shown in the Host tray menu.

type PermissionController

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

PermissionController manages live permission checks, polling, and the native guide window.

func NewPermissionController

func NewPermissionController(ctx context.Context, appName string, probe PermissionProbe, onChange func(ready, total int), onVisibility func()) *PermissionController

NewPermissionController constructs a PermissionController for standalone Host.

func (*PermissionController) Counts

func (pc *PermissionController) Counts() (int, int)

Counts returns the latest (ready, total) permission counts.

func (*PermissionController) Destroy

func (pc *PermissionController) Destroy()

Destroy closes the Permission Guide Window during Host shutdown.

func (*PermissionController) Hide

func (pc *PermissionController) Hide()

Hide hides the Permission Guide Window and pauses background polling.

func (*PermissionController) IsVisible

func (pc *PermissionController) IsVisible() bool

IsVisible reports whether the Permission Guide Window is currently open and visible.

func (*PermissionController) Refresh

func (pc *PermissionController) Refresh() (int, int)

Refresh checks all permissions off the UI thread and returns (ready, total).

func (*PermissionController) Show

func (pc *PermissionController) Show(lang string)

Show opens or raises the Permission Guide Window on the main UI thread.

func (*PermissionController) Supported

func (pc *PermissionController) Supported() bool

Supported reports whether permission checks apply on the current platform.

type PermissionGuideModel

type PermissionGuideModel struct {
	AppName     string
	Items       []PermissionItem
	Checking    bool
	OnAuthorize func(permissionflow.Permission)
	OnRevealApp func()
	OnRecheck   func()
	OnClose     func()
}

PermissionGuideModel holds the renderable state and actions of the Permission Guide Window.

func (*PermissionGuideModel) AllGranted

func (m *PermissionGuideModel) AllGranted() bool

AllGranted reports whether every required permission is granted.

func (*PermissionGuideModel) Counts

func (m *PermissionGuideModel) Counts() (ready, total int)

Counts returns how many permissions are granted and the total count.

type PermissionItem

type PermissionItem struct {
	Permission permissionflow.Permission
	TitleKey   string
	DescKey    string
	Graphic    *ui.SVG
	Granted    bool
	Busy       bool
}

PermissionItem represents one required Host execution permission in the guide UI.

func DefaultPermissionItems

func DefaultPermissionItems() []PermissionItem

DefaultPermissionItems returns the 3 core macOS permissions required by standalone Host.

type PermissionProbe

type PermissionProbe struct {
	GOOS       string
	Executable string
	Check      func(permissionflow.Permission) (permissionflow.Status, error)
	Authorize  func(context.Context, permissionflow.Permission) (permissionflow.Status, error)
	Settings   func(permissionflow.Permission) error
	RevealApp  func(path string) error
}

PermissionProbe abstracts OS permission checks and settings guidance.

func SystemPermissionProbe

func SystemPermissionProbe() PermissionProbe

SystemPermissionProbe returns the live desktop OS permission probe.

func (PermissionProbe) Supported

func (p PermissionProbe) Supported() bool

Supported reports whether this OS uses desktop privacy grants for Host execution.

type ShareController

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

ShareController manages network route selection, live ShareForRole sessions, and the native Share Window.

func NewShareController

func NewShareController(ctx context.Context, appName string, endpoint *link.Link, controller *client.Client, pairingOrigin string, onPaired func(), onVisibility func()) *ShareController

NewShareController constructs a ShareController for standalone Host.

func (*ShareController) Destroy

func (sc *ShareController) Destroy()

Destroy closes the Share Window during Host shutdown.

func (*ShareController) Hide

func (sc *ShareController) Hide()

Hide hides the Share Window and cancels its active pairing session.

func (*ShareController) IsVisible

func (sc *ShareController) IsVisible() bool

IsVisible reports whether the Share Window is currently open and visible.

func (*ShareController) Show

func (sc *ShareController) Show(lang string)

Show opens or raises the Share Window and starts a live executor pairing session.

type ShareNodeOption

type ShareNodeOption struct {
	ID        string
	Title     string
	TitleKey  string
	DescKey   string
	Locales   map[string]string
	Selection *protocol.NetworkSelection
	LatencyMS *uint64
	Probing   bool
	Custom    bool
}

ShareNodeOption describes one selectable network/relay route in the Share Window.

type ShareWindowModel

type ShareWindowModel struct {
	AppName          string
	LoopbackOnly     bool
	NodeSwitching    bool
	SelectedNodeID   string
	Nodes            []ShareNodeOption
	CustomAddress    string
	CustomError      string
	StateKind        string // "preparing", "retrying", "ready", "paired", "failed"
	Code             string
	RemainingSeconds int
	TotalSeconds     int
	Copied           bool
	OnSelectNode     func(id string)
	OnChangeCustom   func(address string)
	OnApplyCustom    func(address string)
	OnCopyCode       func()
	OnRefreshCode    func()
}

ShareWindowModel holds the renderable state and callbacks of the Share Window.

type WindowsRunStore

type WindowsRunStore interface {
	Get(name string) (string, bool, error)
	Set(name, value string) error
	Delete(name string) error
}

WindowsRunStore abstracts HKCU\Software\Microsoft\Windows\CurrentVersion\Run so Windows autostart logic can be unit-tested on every OS.

Jump to

Keyboard shortcuts

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