fix(app): OTA更新体验重构 — 废除闪烁弹窗 + 自动重启
问题:
1. uni.showLoading 每次调用都是关→开,进度回调中连续调用导致疯狂闪烁
2. 安装完成后弹窗询问重启,用户选「稍后」则必须手动杀后台
修复:
1. 替换 uni.showLoading → plus.nativeUI.showWaiting
原生等待框支持原地更新文字,下载进度平滑过渡,零闪烁
2. 安装成功后移除重启询问弹窗,改为:
plus.nativeUI.toast('新版本已就绪,即将重启...')
→ 2秒后 setTimeout → plus.runtime.restart()
用户无需任何操作,2秒后自动生效
This commit is contained in:
@ -97,41 +97,35 @@ export default {
|
|||||||
success: (modalRes) => {
|
success: (modalRes) => {
|
||||||
if (!modalRes.confirm) return;
|
if (!modalRes.confirm) return;
|
||||||
|
|
||||||
// 显示下载进度
|
// 🚀 使用原生等待框,原地更新文字,杜绝闪烁
|
||||||
uni.showLoading({ title: "下载中 0%", mask: true });
|
plus.nativeUI.showWaiting("正在下载 0%");
|
||||||
|
|
||||||
const downloadTask = uni.downloadFile({
|
const downloadTask = uni.downloadFile({
|
||||||
url: wgtUrl,
|
url: wgtUrl,
|
||||||
success: (downloadRes) => {
|
success: (downloadRes) => {
|
||||||
if (downloadRes.statusCode !== 200) {
|
if (downloadRes.statusCode !== 200) {
|
||||||
uni.hideLoading();
|
plus.nativeUI.closeWaiting();
|
||||||
uni.showToast({ title: "下载失败", icon: "none" });
|
uni.showToast({ title: "下载失败", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showLoading({ title: "安装中...", mask: true });
|
// 安装阶段 — 原生等待框直接更新文字,无闪烁
|
||||||
|
plus.nativeUI.showWaiting("正在安装...");
|
||||||
|
|
||||||
// 调用 plus.runtime.install 安装 WGT
|
|
||||||
plus.runtime.install(
|
plus.runtime.install(
|
||||||
downloadRes.tempFilePath,
|
downloadRes.tempFilePath,
|
||||||
{ force: true },
|
{ force: true },
|
||||||
() => {
|
() => {
|
||||||
uni.hideLoading();
|
plus.nativeUI.closeWaiting();
|
||||||
console.log("[OTA] WGT 安装成功");
|
console.log("[OTA] WGT 安装成功");
|
||||||
uni.showModal({
|
// 🚀 静默重启:toast 提示后自动重启,无需用户杀后台
|
||||||
title: "更新完成",
|
plus.nativeUI.toast("新版本已就绪,即将重启...");
|
||||||
content: "新版本已安装,重启后生效。是否立即重启?",
|
setTimeout(() => {
|
||||||
confirmText: "立即重启",
|
plus.runtime.restart();
|
||||||
cancelText: "稍后",
|
}, 2000);
|
||||||
success: (restartRes) => {
|
|
||||||
if (restartRes.confirm) {
|
|
||||||
plus.runtime.restart();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
uni.hideLoading();
|
plus.nativeUI.closeWaiting();
|
||||||
console.error("[OTA] 安装失败:", err.message);
|
console.error("[OTA] 安装失败:", err.message);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "更新失败: " + (err.message || "未知错误"),
|
title: "更新失败: " + (err.message || "未知错误"),
|
||||||
@ -142,19 +136,18 @@ export default {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
uni.hideLoading();
|
plus.nativeUI.closeWaiting();
|
||||||
console.error("[OTA] 下载失败:", err.errMsg);
|
console.error("[OTA] 下载失败:", err.errMsg);
|
||||||
uni.showToast({ title: "下载失败,请检查网络", icon: "none" });
|
uni.showToast({ title: "下载失败,请检查网络", icon: "none" });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 下载进度回调
|
// 下载进度 — 稳定更新原生等待框文字,不会闪烁
|
||||||
if (downloadTask && downloadTask.onProgressUpdate) {
|
if (downloadTask && downloadTask.onProgressUpdate) {
|
||||||
downloadTask.onProgressUpdate((res) => {
|
downloadTask.onProgressUpdate((res) => {
|
||||||
const pct = res.progress;
|
const pct = res.progress;
|
||||||
uni.showLoading({ title: `下载中 ${pct}%`, mask: true });
|
if (pct < 100) {
|
||||||
if (pct >= 100) {
|
plus.nativeUI.showWaiting(`正在下载 ${pct}%`);
|
||||||
uni.showLoading({ title: "安装中...", mask: true });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user