nativeui

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 2 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 nativeui is the interface of the desktop app's native windows: the types internal/desktop programs against, and the registration through which internal/webview provides them. Only the desktop app's binary (cmd/remohop-quick) links internal/webview; in any other binary (the static remohop command line tool) nothing is registered, Probe reports ErrUnavailable and the app falls back to a browser window.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("webview: no native web view on this system")

ErrUnavailable means this system has no usable native web view: no WebView2 runtime on Windows, no WebKitGTK library on Linux, an unknown platform. Callers fall back to a browser window.

Functions

func FitArea

func FitArea(w, h, minW, minH, areaW, areaH int) (int, int, int, int)

FitArea shrinks a window's size, and its minimum size, to fit a work area of areaW x areaH (the screen minus task bar, Dock or panels, in the same units). A window takes at most 92% of the area, so its edges stay clear of them; the minimum never exceeds the area. A zero area (unknown) leaves everything as it is. The overlay banner does not use it: it has its own fixed size.

func Register

func Register(probe func() (Info, error), run func(Config, func(App)) error)

Register installs the native implementation (internal/webview does, from init).

func Run

func Run(cfg Config, setup func(App)) error

Run starts the native application, calls setup on the UI thread and runs the event loop until App.Quit. It must be called from the main goroutine. If the system has no native web view it returns an error wrapping ErrUnavailable without calling setup.

Types

type App

type App interface {
	// NewWindow opens a window showing o.URL.
	NewWindow(o Options) (Window, error)
	// Dispatch runs fn on the UI thread. It may be called from any
	// goroutine, and returns at once.
	Dispatch(fn func())
	// SetTray shows (or with nil removes) the tray icon. It fails where
	// the system has no tray (a Linux desktop without AppIndicator
	// support): callers must then not hide their last window.
	SetTray(t *Tray) error
	// Quit ends Run.
	Quit()
}

App is the running native application.

type Config

type Config struct {
	// AppID names the program to the windowing system: the Linux
	// application name that .desktop files match (WM_CLASS) and the
	// AppIndicator ID.
	AppID string
	// DataDir is where the web engine keeps its profile (cache, local
	// storage). WebView2 needs one it can write; the others ignore it.
	DataDir string
	// IconPNG is the tray icon on Linux and macOS (macOS draws it as a
	// template image: only its alpha channel counts).
	IconPNG []byte
	// TemplatePNG, if set, is the macOS tray icon instead of IconPNG.
	TemplatePNG []byte
	// OnReopen runs when the user asks for the program again while it
	// runs without a visible window (macOS: a click on its Dock icon).
	OnReopen func()
	// OnQuitRequest, if set, runs when the system asks the program to
	// quit (macOS: Quit in the menu or the Dock) instead of quitting; the
	// program calls App.Quit when it is ready.
	OnQuitRequest func()
}

Config configures Run.

type Info

type Info struct {
	// Engine is "WebView2", "WKWebView" or "WebKitGTK".
	Engine string
	// Version is the engine's version where the system says.
	Version string
}

Info describes the native web view of this system.

func Probe

func Probe() (Info, error)

Probe reports whether Run can show native windows here, without creating any. ErrUnavailable (possibly wrapped) means it cannot.

type MenuItem struct {
	Label    string
	Disabled bool
	OnClick  func()
}

MenuItem is a tray menu entry; a zero Label is a separator.

type Notifier

type Notifier interface {
	Notify(title, text string)
}

Notifier is an App that can also show a notification from its tray icon (a balloon or toast on Windows), for when its window may not be seen: hidden in the tray, or behind other windows because the system does not let a background program come to the front.

type Options

type Options struct {
	Title  string
	URL    string
	Width  int // logical pixels; 0 means 960
	Height int // 0 means 680
	// MinWidth and MinHeight bound resizing (0: no bound).
	MinWidth, MinHeight int
	// OnClose runs when the user asks to close the window. Returning false
	// keeps it open (the caller may hide it instead); true closes it.
	// Nil closes it.
	OnClose func() bool
	// Hidden creates the window without showing it.
	Hidden bool
	// Overlay makes a small undecorated window that stays above the
	// others and out of the task bar, in the bottom-right corner of the
	// work area (where notifications appear, clear of the app's own
	// window and tab bar): the "this computer is being controlled" banner.
	Overlay bool
}

Options configure a window.

func (*Options) Size

func (o *Options) Size() (w, h int)

Size is the window size o asks for, with defaults.

type Tray

type Tray struct {
	Tooltip string
	// OnActivate runs on a click on the icon itself, where the platform
	// tells a click from opening the menu (Windows; on macOS and Linux
	// the menu opens).
	OnActivate func()
	Menu       []MenuItem
}

Tray is a status-area icon with a menu.

type Window

type Window interface {
	Navigate(url string)
	SetTitle(title string)
	// Show shows the window and brings it to the front.
	Show()
	Hide()
	// Close closes the window for good.
	Close()
}

Window is a native window with a web view.

Jump to

Keyboard shortcuts

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