Files
sundynix-agentix/sundynix-desktop/frontend/src/lib/version.ts
T
Blizzard 027ccc0ccc chore(desktop): 版本号三处对齐 0.1.1,追平已存在的 v0.1.1 tag
git tag 已打到 v0.1.1,但 APP_VERSION/package.json/build/config.yml 全停在
0.1.0 —— 按更新提示的比对逻辑这会错乱。三处统一 0.1.1,并跑
wails3 task common:update:build-assets 重新生成原生元数据(Info.plist 等,
CFBundleShortVersionString 已核实落到 0.1.1,包名/标识符未被冲回模板值)。
生成器顺手拉的 build/ios/ 脚手架已删,不做 iOS。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 16:28:03 +08:00

51 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 桌面端版本与"检查更新"——查 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.1"; // 当前桌面端版本(与 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;
}