jumplist
import "github.com/tangoui/tango/sys/jumplist"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package jumplist sets the app's shortcut menu: the menu of the Dock icon on macOS and the "Tasks" of the taskbar Jump List on Windows.
jumplist.OnClick(a, func(id string) {
switch id {
case "new": newWindow()
case "sync": syncNow()
}
})
err := jumplist.Set(a, []jumplist.Item{
{ID: "new", Label: "New Window"},
jumplist.Separator(),
{ID: "sync", Label: "Sync Now", Description: "Fetch new mail"},
})
How clicks arrive differs, and OnClick hides it:
- macOS: the Dock menu is part of the running app; a click calls the handlers directly. The items appear above the system's own (Open Recent, Options, Quit).
- Windows: a task is a shortcut that starts the executable again with the argument "--tango-shortcut=<id>". With sys/single the new process forwards it to the running instance, whose handlers run; without it the new process sees its own argument and its handlers run once it is ready. The list is kept by the shell across runs and is tied to the app's AppUserModelID (the app's ID option).
- Linux has no runtime API: shortcuts are Desktop Actions in the app's .desktop file, written when the app is packaged (tan package reads them from the project; each action's Exec line passes "--tango-shortcut=<id>"). Set returns ErrUnsupported; OnClick still works for launches through those actions.
Set and Clear are safe from any goroutine once the app runs; OnClick may be called before Run. Handlers run on the main thread.
变量
var ErrBadItem = errors.New("tango/jumplist: bad item")ErrBadItem is returned by Set for an item without an ID or label, a duplicate ID, or an ID that cannot travel on a command line.
var ErrUnsupported = platform.ErrUnsupportedErrUnsupported is platform.ErrUnsupported.
函数
func Arg
func Arg(id string) stringArg is the command-line argument a Windows task (or a Linux Desktop Action) passes to start the shortcut id.
func Clear
func Clear(a *tango.App) errorClear removes the shortcut menu.
func IDFromArgs
func IDFromArgs(args []string) (string, bool)IDFromArgs returns the shortcut id among command-line arguments, if any.
func OnClick
func OnClick(a *tango.App, fn func(id string))OnClick registers fn for chosen shortcuts, on every platform: Dock menu clicks on macOS, and launches carrying "--tango-shortcut=<id>" (Windows tasks, Linux Desktop Actions) — this process's own launch arguments once, and later launches forwarded by sys/single.
func Set
func Set(a *tango.App, items []Item) errorSet replaces the shortcut menu with items; nil or empty clears it.
类型
Item
type Item struct {
ID string // reported to OnClick; letters, digits and "-_.:" only
Label string
Description string // Windows tooltip
Icon string // Windows: icon resource path, optionally ",index"; empty = the app's icon
Disabled bool // macOS only
Separator bool
}Item is one entry of the shortcut menu.
func Separator
func Separator() ItemSeparator returns a separator item.