|
@@ -6,7 +6,7 @@ import { showDialog } from "vant";
|
|
|
const HOST = "https://nim.angeltokens.io/updates/down/";
|
|
|
const UPDATE_URL = HOST + "update.json";
|
|
|
|
|
|
-// 检查并更新
|
|
|
+// 检查并更新: shasum -a 256
|
|
|
export async function checkAndUpdate() {
|
|
|
// 判断是web 还是 ios
|
|
|
if (Capacitor.getPlatform() === "web") {
|
|
@@ -19,14 +19,21 @@ export async function checkAndUpdate() {
|
|
|
console.log("更新", meta);
|
|
|
|
|
|
// 2. 基本校验
|
|
|
+ // 判断是ios
|
|
|
+ if (Capacitor.getPlatform() === "ios") {
|
|
|
+ await CapacitorUpdater.ready(); // 等插件完全就绪
|
|
|
+ }else{
|
|
|
+ await new Promise(r => setTimeout(r, 1000));
|
|
|
+ }
|
|
|
const current = await CapacitorUpdater.current();
|
|
|
const { version } = await App.getInfo();
|
|
|
|
|
|
- console.log("版本:", current.bundle.version, meta.version)
|
|
|
- if (
|
|
|
- current.bundle.version != "builtin" &&
|
|
|
- semver.gte(current.bundle.version, meta.version)
|
|
|
- ) {
|
|
|
+ console.log("版本:", current.bundle.version, meta.version);
|
|
|
+ if (!current.bundle.version || current.bundle.version == "builtin") {
|
|
|
+ console.log("无新版本!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (semver.gte(current.bundle.version, meta.version)) {
|
|
|
console.log("无新版本");
|
|
|
return;
|
|
|
}
|
|
@@ -41,7 +48,6 @@ export async function checkAndUpdate() {
|
|
|
checksum: meta.checksum,
|
|
|
});
|
|
|
|
|
|
- await CapacitorUpdater.set(update); // 设置新版本
|
|
|
// 通知
|
|
|
if (meta.mandatory) {
|
|
|
await showDialog({
|
|
@@ -49,8 +55,13 @@ export async function checkAndUpdate() {
|
|
|
confirmButtonText: "立即體驗",
|
|
|
message: meta.upDataDescription,
|
|
|
}).then(async () => {
|
|
|
+ await CapacitorUpdater.set(update); // 设置新版本
|
|
|
console.log("✅ 已切换到新版本,准备重启");
|
|
|
await App.exitApp(); // 冷启动加载新 bundle
|
|
|
});
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ await CapacitorUpdater.set(update); // 设置新版本
|
|
|
+ console.log("✅ 已切换到新版本,准备重启");
|
|
|
+ await App.exitApp(); // 冷启动加载新 bundle
|
|
|
+ }
|
|
|
}
|