@ives_xxz/framework 2.3.5 → 2.3.7

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.
@@ -1,8 +1,11 @@
1
- import { FWManager } from './FWManager';
1
+ import { FWManager } from "./FWManager";
2
2
 
3
- const TEMOTE_ASSET = 'remote-asset';
3
+ const TEMOTE_ASSET = "remote-asset";
4
4
 
5
- export default class FWHotUpdateManager extends FWManager implements FW.HotUpdateManager {
5
+ export default class FWHotUpdateManager
6
+ extends FWManager
7
+ implements FW.HotUpdateManager
8
+ {
6
9
  private listener: FW.HotUpdateListener;
7
10
  private assetMgr: any;
8
11
  private storePath: string;
@@ -14,19 +17,29 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
14
17
 
15
18
  setListener(listener: FW.HotUpdateListener): FW.HotUpdateManager {
16
19
  this.listener = listener;
17
- FW.Log.debug('热更新监听设置');
20
+ FW.Log.debug("热更新监听设置");
18
21
  return this;
19
22
  }
20
23
 
21
24
  public update(localManifest: cc.Asset) {
22
25
  if (!localManifest) {
23
- FW.Log.error('没有找到本地Manifest文件!');
26
+ FW.Log.error("没有找到本地Manifest文件!");
24
27
  return;
25
28
  }
26
- FW.Log.debug('开始热更新流程');
29
+
30
+ const loadManifest = jsb.fileUtils.getStringFromFile(
31
+ localManifest.nativeUrl,
32
+ );
33
+ const manifestObject = JSON.parse(loadManifest);
34
+
35
+ FW.Log.debug("开始热更新流程:", manifestObject?.packageUrl);
27
36
  this.localManifest = localManifest;
28
- this.storePath = `${jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/'}${TEMOTE_ASSET}`;
29
- this.assetMgr = new jsb.AssetsManager('', this.storePath, this.versionCompareHandle.bind(this));
37
+ this.storePath = `${jsb.fileUtils ? jsb.fileUtils.getWritablePath() : "/"}${TEMOTE_ASSET}`;
38
+ this.assetMgr = new jsb.AssetsManager(
39
+ "",
40
+ this.storePath,
41
+ this.versionCompareHandle.bind(this),
42
+ );
30
43
  this.assetMgr.setVerifyCallback(function (path: string, asset: any) {
31
44
  const compressed = asset.compressed;
32
45
  const expectedMD5 = asset.md5;
@@ -41,16 +54,19 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
41
54
  this.checkHotUpdate();
42
55
  }
43
56
 
44
- private versionCompareHandle(currentVersion: string, newVersion: string): number {
45
- FW.Log.debug('版本比较', currentVersion, newVersion);
57
+ private versionCompareHandle(
58
+ currentVersion: string,
59
+ newVersion: string,
60
+ ): number {
61
+ FW.Log.debug("版本比较", currentVersion, newVersion);
46
62
  this.currentVersion = currentVersion;
47
63
  this.newVersion = newVersion;
48
64
  this.listener.versionCompareHandle(this.currentVersion, this.newVersion);
49
- var vA = currentVersion.split('.');
50
- var vB = newVersion.split('.');
65
+ var vA = currentVersion.split(".");
66
+ var vB = newVersion.split(".");
51
67
  for (var i = 0; i < vA.length; ++i) {
52
68
  var a = parseInt(vA[i]);
53
- var b = parseInt(vB[i] || '0');
69
+ var b = parseInt(vB[i] || "0");
54
70
  if (a === b) {
55
71
  continue;
56
72
  } else {
@@ -73,7 +89,7 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
73
89
  }
74
90
 
75
91
  private checkHotUpdate() {
76
- FW.Log.debug('checkHotUpdate1', this.isUpdate);
92
+ FW.Log.debug("checkHotUpdate1", this.isUpdate);
77
93
  if (this.isUpdate) {
78
94
  return;
79
95
  }
@@ -81,17 +97,26 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
81
97
  this.assetMgr.loadLocalManifest(this.localManifest.nativeUrl);
82
98
  }
83
99
 
84
- FW.Log.debug('checkHotUpdate3', this.assetMgr.getLocalManifest());
100
+ FW.Log.debug("checkHotUpdate3", this.assetMgr.getLocalManifest());
85
101
 
86
- FW.Log.debug('checkHotUpdate4', this.assetMgr.getLocalManifest().isLoaded());
102
+ FW.Log.debug(
103
+ "checkHotUpdate4",
104
+ this.assetMgr.getLocalManifest().isLoaded(),
105
+ );
87
106
 
88
- if (!this.assetMgr.getLocalManifest() || !this.assetMgr.getLocalManifest().isLoaded()) {
89
- FW.Log.debug('本地manifest未加载,尝试重新加载');
107
+ if (
108
+ !this.assetMgr.getLocalManifest() ||
109
+ !this.assetMgr.getLocalManifest().isLoaded()
110
+ ) {
111
+ FW.Log.debug("本地manifest未加载,尝试重新加载");
90
112
  this.reloadLocalManifest();
91
113
 
92
114
  // 如果仍然无法加载,则返回
93
- if (!this.assetMgr.getLocalManifest() || !this.assetMgr.getLocalManifest().isLoaded()) {
94
- FW.Log.error('无法加载本地manifest文件');
115
+ if (
116
+ !this.assetMgr.getLocalManifest() ||
117
+ !this.assetMgr.getLocalManifest().isLoaded()
118
+ ) {
119
+ FW.Log.error("无法加载本地manifest文件");
95
120
  return;
96
121
  }
97
122
  }
@@ -107,38 +132,41 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
107
132
  if (jsb.fileUtils.isFileExist(updatedManifestPath)) {
108
133
  this.assetMgr.loadLocalManifest(updatedManifestPath);
109
134
 
110
- if (this.assetMgr.getLocalManifest() && this.assetMgr.getLocalManifest().isLoaded()) {
111
- FW.Log.debug('本地manifest重新加载成功');
135
+ if (
136
+ this.assetMgr.getLocalManifest() &&
137
+ this.assetMgr.getLocalManifest().isLoaded()
138
+ ) {
139
+ FW.Log.debug("本地manifest重新加载成功");
112
140
  this.localManifest = this.assetMgr.getLocalManifest();
113
141
  } else {
114
- FW.Log.error('本地manifest重新加载失败');
142
+ FW.Log.error("本地manifest重新加载失败");
115
143
  }
116
144
  } else {
117
- FW.Log.error('更新后的manifest文件不存在:', updatedManifestPath);
145
+ FW.Log.error("更新后的manifest文件不存在:", updatedManifestPath);
118
146
  }
119
147
  } catch (error) {
120
- FW.Log.error('重新加载本地manifest时出错:', error);
148
+ FW.Log.error("重新加载本地manifest时出错:", error);
121
149
  }
122
150
  }
123
151
 
124
152
  private checkEventHandle(event: any) {
125
153
  const code = event.getEventCode();
126
- FW.Log.debug('checkEvent getEventCode -> ', code);
154
+ FW.Log.debug("checkEvent getEventCode -> ", code);
127
155
  switch (code) {
128
156
  case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
129
- FW.Log.debug('checkEvent getEventCode -> ', 'ERROR_NO_LOCAL_MANIFEST');
157
+ FW.Log.debug("checkEvent getEventCode -> ", "ERROR_NO_LOCAL_MANIFEST");
130
158
  break;
131
159
  case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
132
- FW.Log.debug('checkEvent getEventCode -> ', 'ERROR_DOWNLOAD_MANIFEST');
160
+ FW.Log.debug("checkEvent getEventCode -> ", "ERROR_DOWNLOAD_MANIFEST");
133
161
  break;
134
162
  case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
135
- FW.Log.debug('checkEvent getEventCode -> ', 'ERROR_PARSE_MANIFEST');
163
+ FW.Log.debug("checkEvent getEventCode -> ", "ERROR_PARSE_MANIFEST");
136
164
  break;
137
165
  case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
138
- FW.Log.debug('checkEvent getEventCode -> ', 'ALREADY_UP_TO_DATE');
166
+ FW.Log.debug("checkEvent getEventCode -> ", "ALREADY_UP_TO_DATE");
139
167
  break;
140
168
  case jsb.EventAssetsManager.NEW_VERSION_FOUND:
141
- FW.Log.debug('checkEvent getEventCode -> ', 'NEW_VERSION_FOUND');
169
+ FW.Log.debug("checkEvent getEventCode -> ", "NEW_VERSION_FOUND");
142
170
  break;
143
171
  default:
144
172
  return;
@@ -148,7 +176,7 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
148
176
  this.assetMgr.setEventCallback(null!);
149
177
  this.isUpdate = false;
150
178
  FW.Log.debug(
151
- 'isFind New Version -> ',
179
+ "isFind New Version -> ",
152
180
  event.getEventCode() == jsb.EventAssetsManager.NEW_VERSION_FOUND,
153
181
  );
154
182
  if (event.getEventCode() == jsb.EventAssetsManager.NEW_VERSION_FOUND) {
@@ -157,11 +185,11 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
157
185
  }
158
186
 
159
187
  private hotUpdate() {
160
- FW.Log.debug('start hotUpdate ->', this.assetMgr, this.isUpdate);
188
+ FW.Log.debug("start hotUpdate ->", this.assetMgr, this.isUpdate);
161
189
  if (this.assetMgr && !this.isUpdate) {
162
190
  this.assetMgr.setEventCallback(this.updateEventHandle.bind(this));
163
191
  FW.Log.debug(
164
- 'assetMgr state ->',
192
+ "assetMgr state ->",
165
193
  this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED,
166
194
  );
167
195
  if (this.assetMgr.getState() === jsb.AssetsManager.State.UNINITED) {
@@ -180,20 +208,20 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
180
208
  let totalFiles: number = 0;
181
209
  let downloadedBytes: number = 0;
182
210
  let totalBytes: number = 0;
183
- let convertDownloadedBytes: string = '';
184
- let convertTotalBytes: string = '';
211
+ let convertDownloadedBytes: string = "";
212
+ let convertTotalBytes: string = "";
185
213
  const code = event.getEventCode();
186
214
  const msg = event.getMessage();
187
- FW.Log.debug('updateEvent getEventCode -> ', code);
188
- let str = '';
215
+ FW.Log.debug("updateEvent getEventCode -> ", code);
216
+ let str = "";
189
217
  switch (code) {
190
218
  case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
191
219
  failed = true;
192
- str = 'ERROR_NO_LOCAL_MANIFEST';
220
+ str = "ERROR_NO_LOCAL_MANIFEST";
193
221
  break;
194
222
  case jsb.EventAssetsManager.UPDATE_PROGRESSION:
195
- str = 'UPDATE_PROGRESSION';
196
- FW.Log.debug('updateEvent percent -> ', event.getPercent());
223
+ str = "UPDATE_PROGRESSION";
224
+ FW.Log.debug("updateEvent percent -> ", event.getPercent());
197
225
  if (event.getPercent() > 0) {
198
226
  downloadedFiles = event.getDownloadedFiles();
199
227
  totalFiles = event.getTotalFiles();
@@ -203,27 +231,27 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
203
231
  convertTotalBytes = this.convertBytes(totalBytes);
204
232
  percent = event.getPercent();
205
233
  FW.Log.debug(
206
- '正在更新中 -> ',
207
- '下载文件数量:',
234
+ "正在更新中 -> ",
235
+ "下载文件数量:",
208
236
  downloadedFiles,
209
- ',下载文件总数量:',
237
+ ",下载文件总数量:",
210
238
  totalFiles,
211
- ',已下载大小:',
239
+ ",已下载大小:",
212
240
  convertDownloadedBytes,
213
- ',下载总大小:',
241
+ ",下载总大小:",
214
242
  convertTotalBytes,
215
243
  );
216
244
  }
217
245
  break;
218
246
  case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
219
- str = 'ERROR_DOWNLOAD_MANIFEST';
247
+ str = "ERROR_DOWNLOAD_MANIFEST";
220
248
  break;
221
249
  case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
222
- str = 'ERROR_PARSE_MANIFEST';
250
+ str = "ERROR_PARSE_MANIFEST";
223
251
  failed = true;
224
252
  break;
225
253
  case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
226
- str = 'ALREADY_UP_TO_DATE';
254
+ str = "ALREADY_UP_TO_DATE";
227
255
  failed = true;
228
256
  break;
229
257
  case jsb.EventAssetsManager.UPDATE_FINISHED:
@@ -236,37 +264,37 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
236
264
  convertTotalBytes = this.convertBytes(totalBytes);
237
265
  percent = event.getPercent();
238
266
  FW.Log.debug(
239
- '正在更新完成 -> ',
240
- '下载文件数量:',
267
+ "正在更新完成 -> ",
268
+ "下载文件数量:",
241
269
  downloadedFiles,
242
- ',下载文件总数量:',
270
+ ",下载文件总数量:",
243
271
  totalFiles,
244
- ',已下载大小:',
272
+ ",已下载大小:",
245
273
  convertDownloadedBytes,
246
- ',下载总大小:',
274
+ ",下载总大小:",
247
275
  convertTotalBytes,
248
276
  );
249
277
  }
250
- str = 'UPDATE_FINISHED';
278
+ str = "UPDATE_FINISHED";
251
279
  needRestart = true;
252
280
  break;
253
281
  case jsb.EventAssetsManager.UPDATE_FAILED:
254
- str = 'UPDATE_FAILED';
282
+ str = "UPDATE_FAILED";
255
283
  this.isUpdate = false;
256
284
  this.isRetry = true;
257
285
  break;
258
286
  case jsb.EventAssetsManager.ERROR_UPDATING:
259
- str = 'ERROR_UPDATING';
287
+ str = "ERROR_UPDATING";
260
288
  break;
261
289
  case jsb.EventAssetsManager.ERROR_DECOMPRESS:
262
- str = 'ERROR_DECOMPRESS';
290
+ str = "ERROR_DECOMPRESS";
263
291
  break;
264
292
  default:
265
293
  break;
266
294
  }
267
295
 
268
- FW.Log.debug('热更新中->', str);
269
- FW.Log.debug('热更新msg ->', msg);
296
+ FW.Log.debug("热更新中->", str);
297
+ FW.Log.debug("热更新msg ->", msg);
270
298
  this.listener.hotUpdatingHandle?.(code, {
271
299
  percent: percent,
272
300
  downloadedFiles: downloadedFiles,
@@ -277,15 +305,15 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
277
305
  convertTotalBytes: convertTotalBytes,
278
306
  });
279
307
  if (failed) {
280
- FW.Log.debug('热更新中结果 failed -> ', failed);
281
- FW.Log.debug('下载失败');
308
+ FW.Log.debug("热更新中结果 failed -> ", failed);
309
+ FW.Log.debug("下载失败");
282
310
  this.assetMgr.setEventCallback(null!);
283
311
  this.isUpdate = false;
284
312
  this.retry();
285
313
  }
286
314
  if (needRestart) {
287
- FW.Log.debug('热更新中结果 needRestart -> ', needRestart);
288
- FW.Log.debug('下载完成');
315
+ FW.Log.debug("热更新中结果 needRestart -> ", needRestart);
316
+ FW.Log.debug("下载完成");
289
317
  const searchPaths = jsb.fileUtils.getSearchPaths();
290
318
  const newPaths = this.assetMgr.getLocalManifest().getSearchPaths();
291
319
  Array.prototype.unshift.apply(searchPaths, newPaths);
@@ -301,7 +329,7 @@ export default class FWHotUpdateManager extends FWManager implements FW.HotUpdat
301
329
  }
302
330
 
303
331
  private convertBytes(bytes: number) {
304
- const units = ['B', 'KB', 'MB', 'GB'];
332
+ const units = ["B", "KB", "MB", "GB"];
305
333
  let size = bytes,
306
334
  unitIndex = 0;
307
335
  while (size >= 1024 && unitIndex < units.length - 1) {
@@ -1,8 +1,8 @@
1
- import { FWSystemConfig } from "../config/FWSystemConfig";
2
- import { FWLodash } from "../utils/FWLodash";
3
- import { FWAssetManager } from "./FWAssetManager";
4
- import { FWBundleManager } from "./FWBundleManager";
5
- import { FWManager } from "./FWManager";
1
+ import { FWSystemConfig } from '../config/FWSystemConfig';
2
+ import { FWLodash } from '../utils/FWLodash';
3
+ import { FWAssetManager } from './FWAssetManager';
4
+ import { FWBundleManager } from './FWBundleManager';
5
+ import { FWManager } from './FWManager';
6
6
 
7
7
  export class FWResManager extends FWManager implements FW.ResManager {
8
8
  private bundleMgr: FW.BundleManager;
@@ -22,65 +22,60 @@ export class FWResManager extends FWManager implements FW.ResManager {
22
22
  * @returns
23
23
  */
24
24
  async loadBundle(bundleName: string): Promise<cc.AssetManager.Bundle> {
25
- return await this.invoke<cc.AssetManager.Bundle>(
26
- FW.Entry.promiseMgr.execute(async (resolve, reject, signal) => {
25
+ return new Promise(async (resolve, reject) => {
26
+ try {
27
27
  const depends = FWLodash.cloneDeep(FW.Entry.getDepend(bundleName));
28
- try {
29
- if (depends && depends.length > 0) {
30
- for (const depend of depends) {
31
- if (depend === undefined) continue;
28
+ if (depends && depends.length > 0) {
29
+ for (const depend of depends) {
30
+ if (depend === undefined) continue;
32
31
 
33
- if (this.bundleMgr.has(depend)) continue;
32
+ if (this.bundleMgr.has(depend)) continue;
34
33
 
35
- await this.loadBundle(depend);
34
+ await this.loadBundle(depend);
36
35
 
37
- const config = FW.Entry.getComponent<FW.AssetConfig>(
38
- `${depend}${FW.SystemDefine.FWBindTag.CONFIG}`,
39
- );
40
- if (!config) continue;
41
- const preLoad = config.preLoad;
42
- const keys = Object.keys(preLoad);
36
+ const config = FW.Entry.getComponent<FW.AssetConfig>(
37
+ `${depend}${FW.SystemDefine.FWBindTag.CONFIG}`,
38
+ );
39
+ if (!config) continue;
40
+ const preLoad = config.preLoad;
41
+ const keys = Object.keys(preLoad);
43
42
 
44
- if (keys.length > 0) {
45
- const preloadRecursive = async (
46
- obj: FW.LoadConfig | FW.AssetProperty,
47
- ) => {
48
- for (const key of Object.keys(obj)) {
49
- const value: any = (obj as any)[key];
43
+ if (keys.length > 0) {
44
+ const preloadRecursive = async (obj: FW.LoadConfig | FW.AssetProperty) => {
45
+ for (const key of Object.keys(obj)) {
46
+ const value: any = (obj as any)[key];
50
47
 
51
- if (value && typeof value.path === "string") {
52
- const path: string = value.path;
53
- const type: string = value.type;
54
- const d: string = value.bundle || depend;
55
- const priorityLoaded = value.priorityLoaded || false;
48
+ if (value && typeof value.path === 'string') {
49
+ const path: string = value.path;
50
+ const type: string = value.type;
51
+ const d: string = value.bundle || depend;
52
+ const priorityLoaded = value.priorityLoaded || false;
56
53
 
57
- if (path && priorityLoaded) {
58
- await this.assetMgr.load({
59
- path,
60
- bundle: d,
61
- type,
62
- });
63
- }
64
- } else if (value && typeof value === "object") {
65
- await preloadRecursive(value);
54
+ if (path && priorityLoaded) {
55
+ await this.assetMgr.load({
56
+ path,
57
+ bundle: d,
58
+ type,
59
+ });
66
60
  }
61
+ } else if (value && typeof value === 'object') {
62
+ await preloadRecursive(value);
67
63
  }
68
- };
69
- await preloadRecursive(config.preLoad);
70
- }
64
+ }
65
+ };
66
+ await preloadRecursive(config.preLoad);
71
67
  }
72
68
  }
69
+ }
73
70
 
74
- const bundle = await this.bundleMgr.load(bundleName);
71
+ const bundle = await this.bundleMgr.load(bundleName);
75
72
 
76
- resolve(bundle);
77
- } catch (e) {
78
- this.rejectHandlerListener?.loadBundleHandler?.(e, bundleName);
79
- reject(e);
80
- }
81
- }, FWSystemConfig.PromiseConfig.loadBundle).promise,
82
- `loadBundle -> ${bundleName}`,
83
- );
73
+ resolve(bundle);
74
+ } catch (e) {
75
+ this.rejectHandlerListener?.loadBundleHandler?.(e, bundleName);
76
+ reject(e);
77
+ }
78
+ });
84
79
  }
85
80
  /**
86
81
  * 从远程加载spine动画
@@ -96,10 +91,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
96
91
  return await this.assetMgr.loadSpineDataFromRemote(data);
97
92
  }
98
93
 
99
- async loadRemote<T extends cc.Asset = cc.Asset>(
100
- url: string,
101
- texture?: boolean,
102
- ): Promise<T> {
94
+ async loadRemote<T extends cc.Asset = cc.Asset>(url: string, texture?: boolean): Promise<T> {
103
95
  try {
104
96
  const asset = await this.assetMgr.loadRemote(url);
105
97
  if (texture) {
@@ -191,10 +183,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
191
183
  * @param bundleName
192
184
  * @returns
193
185
  */
194
- getAssetData<T extends cc.Asset>(
195
- assetProperty: FW.AssetProperty,
196
- texture?: boolean,
197
- ) {
186
+ getAssetData<T extends cc.Asset>(assetProperty: FW.AssetProperty, texture?: boolean) {
198
187
  const res = this.assetMgr.get(assetProperty);
199
188
  if (texture) {
200
189
  return res;
@@ -206,10 +195,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
206
195
  * @param assetProperty
207
196
  * @returns
208
197
  */
209
- getAsset<T extends cc.Asset>(
210
- assetProperty: FW.AssetProperty,
211
- texture?: boolean,
212
- ): T {
198
+ getAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty, texture?: boolean): T {
213
199
  const res = this.assetMgr.get(assetProperty);
214
200
  if (texture) {
215
201
  return res.asset as T;
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
- "keywords": ["123456"],
6
+ "keywords": [
7
+ "123456"
8
+ ],
7
9
  "author": "ives",
8
10
  "license": "ISC"
9
11
  }