Files
sundynix-agentix/sundynix-desktop/app.go
T
Blizzard 7a4133773c feat(desktop): 真实 Wails 桌面应用可构建可运行
把 Wails 壳从编译不过的桩做成能启动的原生桌面应用。

- main.go: 真实 Wails v2 入口(import wails + assetserver + AssetServer 嵌入 dist +
  深色背景 #0b0d12 + OnStartup + Bind)
- app.go: App.startup 注入 ctx; ReadLocalFile 做真(os.ReadFile, 本地文件 I/O) + Ping 探活
- go.mod: GOWORK=off go mod tidy 拉全 wails v2.12 依赖树
- Makefile: desktop=GOWORK=off wails dev(原生窗口热重载); desktop-build=wails build(打包.app)
  — 用 GOWORK=off 让自包含的 desktop 独立构建,不污染后端 go.work
- .gitignore: 忽略 wails 生成物(build/ wailsjs/ package.json.md5)
- 验证: go build 出 5.7MB 原生二进制(含 webkit cgo); wails build 全过 →
  build/bin/sundynix_desktop.app(生成绑定/编译前端/编译应用/打包/自签名)
- 运行: make desktop(开发窗口) 或 make desktop-build(打包); 桌面端前端经 HTTP 连
  Gateway:8080(CORS 已放开), 需先起后端 + 配模型

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-11 17:33:49 +08:00

29 lines
681 B
Go

package main
import (
"context"
"os"
)
// App 经 Wails 的 TS/Go 强绑定暴露给前端,承载本地文件 I/O 等只有桌面端能做的能力。
type App struct {
ctx context.Context
}
func NewApp() *App { return &App{} }
// startup 在 Wails 启动时注入运行时 ctx。
func (a *App) startup(ctx context.Context) { a.ctx = ctx }
// ReadLocalFile 读取本地文件内容(本地文件系统 I/O)。
func (a *App) ReadLocalFile(path string) (string, error) {
b, err := os.ReadFile(path)
if err != nil {
return "", err
}
return string(b), nil
}
// Ping 供前端探活 Go 桥是否就绪。
func (a *App) Ping() string { return "sundynix-desktop ok" }