liming hai 3 semanas
pai
achega
c3d4e5ef6c
Modificáronse 6 ficheiros con 67 adicións e 29 borrados
  1. 1 1
      android/app/capacitor.build.gradle
  2. 9 1
      capacitor.config.ts
  3. 2 3
      package.json
  4. 47 17
      src/hooks/updataApp.js
  5. 6 7
      src/plugins/storage.js
  6. 2 0
      vite.config.js

+ 1 - 1
android/app/capacitor.build.gradle

@@ -13,11 +13,11 @@ dependencies {
     implementation project(':capacitor-app')
     implementation project(':capacitor-browser')
     implementation project(':capacitor-device')
-    implementation project(':capacitor-file-transfer')
     implementation project(':capacitor-local-notifications')
     implementation project(':capacitor-push-notifications')
     implementation project(':capacitor-status-bar')
     implementation project(':capacitor-toast')
+    implementation project(':capawesome-capacitor-app-update')
 
 }
 apply from: "../../node_modules/.store/cordova-plugin-fingerprint-aio@6.0.1/node_modules/cordova-plugin-fingerprint-aio/src/android/build.gradle"

+ 9 - 1
capacitor.config.ts

@@ -1,4 +1,9 @@
 import { CapacitorConfig } from '@capacitor/cli';
+import * as fs from 'fs';
+
+// 读取 package.json 的 version
+const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
+const appVersion = packageJson.version;
 
 const config: CapacitorConfig = {
   appId: 'com.example.app',
@@ -35,7 +40,10 @@ const config: CapacitorConfig = {
     // 注意:原JSON中嵌套了重复的"plugins"键,已修正
     PushNotifications: {
       presentationOptions: ['badge', 'sound', 'alert']
-    }
+    },
+    VersionSync: {
+      version: appVersion, // 直接传递版本号
+    },
   },
 
   // 资源文件配置

+ 2 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "wallet_app",
-  "version": "1.0.0",
+  "version": "2.0.0",
   "private": true,
   "type": "module",
   "scripts": {
@@ -25,12 +25,11 @@
     "@capacitor/cli": "^7.2.0",
     "@capacitor/core": "^7.2.0",
     "@capacitor/device": "^7.0.1",
-    "@capacitor/file-transfer": "^1.0.1",
     "@capacitor/ios": "^7.2.0",
     "@capacitor/local-notifications": "^7.0.1",
     "@capacitor/push-notifications": "^7.0.1",
     "@capacitor/status-bar": "^7.0.1",
-    "@capacitor/toast": "^7.0.1",
+    "@capacitor/toast": "^7.0.1", 
     "@ionic-native/fingerprint-aio": "^5.36.0",
     "axios": "^1.10.0",
     "clipboard": "^2.0.11",

+ 47 - 17
src/hooks/updataApp.js

@@ -1,30 +1,60 @@
-import { Device } from '@capacitor/device';
-// import { downloadFile } from "@capacitor/file-transfer"
+import { Capacitor } from '@capacitor/core';
+import { AppUpdate } from '@capawesome/capacitor-app-update';
+
+
+
+
+// 获取当前应用版本
+const getCurrentAppVersion = async () => {
+  const result = await AppUpdate.getAppUpdateInfo();
+
+  console.log('当前应用版本:', result);
+  // if (Capacitor.getPlatform() === 'android') {
+  //   return result.currentVersionCode;
+  // } else {
+  //   return result.currentVersionName;
+  // }
+};
+
+
+
+
+
+
+
+
+
+
+
 
 
 // 检测是否有更新包
 export const checkUpdate = async () => { 
   // 获取当前应用版本
-  const { version } = await Device.getInfo();
-  console.log("当前版本:", version)
-
-  // 从服务器获取最新版本信息
-  const response = await fetch('https://your-server.com/api/check-update');
-  const serverData = await response.json();
-
-   // 对比版本号(建议使用语义化版本比较库,如 compare-versions)
-  if (compareVersions(serverData.latestVersion, version) > 0) {
-    console.log('发现新版本:', serverData.latestVersion);
-    return serverData; // 返回更新信息
-  }
+  const info = await App.getInfo(); 
+  console.log("当前版本:", info)
+ 
+  // // 从服务器获取最新版本信息
+  // const response = await fetch('https://your-server.com/api/check-update');
+  // const serverData = await response.json();
+
+  //  // 对比版本号(建议使用语义化版本比较库,如 compare-versions)
+  // if (compareVersions(serverData.latestVersion, version) > 0) {
+  //   console.log('发现新版本:', serverData.latestVersion);
+  //   return serverData; // 返回更新信息
+  // }
   return null; // 无更新
 }
 
 
 // 示例:在应用启动时检查
 export const appStart = async () => {
-  const updateInfo = await checkUpdate();
-  if (updateInfo) {
+  // const updateInfo = await checkUpdate();
+  // if (updateInfo) {
     // showUpdateDialog(updateInfo); // 提示用户更新
-  }
+  // }
+
+
+  const dd = await getCurrentAppVersion()
+  console.log("当前版本:", dd)
 }

+ 6 - 7
src/plugins/storage.js

@@ -1,12 +1,11 @@
-
-import { showNotify } from 'vant';
+import { showToast } from "vant";
 import { i18n } from "@/i18n";
- 
+
 export function setup() {
-  window["$msg"] = (msg, type = 'warning')=>{
-    showNotify({ type:type, message: msg, background:"transparent", color:"#4765dd", top: 150})
-  } 
+  window["$msg"] = (msg, position = "top") => {
+    showToast({ position: position, message: msg });
+  };
 
   window["$t"] = i18n.global.t;
-  window["$web3"] = undefined
+  window["$web3"] = undefined;
 }

+ 2 - 0
vite.config.js

@@ -7,6 +7,8 @@ import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
 import { codeInspectorPlugin } from "code-inspector-plugin";
 import AutoImport from "unplugin-auto-import/vite";
 
+
+
 import { resolve } from "path";
 
 // https://vite.dev/config/