类型 Application

API 文档由 Go 源码生成,内容为英文。

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

Application owns the native event loop and all windows created in one RunApplication call. OpenWindow must be called from the startup callback or a window callback, both of which run on the native event-loop thread.

方法

AddStatusItem#

func (application *Application) AddStatusItem(config StatusItemConfig) (*StatusItem, error)

AddStatusItem puts an icon in the system's status area. It is called from the startup callback or a window callback, like OpenWindow.

OnOpenURL#

func (application *Application) OnOpenURL(handler func(url string))

OnOpenURL sets who receives a link the system opens the application with: one whose scheme the application registered (viva.toml url_schemes). It is called on the event-loop thread, also for links that arrived while the application was starting. Call it from the startup callback.

macOS delivers such links to the running program. Windows and Linux start a program with the link as an argument instead; package app/singleinstance carries it to the running copy, and the program reads it from its arguments at launch. Where the system delivers nothing, the handler is never called.

OnQuitRequest#

func (application *Application) OnQuitRequest(handler func(allow func()))

OnQuitRequest lets an application confirm a system Quit action before it closes document windows. Call it on the application thread during startup. The callback may retain allow while presenting unsaved-content confirmation. It currently receives macOS menu/Dock Quit requests. Application.Quit remains the explicit force-quit path and never asks for confirmation a second time.

OpenContentWindow#

func (application *Application) OpenContentWindow(config Config, canvas *ui.Canvas) (*ContentWindow, error)

OpenContentWindow opens a resizable system window. Call it on the application thread, like OpenWindow. The helper owns Invalidator and drains Post updates before the supplied OnWake. Background workers never touch UI state directly.

OpenWindow#

func (application *Application) OpenWindow(config Config, canvas *ui.Canvas) (*Window, error)

OpenWindow creates and presents one independent retained window.

Quit#

func (application *Application) Quit()

Quit closes every window, whatever their close requests say, and ends RunApplication once their resources are released. It may be called from any goroutine.