5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 06:30:14 +08:00
wails/mkdocs-website/docs/zh/API/systray.md
2023-11-05 18:06:11 +11:00

2.2 KiB
Raw Blame History

系统托盘

系统托盘位于桌面环境的通知区域,可以包含当前运行应用程序的图标和特定系统通知。

您可以通过调用 app.NewSystemTray() 来创建一个系统托盘:

    // 创建一个新的系统托盘
tray := app.NewSystemTray()

SystemTray 类型上提供了以下方法:

SetLabel

APISetLabel(label string)

SetLabel 方法设置托盘的标签。

Label

APILabel() string

Label 方法获取托盘的标签。

PositionWindow

APIPositionWindow(*WebviewWindow, offset int) error

PositionWindow 方法调用了 AttachWindowWindowOffset 方法。

SetIcon

APISetIcon(icon []byte) *SystemTray

SetIcon 方法设置系统托盘的图标。

SetDarkModeIcon

APISetDarkModeIcon(icon []byte) *SystemTray

SetDarkModeIcon 方法设置暗黑模式下系统托盘的图标。

SetMenu

APISetMenu(menu *Menu) *SystemTray

SetMenu 方法设置系统托盘的菜单。

Destroy

APIDestroy()

Destroy 方法销毁系统托盘实例。

OnClick

APIOnClick(handler func()) *SystemTray

OnClick 方法设置点击托盘图标时执行的函数。

OnRightClick

APIOnRightClick(handler func()) *SystemTray

OnRightClick 方法设置右键点击托盘图标时执行的函数。

OnDoubleClick

APIOnDoubleClick(handler func()) *SystemTray

OnDoubleClick 方法设置双击托盘图标时执行的函数。

OnRightDoubleClick

APIOnRightDoubleClick(handler func()) *SystemTray

OnRightDoubleClick 方法设置右键双击托盘图标时执行的函数。

AttachWindow

APIAttachWindow(window *WebviewWindow) *SystemTray

AttachWindow 方法将窗口附加到系统托盘。当点击系统托盘图标时,窗口将显示出来。

WindowOffset

APIWindowOffset(offset int) *SystemTray

WindowOffset 方法设置系统托盘与窗口之间的像素间隔。

WindowDebounce

APIWindowDebounce(debounce time.Duration) *SystemTray

WindowDebounce 方法设置防抖时间。在 Windows 上,它用于指定在响应通知图标上的鼠 标松开事件之前等待多长时间。

OpenMenu

APIOpenMenu()

OpenMenu 方法打开与系统托盘关联的菜单。