react-native-update 10.37.13 → 10.37.16
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/README-CN.md +72 -0
- package/README.md +61 -49
- package/android/build.gradle +47 -17
- package/bunfig.toml +2 -0
- package/error.js +1609 -0
- package/harmony/har-wrapper/AppScope/app.json5 +8 -0
- package/harmony/har-wrapper/build-profile.json5 +35 -0
- package/harmony/har-wrapper/hvigor/hvigor-config.json5 +5 -0
- package/harmony/har-wrapper/hvigorfile.ts +6 -0
- package/harmony/har-wrapper/oh-package.json5 +4 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/cache-v2-77b153ce45aba0ed28ef.json +1415 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/cmakeFiles-v1-b65a07793384e0ce3e08.json +809 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/codemodel-v2-ce0e89410afd8bf3a057.json +60 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/directory-.-Release-f5ebdc15457944623624.json +14 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/index-2026-03-16T14-00-08-0134.json +89 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.cmake/api/v1/reply/target-rnupdate-Release-267153624504c9c3ffdd.json +222 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.ninja_deps +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/.ninja_log +8 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeCache.txt +415 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeCCompiler.cmake +74 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeCXXCompiler.cmake +85 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeDetermineCompilerABI_C.bin +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CMakeSystem.cmake +15 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdC/CMakeCCompilerId.c +880 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdC/CMakeCCompilerId.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +869 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/3.28.2/CompilerIdCXX/CMakeCXXCompilerId.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/CMakeConfigureLog.yaml +388 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/TargetDirectories.txt +3 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/cmake.check_cache +1 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/HDiffPatch/file_for_patch.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/HDiffPatch/libHDiffPatch/HPatch/patch.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/hpatch.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/lzma/C/Lzma2Dec.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/__w/react-native-update/react-native-update/android/jni/lzma/C/LzmaDec.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rnupdate.dir/pushy.c.o +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/CMakeFiles/rules.ninja +64 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/additional_project_files.txt +0 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/build.ninja +206 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/build_file_index.txt +1 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/cmake_install.cmake +54 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/compile_commands.json +38 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/configure_fingerprint.json +1 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/hvigor_native_config.json +1 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/metadata_generation_command.txt +17 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/native_work_dir.txt +1 -0
- package/harmony/pushy/.cxx/default/default/release/arm64-v8a/output.log +14 -0
- package/harmony/pushy/.cxx/default/default/release/hvigor/arm64-v8a/summary.cmake +0 -0
- package/harmony/pushy/BuildProfile.ets +3 -5
- package/harmony/pushy/build-profile.json5 +8 -1
- package/harmony/pushy/oh-package-lock.json5 +1 -1
- package/harmony/pushy/src/main/cpp/CMakeLists.txt +42 -30
- package/harmony/pushy/src/main/ets/DownloadTask.ts +145 -106
- package/harmony/pushy/src/main/ets/Logger.ts +24 -7
- package/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets +1 -1
- package/harmony/pushy/src/main/ets/PushyTurboModule.ts +9 -73
- package/harmony/pushy/src/main/ets/UpdateContext.ts +206 -70
- package/harmony/pushy.har +0 -0
- package/package.json +9 -6
- package/scripts/build-harmony-har.js +427 -0
- package/scripts/prepublish.ts +113 -0
- package/scripts/read.js +188 -0
- package/src/__tests__/core.test.ts +103 -0
- package/src/__tests__/setup.ts +37 -0
- package/src/__tests__/utils.test.ts +36 -0
- package/src/client.ts +17 -10
- package/src/core.ts +5 -5
- package/src/locales/en.ts +1 -0
- package/src/locales/zh.ts +1 -0
- package/src/utils.ts +13 -1
|
@@ -51,6 +51,108 @@ export class DownloadTask {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
private async ensureDirectory(path: string): Promise<void> {
|
|
55
|
+
if (!path || fileIo.accessSync(path)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const parentPath = path.substring(0, path.lastIndexOf('/'));
|
|
60
|
+
if (parentPath && parentPath !== path) {
|
|
61
|
+
await this.ensureDirectory(parentPath);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!fileIo.accessSync(path)) {
|
|
65
|
+
await fileIo.mkdir(path);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private async ensureParentDirectory(filePath: string): Promise<void> {
|
|
70
|
+
const parentPath = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
71
|
+
if (!parentPath) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await this.ensureDirectory(parentPath);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private async recreateDirectory(path: string): Promise<void> {
|
|
78
|
+
await this.removeDirectory(path);
|
|
79
|
+
await this.ensureDirectory(path);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async readFileContent(filePath: string): Promise<ArrayBuffer> {
|
|
83
|
+
const stat = await fileIo.stat(filePath);
|
|
84
|
+
const reader = await fileIo.open(filePath, fileIo.OpenMode.READ_ONLY);
|
|
85
|
+
const content = new ArrayBuffer(stat.size);
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
await fileIo.read(reader.fd, content);
|
|
89
|
+
return content;
|
|
90
|
+
} finally {
|
|
91
|
+
await fileIo.close(reader);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private toUint8Array(content: ArrayBuffer | Uint8Array): Uint8Array {
|
|
96
|
+
if (content instanceof Uint8Array) {
|
|
97
|
+
return content;
|
|
98
|
+
}
|
|
99
|
+
return new Uint8Array(content);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private async writeFileContent(
|
|
103
|
+
targetFile: string,
|
|
104
|
+
content: ArrayBuffer | Uint8Array,
|
|
105
|
+
): Promise<void> {
|
|
106
|
+
const payload = this.toUint8Array(content);
|
|
107
|
+
await this.ensureParentDirectory(targetFile);
|
|
108
|
+
if (fileIo.accessSync(targetFile)) {
|
|
109
|
+
await fileIo.unlink(targetFile);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let writer: fileIo.File | null = null;
|
|
113
|
+
try {
|
|
114
|
+
writer = await fileIo.open(
|
|
115
|
+
targetFile,
|
|
116
|
+
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
|
117
|
+
);
|
|
118
|
+
const chunkSize = 4096;
|
|
119
|
+
let bytesWritten = 0;
|
|
120
|
+
|
|
121
|
+
while (bytesWritten < payload.byteLength) {
|
|
122
|
+
const chunk = payload.slice(bytesWritten, bytesWritten + chunkSize);
|
|
123
|
+
await fileIo.write(writer.fd, chunk);
|
|
124
|
+
bytesWritten += chunk.byteLength;
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
if (writer) {
|
|
128
|
+
await fileIo.close(writer);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private parseJsonEntry(content: ArrayBuffer): Record<string, any> {
|
|
134
|
+
return JSON.parse(
|
|
135
|
+
new util.TextDecoder().decodeToString(new Uint8Array(content)),
|
|
136
|
+
) as Record<string, any>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private async applyBundlePatch(
|
|
140
|
+
originContent: ArrayBuffer | Uint8Array,
|
|
141
|
+
patchContent: ArrayBuffer | Uint8Array,
|
|
142
|
+
outputFile: string,
|
|
143
|
+
): Promise<void> {
|
|
144
|
+
try {
|
|
145
|
+
const patched = await Pushy.hdiffPatch(
|
|
146
|
+
this.toUint8Array(originContent),
|
|
147
|
+
this.toUint8Array(patchContent),
|
|
148
|
+
);
|
|
149
|
+
await this.writeFileContent(outputFile, patched);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
error.message = `Failed to process bundle patch: ${error.message}`;
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
54
156
|
private async downloadFile(params: DownloadTaskParams): Promise<void> {
|
|
55
157
|
const httpRequest = http.createHttp();
|
|
56
158
|
this.hash = params.hash;
|
|
@@ -89,14 +191,7 @@ export class DownloadTask {
|
|
|
89
191
|
if (exists) {
|
|
90
192
|
await fileIo.unlink(params.targetFile);
|
|
91
193
|
} else {
|
|
92
|
-
|
|
93
|
-
0,
|
|
94
|
-
params.targetFile.lastIndexOf('/'),
|
|
95
|
-
);
|
|
96
|
-
exists = fileIo.accessSync(targetDir);
|
|
97
|
-
if (!exists) {
|
|
98
|
-
await fileIo.mkdir(targetDir);
|
|
99
|
-
}
|
|
194
|
+
await this.ensureParentDirectory(params.targetFile);
|
|
100
195
|
}
|
|
101
196
|
|
|
102
197
|
writer = await fileIo.open(
|
|
@@ -198,9 +293,7 @@ export class DownloadTask {
|
|
|
198
293
|
|
|
199
294
|
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
|
|
200
295
|
await this.downloadFile(params);
|
|
201
|
-
await this.
|
|
202
|
-
await fileIo.mkdir(params.unzipDirectory);
|
|
203
|
-
|
|
296
|
+
await this.recreateDirectory(params.unzipDirectory);
|
|
204
297
|
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
|
205
298
|
}
|
|
206
299
|
|
|
@@ -243,12 +336,11 @@ export class DownloadTask {
|
|
|
243
336
|
|
|
244
337
|
private async doPatchFromApp(params: DownloadTaskParams): Promise<void> {
|
|
245
338
|
await this.downloadFile(params);
|
|
246
|
-
await this.
|
|
247
|
-
await fileIo.mkdir(params.unzipDirectory);
|
|
339
|
+
await this.recreateDirectory(params.unzipDirectory);
|
|
248
340
|
|
|
249
341
|
let foundDiff = false;
|
|
250
342
|
let foundBundlePatch = false;
|
|
251
|
-
const copyList: Map<string,
|
|
343
|
+
const copyList: Map<string, string[]> = new Map();
|
|
252
344
|
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
|
253
345
|
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
|
254
346
|
for (const entry of zipFile.entries) {
|
|
@@ -256,11 +348,7 @@ export class DownloadTask {
|
|
|
256
348
|
|
|
257
349
|
if (fn === '__diff.json') {
|
|
258
350
|
foundDiff = true;
|
|
259
|
-
const
|
|
260
|
-
const obj = JSON.parse(
|
|
261
|
-
new util.TextDecoder().decodeToString(bufferArray),
|
|
262
|
-
);
|
|
263
|
-
|
|
351
|
+
const obj = this.parseJsonEntry(entry.content);
|
|
264
352
|
const copies = obj.copies as Record<string, string>;
|
|
265
353
|
for (const [to, rawPath] of Object.entries(copies)) {
|
|
266
354
|
let from = rawPath.replace('resources/rawfile/', '');
|
|
@@ -282,35 +370,16 @@ export class DownloadTask {
|
|
|
282
370
|
}
|
|
283
371
|
if (fn === 'bundle.harmony.js.patch') {
|
|
284
372
|
foundBundlePatch = true;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const writer = await fileIo.open(
|
|
296
|
-
outputFile,
|
|
297
|
-
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
|
298
|
-
);
|
|
299
|
-
const chunkSize = 4096;
|
|
300
|
-
let bytesWritten = 0;
|
|
301
|
-
const totalLength = patched.byteLength;
|
|
302
|
-
|
|
303
|
-
while (bytesWritten < totalLength) {
|
|
304
|
-
const chunk = patched.slice(bytesWritten, bytesWritten + chunkSize);
|
|
305
|
-
await fileIo.write(writer.fd, chunk);
|
|
306
|
-
bytesWritten += chunk.byteLength;
|
|
307
|
-
}
|
|
308
|
-
await fileIo.close(writer);
|
|
309
|
-
continue;
|
|
310
|
-
} catch (error) {
|
|
311
|
-
error.message = 'Failed to process bundle patch:' + error.message;
|
|
312
|
-
throw error;
|
|
313
|
-
}
|
|
373
|
+
const resourceManager = this.context.resourceManager;
|
|
374
|
+
const originContent = await resourceManager.getRawFileContent(
|
|
375
|
+
'bundle.harmony.js',
|
|
376
|
+
);
|
|
377
|
+
await this.applyBundlePatch(
|
|
378
|
+
originContent,
|
|
379
|
+
entry.content,
|
|
380
|
+
`${params.unzipDirectory}/bundle.harmony.js`,
|
|
381
|
+
);
|
|
382
|
+
continue;
|
|
314
383
|
}
|
|
315
384
|
}
|
|
316
385
|
|
|
@@ -325,8 +394,7 @@ export class DownloadTask {
|
|
|
325
394
|
|
|
326
395
|
private async doPatchFromPpk(params: DownloadTaskParams): Promise<void> {
|
|
327
396
|
await this.downloadFile(params);
|
|
328
|
-
await this.
|
|
329
|
-
await fileIo.mkdir(params.unzipDirectory);
|
|
397
|
+
await this.recreateDirectory(params.unzipDirectory);
|
|
330
398
|
|
|
331
399
|
let foundDiff = false;
|
|
332
400
|
let foundBundlePatch = false;
|
|
@@ -338,74 +406,43 @@ export class DownloadTask {
|
|
|
338
406
|
if (fn === '__diff.json') {
|
|
339
407
|
foundDiff = true;
|
|
340
408
|
|
|
341
|
-
await fileIo
|
|
342
|
-
|
|
343
|
-
.
|
|
344
|
-
console.error('copy error:', error);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
const bufferArray = new Uint8Array(entry.content);
|
|
348
|
-
const obj = JSON.parse(
|
|
349
|
-
new util.TextDecoder().decodeToString(bufferArray),
|
|
409
|
+
await fileIo.copyDir(
|
|
410
|
+
`${params.originDirectory}/`,
|
|
411
|
+
`${params.unzipDirectory}/`,
|
|
350
412
|
);
|
|
351
413
|
|
|
414
|
+
const obj = this.parseJsonEntry(entry.content);
|
|
415
|
+
|
|
352
416
|
const { copies, deletes } = obj;
|
|
353
417
|
for (const [to, from] of Object.entries(copies)) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
console.error('copy error:', error);
|
|
361
|
-
});
|
|
418
|
+
const targetFile = `${params.unzipDirectory}/${to}`;
|
|
419
|
+
await this.ensureParentDirectory(targetFile);
|
|
420
|
+
await fileIo.copyFile(
|
|
421
|
+
`${params.originDirectory}/${from}`,
|
|
422
|
+
targetFile,
|
|
423
|
+
);
|
|
362
424
|
}
|
|
363
425
|
for (const fileToDelete of Object.keys(deletes)) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
.
|
|
367
|
-
|
|
368
|
-
});
|
|
426
|
+
const targetFile = `${params.unzipDirectory}/${fileToDelete}`;
|
|
427
|
+
if (fileIo.accessSync(targetFile)) {
|
|
428
|
+
await fileIo.unlink(targetFile);
|
|
429
|
+
}
|
|
369
430
|
}
|
|
370
431
|
continue;
|
|
371
432
|
}
|
|
372
433
|
if (fn === 'bundle.harmony.js.patch') {
|
|
373
434
|
foundBundlePatch = true;
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const stat = await fileIo.stat(filePath);
|
|
378
|
-
const reader = await fileIo.open(filePath, fileIo.OpenMode.READ_ONLY);
|
|
379
|
-
const fileSize = stat.size;
|
|
380
|
-
const originContent = new ArrayBuffer(fileSize);
|
|
381
|
-
try {
|
|
382
|
-
await fileIo.read(reader.fd, originContent);
|
|
383
|
-
const patched = await Pushy.hdiffPatch(
|
|
384
|
-
new Uint8Array(originContent),
|
|
385
|
-
new Uint8Array(entry.content),
|
|
386
|
-
);
|
|
387
|
-
const outputFile = `${params.unzipDirectory}/bundle.harmony.js`;
|
|
388
|
-
const writer = await fileIo.open(
|
|
389
|
-
outputFile,
|
|
390
|
-
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
|
391
|
-
);
|
|
392
|
-
const chunkSize = 4096;
|
|
393
|
-
let bytesWritten = 0;
|
|
394
|
-
const totalLength = patched.byteLength;
|
|
395
|
-
while (bytesWritten < totalLength) {
|
|
396
|
-
const chunk = patched.slice(
|
|
397
|
-
bytesWritten,
|
|
398
|
-
bytesWritten + chunkSize,
|
|
399
|
-
);
|
|
400
|
-
await fileIo.write(writer.fd, chunk);
|
|
401
|
-
bytesWritten += chunk.byteLength;
|
|
402
|
-
}
|
|
403
|
-
await fileIo.close(writer);
|
|
404
|
-
continue;
|
|
405
|
-
} finally {
|
|
406
|
-
await fileIo.close(reader);
|
|
407
|
-
}
|
|
435
|
+
const bundlePath = `${params.originDirectory}/bundle.harmony.js`;
|
|
436
|
+
if (!fileIo.accessSync(bundlePath)) {
|
|
437
|
+
throw Error(`Origin bundle not found: ${bundlePath}`);
|
|
408
438
|
}
|
|
439
|
+
const originContent = await this.readFileContent(bundlePath);
|
|
440
|
+
await this.applyBundlePatch(
|
|
441
|
+
originContent,
|
|
442
|
+
entry.content,
|
|
443
|
+
`${params.unzipDirectory}/bundle.harmony.js`,
|
|
444
|
+
);
|
|
445
|
+
continue;
|
|
409
446
|
}
|
|
410
447
|
}
|
|
411
448
|
|
|
@@ -433,6 +470,7 @@ export class DownloadTask {
|
|
|
433
470
|
.split('.')[0];
|
|
434
471
|
const mediaBuffer = await resourceManager.getMediaByName(mediaName);
|
|
435
472
|
for (const target of targets) {
|
|
473
|
+
await this.ensureParentDirectory(target);
|
|
436
474
|
const fileStream = fileIo.createStreamSync(target, 'w+');
|
|
437
475
|
fileStream.writeSync(mediaBuffer.buffer);
|
|
438
476
|
fileStream.close();
|
|
@@ -441,6 +479,7 @@ export class DownloadTask {
|
|
|
441
479
|
}
|
|
442
480
|
const fromContent = await resourceManager.getRawFd(from);
|
|
443
481
|
for (const target of targets) {
|
|
482
|
+
await this.ensureParentDirectory(target);
|
|
444
483
|
saveFileToSandbox(fromContent, target);
|
|
445
484
|
}
|
|
446
485
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import hilog from '@ohos.hilog';
|
|
3
2
|
|
|
4
3
|
class Logger {
|
|
@@ -7,29 +6,47 @@ class Logger {
|
|
|
7
6
|
private format: string = '%{public}s,%{public}s';
|
|
8
7
|
private isDebug: boolean;
|
|
9
8
|
|
|
10
|
-
constructor(
|
|
9
|
+
constructor(
|
|
10
|
+
prefix: string = 'MyApp',
|
|
11
|
+
domain: number = 0xff00,
|
|
12
|
+
isDebug = false,
|
|
13
|
+
) {
|
|
11
14
|
this.prefix = prefix;
|
|
12
15
|
this.domain = domain;
|
|
13
16
|
this.isDebug = isDebug;
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
private normalizeArgs(args: string[]): [string, string] {
|
|
20
|
+
if (args.length === 0) {
|
|
21
|
+
return ['', ''];
|
|
22
|
+
}
|
|
23
|
+
if (args.length === 1) {
|
|
24
|
+
return [args[0], ''];
|
|
25
|
+
}
|
|
26
|
+
return [args[0], args.slice(1).join(' ')];
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
debug(...args: string[]): void {
|
|
17
30
|
if (this.isDebug) {
|
|
18
|
-
|
|
31
|
+
const [tag, message] = this.normalizeArgs(args);
|
|
32
|
+
hilog.debug(this.domain, this.prefix, this.format, tag, message);
|
|
19
33
|
}
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
info(...args: string[]): void {
|
|
23
|
-
|
|
37
|
+
const [tag, message] = this.normalizeArgs(args);
|
|
38
|
+
hilog.info(this.domain, this.prefix, this.format, tag, message);
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
warn(...args: string[]): void {
|
|
27
|
-
|
|
42
|
+
const [tag, message] = this.normalizeArgs(args);
|
|
43
|
+
hilog.warn(this.domain, this.prefix, this.format, tag, message);
|
|
28
44
|
}
|
|
29
45
|
|
|
30
46
|
error(...args: string[]): void {
|
|
31
|
-
|
|
47
|
+
const [tag, message] = this.normalizeArgs(args);
|
|
48
|
+
hilog.error(this.domain, this.prefix, this.format, tag, message);
|
|
32
49
|
}
|
|
33
50
|
}
|
|
34
51
|
|
|
35
|
-
export default new Logger('
|
|
52
|
+
export default new Logger('pushy', 0xff00, false);
|
|
@@ -13,7 +13,7 @@ export class PushyFileJSBundleProvider extends JSBundleProvider {
|
|
|
13
13
|
|
|
14
14
|
constructor(context: common.UIAbilityContext) {
|
|
15
15
|
super();
|
|
16
|
-
this.updateContext =
|
|
16
|
+
this.updateContext = UpdateContext.getInstance(context);
|
|
17
17
|
this.path = this.updateContext.getBundleUrl();
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -3,13 +3,10 @@ import {
|
|
|
3
3
|
TurboModuleContext,
|
|
4
4
|
} from '@rnoh/react-native-openharmony/ts';
|
|
5
5
|
import common from '@ohos.app.ability.common';
|
|
6
|
-
import dataPreferences from '@ohos.data.preferences';
|
|
7
|
-
import { bundleManager } from '@kit.AbilityKit';
|
|
8
6
|
import logger from './Logger';
|
|
9
7
|
import { UpdateModuleImpl } from './UpdateModuleImpl';
|
|
10
8
|
import { UpdateContext } from './UpdateContext';
|
|
11
9
|
import { EventHub } from './EventHub';
|
|
12
|
-
import { util } from '@kit.ArkTS';
|
|
13
10
|
|
|
14
11
|
const TAG = 'PushyTurboModule';
|
|
15
12
|
|
|
@@ -21,86 +18,25 @@ export class PushyTurboModule extends TurboModule {
|
|
|
21
18
|
super(ctx);
|
|
22
19
|
logger.debug(TAG, ',PushyTurboModule constructor');
|
|
23
20
|
this.mUiCtx = ctx.uiAbilityContext;
|
|
24
|
-
this.context =
|
|
21
|
+
this.context = UpdateContext.getInstance(this.mUiCtx);
|
|
25
22
|
EventHub.getInstance().setRNInstance(ctx.rnInstance);
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
getConstants(): Object {
|
|
29
26
|
logger.debug(TAG, ',call getConstants');
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const isFirstTime = preferencesManager.getSync(
|
|
35
|
-
'isFirstTime',
|
|
36
|
-
false,
|
|
37
|
-
) as boolean;
|
|
38
|
-
const rolledBackVersion = preferencesManager.getSync(
|
|
39
|
-
'rolledBackVersion',
|
|
40
|
-
'',
|
|
41
|
-
) as string;
|
|
42
|
-
const uuid = preferencesManager.getSync('uuid', '') as string;
|
|
43
|
-
const currentVersion = preferencesManager.getSync(
|
|
44
|
-
'currentVersion',
|
|
45
|
-
'',
|
|
46
|
-
) as string;
|
|
27
|
+
const { isFirstTime, rolledBackVersion } =
|
|
28
|
+
this.context.consumeLaunchMarks();
|
|
29
|
+
const uuid = this.context.getKv('uuid');
|
|
30
|
+
const currentVersion = this.context.getCurrentVersion();
|
|
47
31
|
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
|
|
48
32
|
|
|
49
|
-
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
|
50
|
-
let bundleFlags =
|
|
51
|
-
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
52
|
-
let packageVersion = '';
|
|
53
|
-
try {
|
|
54
|
-
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
|
55
|
-
packageVersion = bundleInfo?.versionName || 'Unknown';
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('Failed to get bundle info:', error);
|
|
58
|
-
}
|
|
59
|
-
const storedPackageVersion = preferencesManager.getSync(
|
|
60
|
-
'packageVersion',
|
|
61
|
-
'',
|
|
62
|
-
) as string;
|
|
63
|
-
const storedBuildTime = preferencesManager.getSync(
|
|
64
|
-
'buildTime',
|
|
65
|
-
'',
|
|
66
|
-
) as string;
|
|
67
|
-
let buildTime = '';
|
|
68
|
-
try {
|
|
69
|
-
const resourceManager = this.mUiCtx.resourceManager;
|
|
70
|
-
const content = resourceManager.getRawFileContentSync('meta.json');
|
|
71
|
-
const metaData = JSON.parse(
|
|
72
|
-
new util.TextDecoder().decodeToString(content),
|
|
73
|
-
);
|
|
74
|
-
if (metaData.pushy_build_time) {
|
|
75
|
-
buildTime = String(metaData.pushy_build_time);
|
|
76
|
-
}
|
|
77
|
-
} catch {}
|
|
78
|
-
|
|
79
|
-
const packageVersionChanged =
|
|
80
|
-
!storedPackageVersion || packageVersion !== storedPackageVersion;
|
|
81
|
-
const buildTimeChanged = !storedBuildTime || buildTime !== storedBuildTime;
|
|
82
|
-
|
|
83
|
-
if (packageVersionChanged || buildTimeChanged) {
|
|
84
|
-
this.context.cleanUp();
|
|
85
|
-
preferencesManager.putSync('packageVersion', packageVersion);
|
|
86
|
-
preferencesManager.putSync('buildTime', buildTime);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (isFirstTime) {
|
|
90
|
-
preferencesManager.deleteSync('isFirstTime');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (rolledBackVersion) {
|
|
94
|
-
preferencesManager.deleteSync('rolledBackVersion');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
33
|
return {
|
|
98
|
-
downloadRootDir:
|
|
34
|
+
downloadRootDir: this.context.getRootDir(),
|
|
99
35
|
currentVersionInfo,
|
|
100
|
-
packageVersion,
|
|
36
|
+
packageVersion: this.context.getPackageVersion(),
|
|
101
37
|
currentVersion,
|
|
102
|
-
buildTime,
|
|
103
|
-
isUsingBundleUrl,
|
|
38
|
+
buildTime: this.context.getBuildTime(),
|
|
39
|
+
isUsingBundleUrl: this.context.getIsUsingBundleUrl(),
|
|
104
40
|
isFirstTime,
|
|
105
41
|
rolledBackVersion,
|
|
106
42
|
uuid,
|