|
@@ -40,6 +40,8 @@ const HOT_UPDATE_SKIP_VERSION_KEY = "__APP_WGT_HOT_UPDATE_SKIP_VERSION__";
|
|
|
*/
|
|
*/
|
|
|
const HOT_UPDATE_API_URL =
|
|
const HOT_UPDATE_API_URL =
|
|
|
config.default.apiUrl + config.default.apiUrlSuffix + "/rq/iot-app/newWgt";
|
|
config.default.apiUrl + config.default.apiUrlSuffix + "/rq/iot-app/newWgt";
|
|
|
|
|
+const APP_UPGRADE_API_URL =
|
|
|
|
|
+ config.default.apiUrl + config.default.apiUrlSuffix + "/rq/iot-app/new";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 读取当前进程的热更新运行状态。
|
|
* 读取当前进程的热更新运行状态。
|
|
@@ -193,6 +195,59 @@ const isWgtPackageUrl = (url = "") => {
|
|
|
return normalizedUrl.endsWith(".wgt");
|
|
return normalizedUrl.endsWith(".wgt");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const isApkPackageUrl = (url = "") => {
|
|
|
|
|
+ const normalizedUrl = String(url)
|
|
|
|
|
+ .trim()
|
|
|
|
|
+ .split("#")[0]
|
|
|
|
|
+ .split("?")[0]
|
|
|
|
|
+ .toLowerCase();
|
|
|
|
|
+
|
|
|
|
|
+ return normalizedUrl.endsWith(".apk");
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 启动时先检查整包更新。只有 Android 端存在比当前原生版本更新的 APK 时,
|
|
|
|
|
+ * 才中止 WGT 流程并通知原有整包升级组件。
|
|
|
|
|
+ */
|
|
|
|
|
+const requestAppUpgradeInfo = () => {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ uni.request({
|
|
|
|
|
+ url: APP_UPGRADE_API_URL,
|
|
|
|
|
+ method: "GET",
|
|
|
|
|
+ header: {
|
|
|
|
|
+ "Content-Type": "application/json",
|
|
|
|
|
+ "tenant-id": "1",
|
|
|
|
|
+ },
|
|
|
|
|
+ timeout: 10000,
|
|
|
|
|
+ success: (response) => {
|
|
|
|
|
+ if (response.statusCode !== 200) {
|
|
|
|
|
+ reject(
|
|
|
|
|
+ new Error(
|
|
|
|
|
+ `整包更新检查接口请求失败,HTTP 状态码:${response.statusCode}`
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ resolve(response.data || {});
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (error) => {
|
|
|
|
|
+ reject(new Error(error?.errMsg || "整包更新检查接口请求失败"));
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const shouldPrioritizeAppUpgrade = (response, currentAppVersion) => {
|
|
|
|
|
+ const data = response?.code === 0 ? response?.data : null;
|
|
|
|
|
+
|
|
|
|
|
+ if (!data?.appVersion || !isApkPackageUrl(data.url)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return compareVersion(data.appVersion, currentAppVersion) > 0;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 请求服务端检查是否存在新的 .wgt 资源包。
|
|
* 请求服务端检查是否存在新的 .wgt 资源包。
|
|
|
*
|
|
*
|
|
@@ -567,13 +622,14 @@ const showHotUpdateError = (error, title = "更新失败") => {
|
|
|
*
|
|
*
|
|
|
* 整体执行顺序:
|
|
* 整体执行顺序:
|
|
|
* 1. 等待 plus 就绪
|
|
* 1. 等待 plus 就绪
|
|
|
- * 2. 获取当前资源版本
|
|
|
|
|
- * 3. 请求服务端检查更新
|
|
|
|
|
- * 4. 判断是否存在新的 .wgt 包
|
|
|
|
|
- * 5. 提示用户确认
|
|
|
|
|
- * 6. 下载 .wgt
|
|
|
|
|
- * 7. 安装 .wgt
|
|
|
|
|
- * 8. 重启应用
|
|
|
|
|
|
|
+ * 2. Android 端先检查是否存在新的 APK
|
|
|
|
|
+ * 3. 没有 APK 更新时获取当前资源版本
|
|
|
|
|
+ * 4. 请求服务端检查 WGT 更新
|
|
|
|
|
+ * 5. 判断是否存在新的 .wgt 包
|
|
|
|
|
+ * 6. 提示用户确认
|
|
|
|
|
+ * 7. 下载 .wgt
|
|
|
|
|
+ * 8. 安装 .wgt
|
|
|
|
|
+ * 9. 重启应用
|
|
|
*
|
|
*
|
|
|
* 返回值:
|
|
* 返回值:
|
|
|
* - Promise<{ status: string, ... }>
|
|
* - Promise<{ status: string, ... }>
|
|
@@ -588,6 +644,29 @@ const executeWgtHotUpdate = async () => {
|
|
|
currentStage = "plus-ready";
|
|
currentStage = "plus-ready";
|
|
|
await waitForPlusReady();
|
|
await waitForPlusReady();
|
|
|
|
|
|
|
|
|
|
+ if (uni.getSystemInfoSync().platform === "android") {
|
|
|
|
|
+ currentStage = "request-app-upgrade";
|
|
|
|
|
+ try {
|
|
|
|
|
+ const appUpgradeResponse = await requestAppUpgradeInfo();
|
|
|
|
|
+ if (
|
|
|
|
|
+ shouldPrioritizeAppUpgrade(
|
|
|
|
|
+ appUpgradeResponse,
|
|
|
|
|
+ plus.runtime.version
|
|
|
|
|
+ )
|
|
|
|
|
+ ) {
|
|
|
|
|
+ finalResult = {
|
|
|
|
|
+ status: "fallback-app-check-version",
|
|
|
|
|
+ message: "检测到新的 APK,优先执行整包更新",
|
|
|
|
|
+ data: appUpgradeResponse.data,
|
|
|
|
|
+ };
|
|
|
|
|
+ return finalResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ // APK 检查失败时不阻断原有 WGT 更新能力。
|
|
|
|
|
+ console.warn("[hot-update] APK 更新检查失败,继续检查 WGT", error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
currentStage = "read-local-version";
|
|
currentStage = "read-local-version";
|
|
|
const wgtInfo = await getCurrentWgtInfo();
|
|
const wgtInfo = await getCurrentWgtInfo();
|
|
|
|
|
|