@ives_xxz/framework 1.1.7 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/FW.d.ts CHANGED
@@ -843,7 +843,7 @@ declare namespace FW {
843
843
  };
844
844
 
845
845
  type HotUpdateManager = {
846
- setListener(listener: HotUpdateListener): void;
846
+ setListener(listener: HotUpdateListener): HotUpdateManager;
847
847
  update(localManifest: cc.Asset): void;
848
848
  };
849
849
 
@@ -1470,7 +1470,7 @@ declare namespace FW {
1470
1470
  /**
1471
1471
  * 状态构造类
1472
1472
  */
1473
- stateConstructor: { new(): T };
1473
+ stateConstructor: { new (): T };
1474
1474
  };
1475
1475
 
1476
1476
  type AudioManager = {
@@ -11,11 +11,12 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
11
11
  private localManifest: cc.Asset;
12
12
  private isRetry: boolean;
13
13
  private currentVersion: string;
14
- private newVersion: string
14
+ private newVersion: string;
15
15
 
16
- setListener(listener: FW.HotUpdateListener): void {
16
+ setListener(listener: FW.HotUpdateListener): FW.HotUpdateManager {
17
17
  this.listener = listener;
18
18
  FWLog.debug('热更新监听设置');
19
+ return this;
19
20
  }
20
21
 
21
22
  public update(localManifest: cc.Asset) {
@@ -77,24 +78,50 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
77
78
  if (this.isUpdate) {
78
79
  return;
79
80
  }
80
- FWLog.debug('checkHotUpdate2', this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED);
81
81
  if (this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED) {
82
82
  this.assetMgr.loadLocalManifest(this.localManifest.nativeUrl);
83
83
  }
84
+
84
85
  FWLog.debug('checkHotUpdate3', this.assetMgr.getLocalManifest());
86
+
85
87
  FWLog.debug('checkHotUpdate4', this.assetMgr.getLocalManifest().isLoaded());
88
+
86
89
  if (!this.assetMgr.getLocalManifest() || !this.assetMgr.getLocalManifest().isLoaded()) {
87
- this.assetMgr.loadLocalManifest(this.localManifest.nativeUrl);
90
+ FWLog.debug('本地manifest未加载,尝试重新加载');
91
+ this.reloadLocalManifest();
92
+
93
+ // 如果仍然无法加载,则返回
88
94
  if (!this.assetMgr.getLocalManifest() || !this.assetMgr.getLocalManifest().isLoaded()) {
89
- FWLog.error('Failed to load local manifest');
95
+ FWLog.error('无法加载本地manifest文件');
90
96
  return;
91
97
  }
92
98
  }
99
+
93
100
  this.assetMgr.setEventCallback(this.checkEventHandle.bind(this));
94
101
  this.assetMgr.checkUpdate();
95
102
  this.isUpdate = true;
96
103
  }
97
104
 
105
+ private reloadLocalManifest() {
106
+ try {
107
+ const updatedManifestPath = `${this.storePath}/project.manifest`;
108
+ if (jsb.fileUtils.isFileExist(updatedManifestPath)) {
109
+ this.assetMgr.loadLocalManifest(updatedManifestPath);
110
+
111
+ if (this.assetMgr.getLocalManifest() && this.assetMgr.getLocalManifest().isLoaded()) {
112
+ FWLog.debug('本地manifest重新加载成功');
113
+ this.localManifest = this.assetMgr.getLocalManifest();
114
+ } else {
115
+ FWLog.error('本地manifest重新加载失败');
116
+ }
117
+ } else {
118
+ FWLog.error('更新后的manifest文件不存在:', updatedManifestPath);
119
+ }
120
+ } catch (error) {
121
+ FWLog.error('重新加载本地manifest时出错:', error);
122
+ }
123
+ }
124
+
98
125
  private checkEventHandle(event: any) {
99
126
  const code = event.getEventCode();
100
127
  FWLog.debug('checkEvent getEventCode -> ', code);
@@ -121,7 +148,10 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
121
148
  this.listener.checkHotUpdateHandle?.(code);
122
149
  this.assetMgr.setEventCallback(null!);
123
150
  this.isUpdate = false;
124
- FWLog.debug('isFind New Version -> ', event.getEventCode() == jsb.EventAssetsManager.NEW_VERSION_FOUND);
151
+ FWLog.debug(
152
+ 'isFind New Version -> ',
153
+ event.getEventCode() == jsb.EventAssetsManager.NEW_VERSION_FOUND,
154
+ );
125
155
  if (event.getEventCode() == jsb.EventAssetsManager.NEW_VERSION_FOUND) {
126
156
  this.hotUpdate();
127
157
  }
@@ -131,7 +161,10 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
131
161
  FWLog.debug('start hotUpdate ->', this.assetMgr, this.isUpdate);
132
162
  if (this.assetMgr && !this.isUpdate) {
133
163
  this.assetMgr.setEventCallback(this.updateEventHandle.bind(this));
134
- FWLog.debug('assetMgr state ->', this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED);
164
+ FWLog.debug(
165
+ 'assetMgr state ->',
166
+ this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED,
167
+ );
135
168
  if (this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED) {
136
169
  this.assetMgr.loadLocalManifest(this.localManifest.nativeUrl);
137
170
  }
@@ -170,7 +203,17 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
170
203
  convertDownloadedBytes = this.convertBytes(downloadedBytes);
171
204
  convertTotalBytes = this.convertBytes(totalBytes);
172
205
  percent = event.getPercent();
173
- FWLog.debug('正在更新中 -> ', '下载文件数量:', downloadedFiles, ',下载文件总数量:', totalFiles, ',已下载大小:', convertDownloadedBytes, ',下载总大小:', convertTotalBytes);
206
+ FWLog.debug(
207
+ '正在更新中 -> ',
208
+ '下载文件数量:',
209
+ downloadedFiles,
210
+ ',下载文件总数量:',
211
+ totalFiles,
212
+ ',已下载大小:',
213
+ convertDownloadedBytes,
214
+ ',下载总大小:',
215
+ convertTotalBytes,
216
+ );
174
217
  }
175
218
  break;
176
219
  case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
@@ -193,7 +236,17 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
193
236
  convertDownloadedBytes = this.convertBytes(downloadedBytes);
194
237
  convertTotalBytes = this.convertBytes(totalBytes);
195
238
  percent = event.getPercent();
196
- FWLog.debug('正在更新完成 -> ', '下载文件数量:', downloadedFiles, ',下载文件总数量:', totalFiles, ',已下载大小:', convertDownloadedBytes, ',下载总大小:', convertTotalBytes);
239
+ FWLog.debug(
240
+ '正在更新完成 -> ',
241
+ '下载文件数量:',
242
+ downloadedFiles,
243
+ ',下载文件总数量:',
244
+ totalFiles,
245
+ ',已下载大小:',
246
+ convertDownloadedBytes,
247
+ ',下载总大小:',
248
+ convertTotalBytes,
249
+ );
197
250
  }
198
251
  str = 'UPDATE_FINISHED';
199
252
  needRestart = true;
@@ -234,16 +287,17 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
234
287
  if (needRestart) {
235
288
  FWLog.debug('热更新中结果 needRestart -> ', needRestart);
236
289
  FWLog.debug('下载完成');
237
- this.assetMgr.setEventCallback(null!);
238
- var searchPaths = jsb.fileUtils.getSearchPaths();
239
- var newPaths = this.assetMgr.getLocalManifest().getSearchPaths();
290
+ const searchPaths = jsb.fileUtils.getSearchPaths();
291
+ const newPaths = this.assetMgr.getLocalManifest().getSearchPaths();
240
292
  Array.prototype.unshift.apply(searchPaths, newPaths);
241
293
  jsb.fileUtils.setSearchPaths(searchPaths);
242
294
  this.isRetry = false;
243
295
  this.isUpdate = false;
244
- this.assetMgr = null;
245
- this.listener.completedHandle?.(this.newVersion);
246
296
 
297
+ this.reloadLocalManifest();
298
+
299
+ this.assetMgr.setEventCallback(null!);
300
+ this.listener.completedHandle?.(this.newVersion);
247
301
  }
248
302
  }
249
303
 
@@ -258,6 +312,6 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
258
312
  return `${size.toFixed(size < 10 ? 2 : 1)} ${units[unitIndex]}`;
259
313
  }
260
314
 
261
- public initialize(): void { }
262
- public onDestroy(): void { }
315
+ public initialize(): void {}
316
+ public onDestroy(): void {}
263
317
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [