|
@@ -1,4 +1,4 @@
|
|
- import { CapacitorUpdater } from "@capgo/capacitor-updater";
|
|
|
|
|
|
+import { CapacitorUpdater } from "@capgo/capacitor-updater";
|
|
import { App } from "@capacitor/app";
|
|
import { App } from "@capacitor/app";
|
|
import semver from "semver";
|
|
import semver from "semver";
|
|
import { showDialog } from "vant";
|
|
import { showDialog } from "vant";
|
|
@@ -18,14 +18,6 @@ export async function checkAndUpdate() {
|
|
const meta = await fetch(UPDATE_URL).then((r) => r.json());
|
|
const meta = await fetch(UPDATE_URL).then((r) => r.json());
|
|
console.log("2. 基本校验", meta);
|
|
console.log("2. 基本校验", meta);
|
|
|
|
|
|
- // 通知
|
|
|
|
- if (meta.mandatory) {
|
|
|
|
- showDialog({
|
|
|
|
- title: meta.notificationTitle,
|
|
|
|
- message: meta.notificationBody,
|
|
|
|
- }).then(async () => {});
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// 2. 基本校验
|
|
// 2. 基本校验
|
|
const current = await CapacitorUpdater.current();
|
|
const current = await CapacitorUpdater.current();
|
|
const { version } = await App.getInfo();
|
|
const { version } = await App.getInfo();
|
|
@@ -49,14 +41,18 @@ export async function checkAndUpdate() {
|
|
});
|
|
});
|
|
|
|
|
|
// 通知
|
|
// 通知
|
|
- showDialog({
|
|
|
|
- title: `v ${meta.version} 已發布`,
|
|
|
|
- confirmButtonText: "立即體驗",
|
|
|
|
- message: meta.upDataDescription,
|
|
|
|
- }).then(async () => {
|
|
|
|
- // 重启
|
|
|
|
|
|
+ if (meta.mandatory) {
|
|
|
|
+ showDialog({
|
|
|
|
+ title: `v ${meta.version} 已發布`,
|
|
|
|
+ confirmButtonText: "立即體驗",
|
|
|
|
+ message: meta.upDataDescription,
|
|
|
|
+ }).then(async () => {
|
|
|
|
+ // 重启
|
|
|
|
+ await CapacitorUpdater.set(update); // 设置新版本
|
|
|
|
+ console.log("✅ 已切换到新版本,准备重启");
|
|
|
|
+ await App.exitApp(); // 冷启动加载新 bundle
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
await CapacitorUpdater.set(update);
|
|
await CapacitorUpdater.set(update);
|
|
- console.log("✅ 已切换到新版本,准备重启");
|
|
|
|
- await App.exitApp(); // 冷启动加载新 bundle
|
|
|
|
- });
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|