react-native-update 10.37.3 → 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.
- package/harmony/pushy/src/main/ets/DownloadTask.ts +13 -8
- package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +10 -16
- package/harmony/pushy/src/main/ets/UpdateContext.ts +4 -18
- package/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +13 -81
- package/package.json +1 -1
- package/src/locales/en.ts +1 -1
- package/src/locales/zh.ts +1 -1
- package/src/provider.tsx +1 -1
|
@@ -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
|
|
198
|
-
|
|
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
|
-
|
|
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;
|
|
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;
|
|
19
|
-
hash: string;
|
|
20
|
-
originHash: string;
|
|
21
|
-
targetFile: string;
|
|
22
|
-
unzipDirectory: string;
|
|
23
|
-
originDirectory: string;
|
|
24
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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(`
|
|
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<
|
|
160
|
-
|
|
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
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"
|
|
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?:
|
|
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;
|