react-native-update 10.37.2 → 10.37.4

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.
@@ -23,7 +23,7 @@ export function reactNativeUpdatePlugin() {
23
23
  }
24
24
 
25
25
  const metaContent = {
26
- pushy_build_time: Date.now(),
26
+ pushy_build_time: String(Date.now()),
27
27
  versionName,
28
28
  };
29
29
 
@@ -193,9 +193,13 @@ export class DownloadTask {
193
193
  }
194
194
  const obj = JSON.parse(jsonContent);
195
195
 
196
- const copies = obj.copies;
197
- for (const to in copies) {
198
- let from = copies[to].replace('resources/rawfile/', '');
196
+ const copies = obj.copies as Record<string, string>;
197
+ for (const [to, rawPath] of Object.entries(copies)) {
198
+ if (!rawPath.startsWith('resources/rawfile/')) {
199
+ // skip other resource
200
+ continue;
201
+ }
202
+ let from = rawPath.replace('resources/rawfile/', '');
199
203
  if (from === '') {
200
204
  from = to;
201
205
  }
@@ -355,10 +359,12 @@ export class DownloadTask {
355
359
  private async copyFromResource(
356
360
  copyList: Map<string, Array<string>>,
357
361
  ): Promise<void> {
362
+ let currentFrom = '';
358
363
  try {
359
364
  const resourceManager = this.context.resourceManager;
360
365
 
361
366
  for (const [from, targets] of copyList.entries()) {
367
+ currentFrom = from;
362
368
  const fromContent = await resourceManager.getRawFileContent(from);
363
369
  for (const target of targets) {
364
370
  const fileStream = fileIo.createStreamSync(target, 'w+');
@@ -367,7 +373,7 @@ export class DownloadTask {
367
373
  }
368
374
  }
369
375
  } catch (error) {
370
- console.error('Copy from resource failed:', error);
376
+ console.error('Copy from resource failed:', currentFrom, error.message);
371
377
  throw error;
372
378
  }
373
379
  }
@@ -427,9 +433,8 @@ export class DownloadTask {
427
433
  throw Error(`Unknown task type: ${params.type}`);
428
434
  }
429
435
 
430
- params.listener?.onDownloadCompleted(params);
431
436
  } catch (error) {
432
- console.error('Task execution failed:', error);
437
+ console.error('Task execution failed:', error.message);
433
438
  if (params.type !== DownloadTaskParams.TASK_TYPE_CLEANUP) {
434
439
  try {
435
440
  if (params.type === DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD) {
@@ -438,10 +443,10 @@ export class DownloadTask {
438
443
  await this.removeDirectory(params.unzipDirectory);
439
444
  }
440
445
  } catch (cleanupError) {
441
- console.error('Cleanup after error failed:', cleanupError);
446
+ console.error('Cleanup after error failed:', cleanupError.message);
442
447
  }
443
448
  }
444
- params.listener?.onDownloadFailed(error);
449
+ throw error;
445
450
  }
446
451
  }
447
452
  }
@@ -1,25 +1,19 @@
1
- export interface DownloadTaskListener {
2
- onDownloadCompleted(params: DownloadTaskParams): void;
3
- onDownloadFailed(error: Error): void;
4
- }
5
-
6
1
  /**
7
2
  * 下载任务参数类
8
3
  */
9
4
  export class DownloadTaskParams {
10
5
  // 任务类型常量
11
- static readonly TASK_TYPE_CLEANUP: number = 0; // 保留hash和originHash
12
- static readonly TASK_TYPE_PATCH_FULL: number = 1; // 全量补丁
6
+ static readonly TASK_TYPE_CLEANUP: number = 0; // 保留hash和originHash
7
+ static readonly TASK_TYPE_PATCH_FULL: number = 1; // 全量补丁
13
8
  static readonly TASK_TYPE_PATCH_FROM_APP: number = 2; // 从APP补丁
14
9
  static readonly TASK_TYPE_PATCH_FROM_PPK: number = 3; // 从PPK补丁
15
10
  static readonly TASK_TYPE_PLAIN_DOWNLOAD: number = 4; // 普通下载
16
11
 
17
- type: number; // 任务类型
18
- url: string; // 下载URL
19
- hash: string; // 文件哈希值
20
- originHash: string; // 原始文件哈希值
21
- targetFile: string; // 目标文件路径
22
- unzipDirectory: string; // 解压目录路径
23
- originDirectory: string; // 原始文件目录路径
24
- listener: DownloadTaskListener; // 下载监听器
25
- }
12
+ type: number; // 任务类型
13
+ url: string; // 下载URL
14
+ hash: string; // 文件哈希值
15
+ originHash: string; // 原始文件哈希值
16
+ targetFile: string; // 目标文件路径
17
+ unzipDirectory: string; // 解压目录路径
18
+ originDirectory: string; // 原始文件目录路径
19
+ }
@@ -89,23 +89,19 @@ export class UpdateContext {
89
89
  this.cleanUp();
90
90
  }
91
91
 
92
- public async downloadFullUpdate(
93
- url: string,
94
- hash: string,
95
- listener: DownloadFileListener,
96
- ): Promise<void> {
92
+ public async downloadFullUpdate(url: string, hash: string): Promise<void> {
97
93
  try {
98
94
  const params = new DownloadTaskParams();
99
95
  params.type = DownloadTaskParams.TASK_TYPE_PATCH_FULL;
100
96
  params.url = url;
101
97
  params.hash = hash;
102
- params.listener = listener;
103
98
  params.targetFile = `${this.rootDir}/${hash}.ppk`;
104
99
  params.unzipDirectory = `${this.rootDir}/${hash}`;
105
100
  const downloadTask = new DownloadTask(this.context);
106
101
  await downloadTask.execute(params);
107
102
  } catch (e) {
108
103
  console.error('Failed to download full update:', e);
104
+ throw e;
109
105
  }
110
106
  }
111
107
 
@@ -113,13 +109,11 @@ export class UpdateContext {
113
109
  url: string,
114
110
  hash: string,
115
111
  fileName: string,
116
- listener: DownloadFileListener,
117
112
  ): Promise<void> {
118
113
  const params = new DownloadTaskParams();
119
114
  params.type = DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD;
120
115
  params.url = url;
121
116
  params.hash = hash;
122
- params.listener = listener;
123
117
  params.targetFile = this.rootDir + '/' + fileName;
124
118
 
125
119
  const downloadTask = new DownloadTask(this.context);
@@ -130,14 +124,12 @@ export class UpdateContext {
130
124
  url: string,
131
125
  hash: string,
132
126
  originHash: string,
133
- listener: DownloadFileListener,
134
127
  ): Promise<void> {
135
128
  const params = new DownloadTaskParams();
136
129
  params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
137
130
  params.url = url;
138
131
  params.hash = hash;
139
132
  params.originHash = originHash;
140
- params.listener = listener;
141
133
  params.targetFile = `${this.rootDir}/${originHash}_${hash}.ppk.patch`;
142
134
  params.unzipDirectory = `${this.rootDir}/${hash}`;
143
135
  params.originDirectory = `${this.rootDir}/${params.originHash}`;
@@ -149,21 +141,19 @@ export class UpdateContext {
149
141
  public async downloadPatchFromPackage(
150
142
  url: string,
151
143
  hash: string,
152
- listener: DownloadFileListener,
153
144
  ): Promise<void> {
154
145
  try {
155
146
  const params = new DownloadTaskParams();
156
147
  params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APP;
157
148
  params.url = url;
158
149
  params.hash = hash;
159
- params.listener = listener;
160
150
  params.targetFile = `${this.rootDir}/${hash}.app.patch`;
161
151
  params.unzipDirectory = `${this.rootDir}/${hash}`;
162
152
 
163
153
  const downloadTask = new DownloadTask(this.context);
164
154
  return await downloadTask.execute(params);
165
155
  } catch (e) {
166
- console.error('Failed to download APK patch:', e);
156
+ console.error('Failed to download package patch:', e);
167
157
  throw e;
168
158
  }
169
159
  }
@@ -186,6 +176,7 @@ export class UpdateContext {
186
176
  this.setKv('rolledBackVersion', '');
187
177
  } catch (e) {
188
178
  console.error('Failed to switch version:', e);
179
+ throw e;
189
180
  }
190
181
  }
191
182
 
@@ -269,8 +260,3 @@ export class UpdateContext {
269
260
  return UpdateContext.isUsingBundleUrl;
270
261
  }
271
262
  }
272
-
273
- export interface DownloadFileListener {
274
- onDownloadCompleted(params: DownloadTaskParams): void;
275
- onDownloadFailed(error: Error): void;
276
- }
@@ -1,7 +1,6 @@
1
1
  import bundleManager from '@ohos.bundle.bundleManager';
2
2
  import common from '@ohos.app.ability.common';
3
3
  import { UpdateContext } from './UpdateContext';
4
- import { DownloadTaskParams } from './DownloadTaskParams';
5
4
  import logger from './Logger';
6
5
 
7
6
  const TAG = 'UpdateModuleImpl';
@@ -13,89 +12,28 @@ export class UpdateModuleImpl {
13
12
  updateContext: UpdateContext,
14
13
  options: { updateUrl: string; hash: string },
15
14
  ): Promise<void> {
16
- try {
17
- await updateContext.downloadFullUpdate(options.updateUrl, options.hash, {
18
- onDownloadCompleted: (params: DownloadTaskParams) => {
19
- return Promise.resolve();
20
- },
21
- onDownloadFailed: (error: Error) => {
22
- return Promise.reject(error);
23
- },
24
- });
25
- } catch (error) {
26
- logger.error(TAG, `downloadFullUpdate failed: ${error}`);
27
- throw error;
28
- }
29
- }
30
-
31
- static async downloadAndInstallApk(
32
- context: common.UIAbilityContext,
33
- options: { url: string; hash: string; target: string },
34
- ): Promise<void> {
35
- try {
36
- const want = {
37
- action: 'action.system.home',
38
- parameters: {
39
- uri: 'appmarket://details',
40
- },
41
- };
42
-
43
- if (!context) {
44
- throw Error('获取context失败');
45
- }
46
-
47
- await context.startAbility(want);
48
- } catch (error) {
49
- logger.error(TAG, `installApk failed: ${error}`);
50
- throw error;
51
- }
15
+ return updateContext.downloadFullUpdate(options.updateUrl, options.hash);
52
16
  }
53
17
 
54
18
  static async downloadPatchFromPackage(
55
19
  updateContext: UpdateContext,
56
20
  options: { updateUrl: string; hash: string },
57
21
  ): Promise<void> {
58
- try {
59
- return await updateContext.downloadPatchFromPackage(
60
- options.updateUrl,
61
- options.hash,
62
- {
63
- onDownloadCompleted: (params: DownloadTaskParams) => {
64
- return Promise.resolve();
65
- },
66
- onDownloadFailed: (error: Error) => {
67
- return Promise.reject(error);
68
- },
69
- },
70
- );
71
- } catch (error) {
72
- logger.error(TAG, `downloadPatchFromPackage failed: ${error}`);
73
- throw error;
74
- }
22
+ return updateContext.downloadPatchFromPackage(
23
+ options.updateUrl,
24
+ options.hash,
25
+ );
75
26
  }
76
27
 
77
28
  static async downloadPatchFromPpk(
78
29
  updateContext: UpdateContext,
79
30
  options: { updateUrl: string; hash: string; originHash: string },
80
31
  ): Promise<void> {
81
- try {
82
- await updateContext.downloadPatchFromPpk(
83
- options.updateUrl,
84
- options.hash,
85
- options.originHash,
86
- {
87
- onDownloadCompleted: (params: DownloadTaskParams) => {
88
- return Promise.resolve();
89
- },
90
- onDownloadFailed: (error: Error) => {
91
- return Promise.reject(error);
92
- },
93
- },
94
- );
95
- } catch (error) {
96
- logger.error(TAG, `downloadPatchFromPpk failed: ${error}`);
97
- throw Error(`执行报错: ${error.message}`);
98
- }
32
+ return updateContext.downloadPatchFromPpk(
33
+ options.updateUrl,
34
+ options.hash,
35
+ options.originHash,
36
+ );
99
37
  }
100
38
 
101
39
  static async reloadUpdate(
@@ -121,7 +59,7 @@ export class UpdateModuleImpl {
121
59
  await context.startAbility(want);
122
60
  } catch (error) {
123
61
  logger.error(TAG, `reloadUpdate failed: ${error}`);
124
- throw Error(`pushy:switchVersion failed ${error.message}`);
62
+ throw Error(`switchVersion failed ${error.message}`);
125
63
  }
126
64
  }
127
65
 
@@ -156,14 +94,8 @@ export class UpdateModuleImpl {
156
94
  static async setUuid(
157
95
  updateContext: UpdateContext,
158
96
  uuid: string,
159
- ): Promise<boolean> {
160
- try {
161
- await updateContext.setKv('uuid', uuid);
162
- return true;
163
- } catch (error) {
164
- logger.error(TAG, `setUuid failed: ${error}`);
165
- throw Error(`执行报错: ${error.message}`);
166
- }
97
+ ): Promise<void> {
98
+ return updateContext.setKv('uuid', uuid);
167
99
  }
168
100
 
169
101
  static checkJson(json: string): boolean {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.37.2",
3
+ "version": "10.37.4",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/locales/en.ts CHANGED
@@ -70,7 +70,7 @@ export default {
70
70
 
71
71
  // Development environment messages
72
72
  dev_incremental_update_disabled:
73
- 'Currently in development environment, incremental hot update cannot be executed and restart will not take effect. If you need to test effective full hot update in development environment (but will reconnect to metro after restart), please enable "ignore timestamp" switch and retry.',
73
+ 'Currently in development environment, incremental hot update cannot be executed and restart will not take effect. If you need to test effective full hot update in development environment (but will reconnect to metro after restart), please enable "ignore timestamp" in app settings in admin dashboard and retry.',
74
74
 
75
75
  // Context error messages
76
76
  error_use_update_outside_provider:
package/src/locales/zh.ts CHANGED
@@ -67,7 +67,7 @@ export default {
67
67
 
68
68
  // Development environment messages
69
69
  dev_incremental_update_disabled:
70
- '当前是开发环境,无法执行增量式热更新,重启不会生效。如果需要在开发环境中测试可生效的全量热更新(但也会在再次重启后重新连接 metro),请打开"忽略时间戳"开关再重试。',
70
+ '当前是开发环境,无法执行增量式热更新,重启不会生效。如果需要在开发环境中测试可生效的全量热更新(但也会在再次重启后重新连接 metro),请在网页管理后台的应用设置中打开"忽略时间戳"开关再重试。',
71
71
 
72
72
  // Context error messages
73
73
  error_use_update_outside_provider:
package/src/provider.tsx CHANGED
@@ -162,7 +162,7 @@ export const UpdateProvider = ({
162
162
  );
163
163
 
164
164
  const checkUpdate = useCallback(
165
- async ({ extra }: { extra?: Record<string, any> } | undefined = {}) => {
165
+ async ({ extra }: { extra?: Partial<{ toHash: string }> } = {}) => {
166
166
  const now = Date.now();
167
167
  if (lastChecking.current && now - lastChecking.current < 1000) {
168
168
  return;
@@ -197,7 +197,9 @@ export const UpdateProvider = ({
197
197
  }
198
198
  log(`${info.name} in ${rollout}% rollout, continue`);
199
199
  }
200
- info.description = info.description ?? '';
200
+ if (info.update) {
201
+ info.description = info.description ?? '';
202
+ }
201
203
  updateInfoRef.current = info;
202
204
  setUpdateInfo(info);
203
205
  if (info.expired) {
@@ -250,7 +252,7 @@ export const UpdateProvider = ({
250
252
  client.t('alert_title'),
251
253
  client.t('alert_new_version_found', {
252
254
  name: info.name!,
253
- description: info.description,
255
+ description: info.description!,
254
256
  }),
255
257
  [
256
258
  { text: client.t('alert_cancel'), style: 'cancel' },
package/src/type.ts CHANGED
@@ -98,10 +98,10 @@ export interface ClientOptions {
98
98
  dismissErrorAfter?: number;
99
99
  debug?: boolean;
100
100
  throwError?: boolean;
101
- beforeCheckUpdate?: () => Promise<boolean>;
102
- beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
103
- afterDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
104
- onPackageExpired?: (info: CheckResult) => Promise<boolean>;
101
+ beforeCheckUpdate?: () => Promise<boolean> | boolean;
102
+ beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean> | boolean;
103
+ afterDownloadUpdate?: (info: CheckResult) => Promise<boolean> | boolean;
104
+ onPackageExpired?: (info: CheckResult) => Promise<boolean> | boolean;
105
105
  overridePackageVersion?: string;
106
106
  }
107
107