feat(app): 为 Windows 系统添加系统托盘功能并支持 Linux

- 在 app.go 中添加了对 Windows 操作系统的判断- 仅在 Windows 系统上创建系统托盘
- 更新 GitHub Actions 工作流,添加 Linux 平台的构建
This commit is contained in:
spark 2025-01-06 16:30:03 +08:00
parent 64270d5df2
commit 9a3393bfc3
2 changed files with 14 additions and 6 deletions

View File

@ -20,6 +20,9 @@ jobs:
- name: 'go-stock.exe' - name: 'go-stock.exe'
platform: 'windows/amd64' platform: 'windows/amd64'
os: 'windows-latest' os: 'windows-latest'
- name: 'go-stock'
platform: 'linux/amd64'
os: 'ubuntu-latest'
runs-on: ${{ matrix.build.os }} runs-on: ${{ matrix.build.os }}
steps: steps:

17
app.go
View File

@ -29,12 +29,16 @@ func (a *App) startup(ctx context.Context) {
// Perform your setup here // Perform your setup here
a.ctx = ctx a.ctx = ctx
// 创建系统托盘 //判断是否是windows操作系统
go systray.Run(func() { platform := runtime.Environment(ctx).Platform
onReady(a) if platform == "windows" {
}, func() { // 创建系统托盘
onExit(a) go systray.Run(func() {
}) onReady(a)
}, func() {
onExit(a)
})
}
} }
@ -132,6 +136,7 @@ func onExit(a *App) {
} }
func onReady(a *App) { func onReady(a *App) {
// 初始化操作 // 初始化操作
logger.SugaredLogger.Infof("onReady") logger.SugaredLogger.Infof("onReady")
systray.SetIcon(icon2) systray.SetIcon(icon2)