feat: 新增自动更新版本引导流程及相关配置调整

- 新增完整的upvp更新引导页面套件,涵盖版本展示、版本检查、测试协议确认与完成页流程
- 新增appVersion配置字段用于记录当前应用版本,调整配置文件存储路径与旧配置迁移逻辑
- 更新路由配置与全局状态管理以支持更新引导流程
- 更新自动更新计划文档与示例配置文件
This commit is contained in:
2026-08-31 03:04:23 +08:00
parent fa44d41d44
commit b3da357d57
16 changed files with 391 additions and 28 deletions
+68
View File
@@ -0,0 +1,68 @@
import { useEffect, useState } from "react";
import { useRouteStore } from "@/stores/routeStore";
import { useConfigStore } from "@/stores/configStore";
import { VERSION } from "@/lib/version";
import { compareVersions } from "@/api/update";
import { UpvpLayout } from "./layout";
import { AppleHelloEnglishEffect } from "@/components/ui/apple-hello-effect";
/**
* 第四步(结束):与 OOBE 结束页一致。
* 写入 appVersion 规则:
* - 程序版本 > appVersion(正常升级)→ 更新 appVersion 为当前版本号
* - 程序版本 < appVersion(版本倒退)→ 不修改,保持原样
*/
export function UpvpFinish() {
const navigate = useRouteStore((s) => s.navigate);
const appVersion = useConfigStore((s) => s.config.appVersion);
const setAppVersion = useConfigStore((s) => s.setAppVersion);
const [ready, setReady] = useState(false);
const [shouldWrite, setShouldWrite] = useState(false);
useEffect(() => {
let cancelled = false;
compareVersions(VERSION, appVersion)
.then((r) => {
if (cancelled) return;
// 仅版本倒退(a<b)保持原样;相等/无效也写入(无害,值为当前版本)
setShouldWrite(r.result !== "a<b");
})
.catch(() => {
if (!cancelled) setShouldWrite(true);
})
.finally(() => {
if (!cancelled) setReady(true);
});
return () => {
cancelled = true;
};
}, [appVersion]);
const handleFinish = () => {
if (shouldWrite) {
// 正常升级:记录当前版本到配置,下次启动程序版本与配置版本一致 → 正常进入主页
setAppVersion(VERSION);
}
// 版本倒退:不修改 appVersion,下次启动仍会进入 upvp 提醒
navigate("home");
};
return (
<UpvpLayout>
<div className="flex flex-col items-center gap-6">
<AppleHelloEnglishEffect className="text-foreground" />
</div>
<div className="absolute bottom-12">
<button
onClick={handleFinish}
disabled={!ready}
className="h-12 px-6 rounded-full bg-foreground/[0.06] hover:bg-foreground/[0.12] flex items-center justify-center text-foreground/60 hover:text-foreground transition-all duration-200 text-sm font-medium disabled:opacity-40 disabled:cursor-not-allowed"
>
</button>
</div>
</UpvpLayout>
);
}