From a927aa428be6c1ae6110b52ab62c823537b37f57 Mon Sep 17 00:00:00 2001 From: gongxh Date: Sat, 19 Apr 2025 15:10:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=83=AD=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E6=A3=80=E6=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hotupdate/HotUpdate.ts | 4 ---- src/hotupdate/HotUpdateManager.ts | 37 +++++++++++++++++++------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/hotupdate/HotUpdate.ts b/src/hotupdate/HotUpdate.ts index e3f3efb..b8d8b6b 100644 --- a/src/hotupdate/HotUpdate.ts +++ b/src/hotupdate/HotUpdate.ts @@ -25,8 +25,6 @@ export interface IManifestResult extends IPromiseResult { export enum HotUpdateCode { /** 成功 */ Succeed = 0, - /** 出错了 */ - Error = -1, /** 平台不支持 不需要热更新 */ PlatformNotSupported = -1000, /** 未初始化 */ @@ -146,8 +144,6 @@ export class HotUpdate { } else { this._complete(res.code, res.message); } - }).catch((err) => { - this._complete(HotUpdateCode.Error, JSON.stringify(err)); }); } } diff --git a/src/hotupdate/HotUpdateManager.ts b/src/hotupdate/HotUpdateManager.ts index 5a97110..b7ffa13 100644 --- a/src/hotupdate/HotUpdateManager.ts +++ b/src/hotupdate/HotUpdateManager.ts @@ -34,7 +34,7 @@ export class HotUpdateManager { /** 是否正在更新 或者 正在检查更新 */ private _updating: boolean = false; - /** 更新实例 只有更新的时候初始化 检查更新不赋值 */ + /** 更新实例 */ private _hotUpdate: HotUpdate = null; /** @@ -117,12 +117,10 @@ export class HotUpdateManager { return; } this._updating = true; - new HotUpdate().checkUpdate().then((res) => { + this._hotUpdate = new HotUpdate(); + this._hotUpdate.checkUpdate().then((res) => { this._updating = false; resolve(res); - }).catch((err) => { - this._updating = false; - resolve({ code: HotUpdateCode.Error, message: JSON.stringify(err) }); }); }); } @@ -147,15 +145,26 @@ export class HotUpdateManager { return; } this._updating = true; - this._hotUpdate = new HotUpdate(); - this._hotUpdate.startUpdate({ - skipCheck: res.skipCheck, - progress: res.progress, - complete: (code: HotUpdateCode, message: string) => { - this._updating = false; - res.complete(code, message); - } - }); + if (res.skipCheck && this._hotUpdate) { + this._hotUpdate.startUpdate({ + skipCheck: res.skipCheck, + progress: res.progress, + complete: (code: HotUpdateCode, message: string) => { + this._updating = false; + res.complete(code, message); + } + }); + } else { + this._hotUpdate = new HotUpdate(); + this._hotUpdate.startUpdate({ + skipCheck: false, + progress: res.progress, + complete: (code: HotUpdateCode, message: string) => { + this._updating = false; + res.complete(code, message); + } + }); + } } /** 重试失败的资源 */