feat: 撤回了更新的全部代码

This commit is contained in:
2026-05-15 15:09:14 +08:00
parent be205eafe0
commit dd7b41d1ad
36 changed files with 6 additions and 2901 deletions

View File

@@ -1,83 +1,27 @@
// #ifdef APP-PLUS
import checkUpdate from "@/uni_modules/uni-upgrade-center-app/utils/check-update";
// #endif
let isCheckingAppUpdate = false;
let hasRegisteredMiniProgramUpdate = false;
const APP_UPDATE_CHECK_TIMEOUT = 30000;
const formatUpdateError = (error) => {
if (!error) return "";
if (typeof error === "string") return error;
return error.message || error.errMsg || JSON.stringify(error);
};
export const checkMiniProgramUpdate = () => {
export const updateManager = () => {
// #ifdef MP-WEIXIN || MP-TOUTIAO
if (hasRegisteredMiniProgramUpdate) return;
hasRegisteredMiniProgramUpdate = true;
const miniProgramUpdateManager = uni.getUpdateManager();
const updateManager = uni.getUpdateManager();
// 当向小程序后台请求完新版本信息,会进行回调
miniProgramUpdateManager.onCheckForUpdate((res) => {
updateManager.onCheckForUpdate((res) => {
console.log("onCheckForUpdate res:", res.hasUpdate);
});
// 当新版本下载完成,会进行回调
miniProgramUpdateManager.onUpdateReady(() => {
updateManager.onUpdateReady(() => {
uni.showModal({
title: "更新提示",
content: "新版本已经准备好,是否重启应用?",
success: (res) => {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
miniProgramUpdateManager.applyUpdate();
updateManager.applyUpdate();
}
},
});
});
// 当新版本下载失败,会进行回调
miniProgramUpdateManager.onUpdateFailed(() => {});
updateManager.onUpdateFailed(() => {});
// #endif
};
export const checkAppUpdate = () => {
// #ifdef APP-PLUS
if (isCheckingAppUpdate) return Promise.resolve(null);
isCheckingAppUpdate = true;
return new Promise((resolve) => {
let finished = false;
const finish = (result = null) => {
if (finished) return;
finished = true;
clearTimeout(timeoutTimer);
isCheckingAppUpdate = false;
resolve(result);
};
const timeoutTimer = setTimeout(() => {
finish();
}, APP_UPDATE_CHECK_TIMEOUT);
checkUpdate()
.then(finish)
.catch((error) => {
console.warn("App更新检查失败:", formatUpdateError(error));
finish();
});
});
// #endif
// #ifndef APP-PLUS
return Promise.resolve(null);
// #endif
};
export const updateManager = () => {
checkMiniProgramUpdate();
return checkAppUpdate();
};