Merge branch 'fix/pending-bundle' into dev
This commit is contained in:
@@ -135,7 +135,16 @@ async function download(): Promise<BundleInfo | null> {
|
||||
|
||||
/** 立即应用并重启 */
|
||||
async function apply(bundle: BundleInfo): Promise<void> {
|
||||
await CapacitorUpdater.set({ id: bundle.id });
|
||||
error.value = "";
|
||||
try {
|
||||
await CapacitorUpdater.set({ id: bundle.id });
|
||||
} catch (e) {
|
||||
// 包目录已被清理或本身就是坏的(例如把安装包当热更包下下来),
|
||||
// set 会报 id 不存在。不清理的话每次启动都卡在「已下载,重启生效」
|
||||
await CapacitorUpdater.delete({ id: bundle.id }).catch(() => undefined);
|
||||
ready.value = null;
|
||||
error.value = e instanceof Error ? e.message : "更新失败";
|
||||
}
|
||||
}
|
||||
|
||||
/** 排队到下次启动应用 */
|
||||
@@ -143,6 +152,9 @@ async function defer(bundle: BundleInfo): Promise<void> {
|
||||
await CapacitorUpdater.next({ id: bundle.id });
|
||||
}
|
||||
|
||||
/** 可以应用的包状态:剩下的都是删除中或下载失败的残骸,set 会报 id 不存在 */
|
||||
const USABLE_STATUS: Array<BundleInfo["status"]> = ["success", "pending"];
|
||||
|
||||
/** 查找已下载但尚未应用的版本 */
|
||||
async function restorePending(): Promise<void> {
|
||||
if (!supported) {
|
||||
@@ -152,7 +164,7 @@ async function restorePending(): Promise<void> {
|
||||
const [current, list] = await Promise.all([CapacitorUpdater.current(), CapacitorUpdater.list()]);
|
||||
const currentId = current.bundle?.id;
|
||||
const pending = list.bundles
|
||||
.filter(bundle => bundle.id !== currentId)
|
||||
.filter(bundle => bundle.id !== currentId && USABLE_STATUS.includes(bundle.status))
|
||||
.sort((a, b) => Date.parse(b.downloaded) - Date.parse(a.downloaded))[0];
|
||||
ready.value = pending ?? null;
|
||||
} catch {
|
||||
|
||||
@@ -279,6 +279,10 @@ async function handleApply(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await apply(bundle);
|
||||
// 应用成功会直接重启,走到这里说明包是坏的,已经清理掉,提示后可以重新检查
|
||||
if (updateError.value) {
|
||||
Message.error(`更新失败:${updateError.value}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user