✨ Added settings window
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// SetupSystemTray 设置系统托盘及其功能
|
||||
func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow, assets embed.FS) {
|
||||
func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow, settingsWindow *application.WebviewWindow, assets embed.FS) {
|
||||
// 创建系统托盘
|
||||
systray := app.NewSystemTray()
|
||||
|
||||
@@ -22,9 +22,12 @@ func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow
|
||||
|
||||
// 创建托盘菜单
|
||||
menu := app.NewMenu()
|
||||
menu.Add("显示主窗口").OnClick(func(data *application.Context) {
|
||||
menu.Add("主窗口").OnClick(func(data *application.Context) {
|
||||
mainWindow.Show()
|
||||
})
|
||||
menu.Add("设置").OnClick(func(data *application.Context) {
|
||||
settingsWindow.Show()
|
||||
})
|
||||
menu.AddSeparator()
|
||||
menu.Add("退出").OnClick(func(data *application.Context) {
|
||||
app.Quit()
|
||||
@@ -51,4 +54,16 @@ func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow
|
||||
mainWindow.Hide()
|
||||
})
|
||||
|
||||
// 设置窗口关闭事件处理
|
||||
settingsWindow.RegisterHook(events.Common.WindowClosing, func(event *application.WindowEvent) {
|
||||
// 取消默认关闭行为
|
||||
event.Cancel()
|
||||
// 隐藏窗口
|
||||
settingsWindow.Hide()
|
||||
})
|
||||
|
||||
// 注册事件监听器,用于处理前端发送的显示设置窗口事件
|
||||
app.OnEvent("show_settings_window", func(event *application.CustomEvent) {
|
||||
settingsWindow.Show()
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user