- 托盘:用 getlantern/systray 重写 internal/tray,支持显示/隐藏窗口与退出 - 图标:新增 pkg/icongen 工具,支持 png/jpg/gif/bmp/webp,输出 ico/png 多个尺寸 - 重命名:项目默认名改为「青梧映星」,wails.json/productname/companyname/copyright 同步更新 - 顶栏:新增顶部导航栏(主题切换、设置、用户),iconfont 自托管 fa-solid-900.woff2 - 主题:CSS 变量 + html[data-theme] 控制白昼/黑夜切换,同时调用 WindowSetDarkTheme/LightTheme - 底部:版权栏包含工作室、开发者与点击跳转客服链接 - 打包:wails build + exe 版本更新至 1.20 MB
104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package main
|
||
|
||
import (
|
||
"context"
|
||
"embed"
|
||
"log"
|
||
"sync/atomic"
|
||
|
||
"github.com/wailsapp/wails/v2"
|
||
"github.com/wailsapp/wails/v2/pkg/options"
|
||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||
"github.com/wailsapp/wails/v2/pkg/options/windows"
|
||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||
|
||
"go_win_template/internal/plugins"
|
||
"go_win_template/internal/tray"
|
||
)
|
||
|
||
//go:embed all:frontend/dist
|
||
//go:embed assets/icon.png
|
||
//go:embed build/windows/icon.ico
|
||
var assets embed.FS
|
||
|
||
var (
|
||
trayMgr *tray.Manager
|
||
forceQuit atomic.Bool
|
||
)
|
||
|
||
func main() {
|
||
wailsApp := NewApp()
|
||
|
||
cfg := &options.App{
|
||
Title: "青梧映星",
|
||
Width: 1280,
|
||
Height: 800,
|
||
MinWidth: 1024,
|
||
MinHeight: 600,
|
||
WindowStartState: options.Normal,
|
||
AssetServer: &assetserver.Options{
|
||
Assets: assets,
|
||
},
|
||
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
|
||
Windows: &windows.Options{
|
||
// 窗口标题栏跟随系统白昼/黑夜主题
|
||
Theme: windows.SystemDefault,
|
||
},
|
||
OnStartup: func(ctx context.Context) {
|
||
log.Println("[main] startup complete")
|
||
// 启动插件
|
||
if err := plugins.Start(ctx); err != nil {
|
||
log.Printf("[main] plugin start error: %v", err)
|
||
}
|
||
plugins.PrintStatus()
|
||
// 启动系统托盘
|
||
startTray(ctx)
|
||
},
|
||
OnBeforeClose: func(ctx context.Context) bool {
|
||
// 真正退出时不再拦截
|
||
if forceQuit.Load() {
|
||
return false
|
||
}
|
||
// 托盘可用时,关闭窗口改为隐藏到托盘
|
||
if trayMgr != nil && trayMgr.Active() {
|
||
runtime.WindowHide(ctx)
|
||
return true
|
||
}
|
||
return false
|
||
},
|
||
OnShutdown: func(context.Context) {
|
||
if trayMgr != nil {
|
||
trayMgr.Quit()
|
||
}
|
||
},
|
||
Bind: []interface{}{
|
||
wailsApp,
|
||
},
|
||
}
|
||
|
||
err := wails.Run(cfg)
|
||
if err != nil {
|
||
log.Fatal(err)
|
||
}
|
||
}
|
||
|
||
// startTray 初始化系统托盘。Windows 下托盘图标需为 .ico 格式,
|
||
// 使用 build/windows/icon.ico;macOS/Linux 可改用 .png。
|
||
func startTray(ctx context.Context) {
|
||
icon, err := assets.ReadFile("build/windows/icon.ico")
|
||
if err != nil {
|
||
log.Printf("[tray] load icon failed: %v", err)
|
||
return
|
||
}
|
||
|
||
trayMgr = tray.New(tray.Options{
|
||
Icon: icon,
|
||
Tooltip: "青梧映星",
|
||
OnQuit: func() {
|
||
forceQuit.Store(true)
|
||
runtime.Quit(ctx)
|
||
},
|
||
})
|
||
trayMgr.Run(ctx)
|
||
}
|