react-native-update 10.42.2 → 10.42.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.
@@ -51,6 +51,17 @@ export function parseManifestToArrays(
51
51
  };
52
52
  }
53
53
 
54
+ function toArrayBufferSlice(
55
+ payload: Uint8Array,
56
+ offset: number,
57
+ length: number,
58
+ ): ArrayBuffer {
59
+ return payload.buffer.slice(
60
+ payload.byteOffset + offset,
61
+ payload.byteOffset + offset + length,
62
+ );
63
+ }
64
+
54
65
  const DIFF_MANIFEST_ENTRY = '__diff.json';
55
66
  const HARMONY_BUNDLE_PATCH_ENTRY = 'bundle.harmony.js.patch';
56
67
  const TEMP_ORIGIN_BUNDLE_ENTRY = '.origin.bundle.harmony.js';
@@ -172,9 +183,13 @@ export class DownloadTask {
172
183
  let bytesWritten = 0;
173
184
 
174
185
  while (bytesWritten < payload.byteLength) {
175
- const chunk = payload.subarray(bytesWritten, bytesWritten + chunkSize);
186
+ const chunkLength = Math.min(
187
+ chunkSize,
188
+ payload.byteLength - bytesWritten,
189
+ );
190
+ const chunk = toArrayBufferSlice(payload, bytesWritten, chunkLength);
176
191
  await fileIo.write(writer.fd, chunk);
177
- bytesWritten += chunk.byteLength;
192
+ bytesWritten += chunkLength;
178
193
  }
179
194
  } finally {
180
195
  if (writer) {
@@ -268,7 +283,7 @@ export class DownloadTask {
268
283
  break;
269
284
  }
270
285
 
271
- await fileIo.write(writer.fd, new Uint8Array(buffer, 0, readLength));
286
+ await fileIo.write(writer.fd, buffer.slice(0, readLength));
272
287
  offset += readLength;
273
288
 
274
289
  if (readLength < FILE_COPY_BUFFER_SIZE) {
@@ -7,7 +7,6 @@ import { bundleManager } from '@kit.AbilityKit';
7
7
  import logger from './Logger';
8
8
  import { UpdateContext } from './UpdateContext';
9
9
  import { EventHub } from './EventHub';
10
- import { util } from '@kit.ArkTS';
11
10
 
12
11
  const TAG = 'PushyTurboModule';
13
12
 
@@ -47,33 +46,6 @@ export class PushyTurboModule extends UITurboModule {
47
46
  return bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
48
47
  }
49
48
 
50
- private getPackageVersion(): string {
51
- try {
52
- const bundleInfo = bundleManager.getBundleInfoForSelfSync(
53
- this.getBundleFlags(),
54
- );
55
- return bundleInfo?.versionName || 'Unknown';
56
- } catch (error) {
57
- console.error('Failed to get bundle info:', error);
58
- return '';
59
- }
60
- }
61
-
62
- private getBuildTime(): string {
63
- try {
64
- const content = this.mUiCtx.resourceManager.getRawFileContentSync(
65
- 'meta.json',
66
- );
67
- const metaData = JSON.parse(
68
- new util.TextDecoder().decodeToString(content),
69
- ) as Record<string, string | number | boolean | null | undefined>;
70
- if (metaData.pushy_build_time) {
71
- return String(metaData.pushy_build_time);
72
- }
73
- } catch {}
74
- return '';
75
- }
76
-
77
49
  private requireHash(hash: string, methodName: string): string {
78
50
  if (!hash) {
79
51
  throw Error(`${methodName}: empty hash`);
@@ -95,8 +67,8 @@ export class PushyTurboModule extends UITurboModule {
95
67
 
96
68
  getConstants(): Object {
97
69
  logger.debug(TAG, ',call getConstants');
98
- const packageVersion = this.getPackageVersion();
99
- const buildTime = this.getBuildTime();
70
+ const packageVersion = this.context.getPackageVersion();
71
+ const buildTime = this.context.getBuildTime();
100
72
  this.context.syncStateWithBinaryVersion(packageVersion, buildTime);
101
73
 
102
74
  const currentVersion = this.context.getCurrentVersion();
@@ -3,6 +3,8 @@ import fileIo from '@ohos.file.fs';
3
3
  import { DownloadTask } from './DownloadTask';
4
4
  import common from '@ohos.app.ability.common';
5
5
  import { DownloadTaskParams } from './DownloadTaskParams';
6
+ import { bundleManager } from '@kit.AbilityKit';
7
+ import { util } from '@kit.ArkTS';
6
8
  import NativePatchCore, {
7
9
  STATE_OP_CLEAR_FIRST_TIME,
8
10
  STATE_OP_CLEAR_ROLLBACK_MARK,
@@ -13,6 +15,10 @@ import NativePatchCore, {
13
15
  StateCoreResult,
14
16
  } from './NativePatchCore';
15
17
 
18
+ type FlushablePreferences = preferences.Preferences & {
19
+ flushSync?: () => void;
20
+ };
21
+
16
22
  export class UpdateContext {
17
23
  private context: common.UIAbilityContext;
18
24
  private rootDir: string;
@@ -32,6 +38,10 @@ export class UpdateContext {
32
38
  console.error('Failed to create root directory:', e);
33
39
  }
34
40
  this.initPreferences();
41
+ this.syncStateWithBinaryVersion(
42
+ this.getPackageVersion(),
43
+ this.getBuildTime(),
44
+ );
35
45
  }
36
46
 
37
47
  private initPreferences() {
@@ -44,6 +54,37 @@ export class UpdateContext {
44
54
  }
45
55
  }
46
56
 
57
+ private getBundleFlags(): bundleManager.BundleFlag {
58
+ return bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
59
+ }
60
+
61
+ public getPackageVersion(): string {
62
+ try {
63
+ const bundleInfo = bundleManager.getBundleInfoForSelfSync(
64
+ this.getBundleFlags(),
65
+ );
66
+ return bundleInfo?.versionName || 'Unknown';
67
+ } catch (error) {
68
+ console.error('Failed to get bundle info:', error);
69
+ return '';
70
+ }
71
+ }
72
+
73
+ public getBuildTime(): string {
74
+ try {
75
+ const content = this.context.resourceManager.getRawFileContentSync(
76
+ 'meta.json',
77
+ );
78
+ const metaData = JSON.parse(
79
+ new util.TextDecoder().decodeToString(content),
80
+ ) as Record<string, string | number | boolean | null | undefined>;
81
+ if (metaData.pushy_build_time) {
82
+ return String(metaData.pushy_build_time);
83
+ }
84
+ } catch {}
85
+ return '';
86
+ }
87
+
47
88
  private readString(key: string): string {
48
89
  const value = this.preferences.getSync(key, '') as
49
90
  | string
@@ -87,6 +128,20 @@ export class UpdateContext {
87
128
  return defaultValue;
88
129
  }
89
130
 
131
+ private flushPreferences(reason: string): void {
132
+ try {
133
+ const flushablePreferences = this.preferences as FlushablePreferences;
134
+ if (typeof flushablePreferences.flushSync === 'function') {
135
+ flushablePreferences.flushSync();
136
+ return;
137
+ }
138
+ throw Error('preferences.flushSync is not available');
139
+ } catch (error) {
140
+ console.error(`Failed to flush preferences for ${reason}:`, error);
141
+ throw error;
142
+ }
143
+ }
144
+
90
145
  private putNullableString(key: string, value?: string): void {
91
146
  if (value) {
92
147
  this.preferences.putSync(key, value);
@@ -136,7 +191,7 @@ export class UpdateContext {
136
191
  if (options.removeStaleHash && state.staleVersionToDelete) {
137
192
  this.preferences.deleteSync(`hash_${state.staleVersionToDelete}`);
138
193
  }
139
- this.preferences.flush();
194
+ this.flushPreferences('persist state');
140
195
  if (options.cleanUp) {
141
196
  this.cleanUp();
142
197
  }
@@ -196,7 +251,7 @@ export class UpdateContext {
196
251
 
197
252
  public setKv(key: string, value: string): void {
198
253
  this.preferences.putSync(key, value);
199
- this.preferences.flush();
254
+ this.flushPreferences(`set key ${key}`);
200
255
  }
201
256
 
202
257
  public getKv(key: string): string {
package/harmony/pushy.har CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.42.2",
3
+ "version": "10.42.4",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
Binary file
Binary file