1f487c3163
从 wails/v2 v2.12.0 迁到 v3 v3.0.0-alpha2.117,采用 v3 工程规范:
Go 侧:
- main.go:wails.Run(options.App) → application.New(Options{Services,Assets,Mac})
+ app.Window.NewWithOptions(WebviewWindowOptions) + app.Run();窗口选项照搬
(1440×900/min 1100×700/#0b0d12/Mac TitleBarHiddenInset)
- app.go:App 结构体绑定 → v3 Service(application.NewService);去 startup/ctx 注入;
SaveFileDialog 改 v3 链式 API(application.Get().Dialog.SaveFile().SetFilename().
AddFilter().PromptForSingleSelection());5 个原生方法保留
- go.mod wails/v2→v3、go 1.25
构建:
- wails.json → Taskfile.yml + build/(config.yml 填产品信息 + 各平台配置)
- 删移动端脚手架(ios/android),桌面端只留 darwin/windows/linux
- .gitignore 改为只忽略 build/bin(build/ 构建系统需提交)
前端:
- vite.config 接 @wailsio/runtime/plugins/vite 插件 + WAILS_VITE_PORT
- package.json 加 @wailsio/runtime;wails3 generate bindings → frontend/bindings/
- desktop.ts:window.go.main.App → import { App } from bindings;桌面态检测改
window._wails.environment(原生注入);isMacDesktop 用 System.IsMac()
- version.ts:runtime.BrowserOpenURL → @wailsio/runtime Browser.OpenURL;测试同步更新
- tsconfig 加 allowJs(消费 JSDoc 绑定)
验证进度:Go 编译过 + tsc 干净 + 48 前端测试绿 + 前端 vite build 通过。
**未完成:整体 wails3 build/dev 原生窗口实跑 + 原生能力(另存为/打开/外链)联调**——下次续。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
51 lines
2.2 KiB
TypeScript
51 lines
2.2 KiB
TypeScript
// 桌面端版本与"检查更新"——查 GitHub Releases 最新版,比当前版本新则提示下载。
|
||
// 发版流程:bump 此处 APP_VERSION(= package.json version)→ 打 tag vX.Y.Z → release workflow 自动构建+发布。
|
||
import { Browser } from "@wailsio/runtime";
|
||
|
||
export const APP_VERSION = "0.1.0"; // 当前桌面端版本(与 git tag 去掉 v 前缀对齐)
|
||
|
||
const REPO = "blizzardzhang/sundynix-agentix";
|
||
|
||
export interface ReleaseInfo {
|
||
version: string; // 最新版本号(不含 v)
|
||
url: string; // release 页面(用户在此选 mac/win 安装包)
|
||
notes: string; // 更新日志
|
||
}
|
||
|
||
// checkUpdate 查 GitHub 最新 release;有比当前更新的版本则返回信息,否则 null(含出错/限流时静默)。
|
||
export async function checkUpdate(): Promise<ReleaseInfo | null> {
|
||
try {
|
||
const res = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`, {
|
||
headers: { Accept: "application/vnd.github+json" },
|
||
});
|
||
if (!res.ok) return null; // 404=还没发过 release / 403=限流 → 静默
|
||
const d = (await res.json()) as { tag_name?: string; html_url?: string; body?: string };
|
||
const latest = String(d.tag_name ?? "").replace(/^v/, "");
|
||
if (!latest || !isNewer(latest, APP_VERSION)) return null;
|
||
return { version: latest, url: d.html_url ?? `https://github.com/${REPO}/releases/latest`, notes: d.body ?? "" };
|
||
} catch {
|
||
return null; // 离线等 → 不打扰
|
||
}
|
||
}
|
||
|
||
// openExternal 在系统浏览器打开链接(Wails v3 用 Browser.OpenURL,浏览器模式回退 window.open)。
|
||
export function openExternal(url: string): void {
|
||
if ((window as unknown as { _wails?: { environment?: unknown } })._wails?.environment) {
|
||
void Browser.OpenURL(url);
|
||
} else {
|
||
window.open(url, "_blank");
|
||
}
|
||
}
|
||
|
||
// isNewer 语义化版本比较:a 是否比 b 新(按 major.minor.patch)。导出以便单测覆盖版本判定矩阵。
|
||
export function isNewer(a: string, b: string): boolean {
|
||
const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
|
||
const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
|
||
for (let i = 0; i < 3; i++) {
|
||
const x = pa[i] ?? 0;
|
||
const y = pb[i] ?? 0;
|
||
if (x !== y) return x > y;
|
||
}
|
||
return false;
|
||
}
|