Skip to content

appctl ​

go
import "github.com/tangoui/tango/sys/appctl"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package appctl controls the app as a whole in the window manager: hide and show all its windows, the dock / taskbar badge and progress bar, bouncing the dock icon or flashing the taskbar button, and the dock icon itself (tray-only apps).

appctl.SetBadge(app, "3")      // "" clears
appctl.SetProgress(app, 0.5)   // negative hides
appctl.RequestAttention(app, false)

Support by platform:

                  macOS   Windows                    Linux
Hide / Show       yes     yes (all windows)          yes (all windows)
SetBadge          yes     digits, as overlay icon    digits, Unity launcher API (Ubuntu Dock, KDE)
SetProgress       yes     yes (taskbar)              Unity launcher API
RequestAttention  yes     yes (FlashWindowEx)        yes (urgency hint)
SetDockVisible    yes     no                         no

Functions are safe from any goroutine once the app runs. They return ErrUnsupported when the platform cannot do it (Supports tells beforehand), and tango.ErrNotRunning after the app quit. The badge and progress also appear on windows created after they were set.

常量 ​

go
const (
	CtlHide      = platform.CtlHide      // Hide, Show
	CtlBadge     = platform.CtlBadge     // SetBadge with counts
	CtlBadgeText = platform.CtlBadgeText // SetBadge with any text
	CtlProgress  = platform.CtlProgress  // SetProgress
	CtlAttention = platform.CtlAttention // RequestAttention
	CtlDock      = platform.CtlDock      // SetDockVisible
)

Operations, for Supports.

变量 ​

go
var ErrUnsupported = platform.ErrUnsupported

ErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.

函数 ​

func Hide ​

go
func Hide(a *tango.App) error

Hide hides all of the app's windows (Cmd+H on macOS).

func RequestAttention ​

go
func RequestAttention(a *tango.App, critical bool) error

RequestAttention bounces the dock icon or flashes the taskbar button until the user activates the app. critical keeps it going on macOS (informational requests bounce once).

func SetBadge ​

go
func SetBadge(a *tango.App, text string) error

SetBadge shows text on the dock icon / taskbar button; "" clears it. Windows and Linux only show numbers: other text returns ErrUnsupported there (and clears the badge).

func SetDockVisible ​

go
func SetDockVisible(a *tango.App, visible bool) error

SetDockVisible shows or hides the app's dock icon (macOS). Without it the app has no menu bar either and lives in a tray icon.

func SetProgress ​

go
func SetProgress(a *tango.App, p float64) error

SetProgress shows a progress bar in [0, 1] on the dock icon / taskbar button; values above 1 are clamped, a negative value hides it.

func Show ​

go
func Show(a *tango.App) error

Show shows the windows Hide hid and brings the app to the front.

func Supports ​

go
func Supports(a *tango.App, op platform.AppControlOp) bool

Supports reports whether the platform performs every operation in op.

以 MIT 许可发布