refactor(app): 调整系统托盘创建逻辑并更新应用配置

- 将系统托盘创建逻辑从 main.go 移动到 app.go 中的 startup 方法- 更新应用配置,添加生产环境日志级别配置
- 移除 main.go 中的冗余注释
This commit is contained in:
spark 2025-01-14 21:03:35 +08:00
parent 6483243d2a
commit 02bfe4758e
2 changed files with 31 additions and 30 deletions

8
app.go
View File

@ -39,6 +39,14 @@ func NewApp() *App {
func (a *App) startup(ctx context.Context) { func (a *App) startup(ctx context.Context) {
// Perform your setup here // Perform your setup here
a.ctx = ctx a.ctx = ctx
// 创建系统托盘
go systray.Run(func() {
onReady(a)
}, func() {
onExit(a)
})
} }
// domReady is called after front-end resources have been loaded // domReady is called after front-end resources have been loaded

View File

@ -4,7 +4,6 @@ import (
"embed" "embed"
"encoding/json" "encoding/json"
"github.com/duke-git/lancet/v2/convertor" "github.com/duke-git/lancet/v2/convertor"
"github.com/getlantern/systray"
"github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger" "github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/menu" "github.com/wailsapp/wails/v2/pkg/menu"
@ -84,13 +83,6 @@ func main() {
// runtime.Quit(app.ctx) // runtime.Quit(app.ctx)
//}) //})
// 创建系统托盘
go systray.Run(func() {
onReady(app)
}, func() {
onExit(app)
})
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{
Title: "go-stock", Title: "go-stock",
@ -110,6 +102,7 @@ func main() {
Menu: AppMenu, Menu: AppMenu,
Logger: nil, Logger: nil,
LogLevel: logger.DEBUG, LogLevel: logger.DEBUG,
LogLevelProduction: logger.ERROR,
OnStartup: app.startup, OnStartup: app.startup,
OnDomReady: app.domReady, OnDomReady: app.domReady,
OnBeforeClose: app.beforeClose, OnBeforeClose: app.beforeClose,