浏览代码

feat: 版本控制

liming 2 周之前
父节点
当前提交
64bc87eed0
共有 2 个文件被更改,包括 9 次插入12 次删除
  1. 6 8
      src/updater/index.js
  2. 3 4
      src/updater/update.json

+ 6 - 8
src/updater/index.js

@@ -16,15 +16,16 @@ export async function checkAndUpdate() {
 
   // 1. 拉取元数据
   const meta = await fetch(UPDATE_URL).then((r) => r.json());
-  console.log("2. 基本校验", meta);
+  console.log("更新", meta);
 
   // 2. 基本校验
   const current = await CapacitorUpdater.current();
   const { version } = await App.getInfo();
 
+  console.log("版本:", current.bundle.version, meta.version)
   if (
     current.bundle.version != "builtin" &&
-    semver.lt(current.bundle.version, meta.version)
+    semver.gte(current.bundle.version, meta.version)
   ) {
     console.log("无新版本");
     return;
@@ -40,19 +41,16 @@ export async function checkAndUpdate() {
     checksum: meta.checksum,
   });
 
+  await CapacitorUpdater.set(update); // 设置新版本
   // 通知
   if (meta.mandatory) {
-    showDialog({
+    await 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);
-  }
+  } 
 }

+ 3 - 4
src/updater/update.json

@@ -1,9 +1,8 @@
 {
-  "version": "1.0.1",
-  "releaseDate": "2025-07-29", 
-  "checksum": "a10e05f75f27f9402646f12d743ec5804ecafcc4fb0e30645e7dff5aae75906d",
+  "version": "1.0.2",
+  "releaseDate": "2025-07-29 12:00:00", 
+  "checksum": "9bbb76110107c102dee68f1146c8d556a59b0cb550b3abcfc6cdb221182b0f12",
   "minBinaryVersion": "1.0.0",
   "mandatory": true,
   "upDataDescription":"✨修正一些錯誤!"
-   
 }