react-native-update 10.34.9 → 10.35.0

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.
@@ -57,7 +57,7 @@ export class DownloadTask {
57
57
 
58
58
  try {
59
59
  try {
60
- const exists = fileIo.accessSync(params.targetFile);
60
+ let exists = fileIo.accessSync(params.targetFile);
61
61
  if (exists) {
62
62
  await fileIo.unlink(params.targetFile);
63
63
  } else {
@@ -65,7 +65,7 @@ export class DownloadTask {
65
65
  0,
66
66
  params.targetFile.lastIndexOf('/'),
67
67
  );
68
- const exists = fileIo.accessSync(targetDir);
68
+ exists = fileIo.accessSync(targetDir);
69
69
  if (!exists) {
70
70
  await fileIo.mkdir(targetDir);
71
71
  }
@@ -1,49 +1,41 @@
1
- import { HotReloadConfig, JSBundleProvider, JSBundleProviderError, JSPackagerClientConfig } from '@rnoh/react-native-openharmony';
2
- import fileIo from '@ohos.file.fs';
1
+ import {
2
+ FileJSBundle,
3
+ HotReloadConfig,
4
+ JSBundleProvider,
5
+ JSBundleProviderError
6
+ } from '@rnoh/react-native-openharmony';
3
7
  import common from '@ohos.app.ability.common';
8
+ import fs from '@ohos.file.fs';
4
9
  import { UpdateContext } from './UpdateContext';
5
10
 
6
11
  export class PushyFileJSBundleProvider extends JSBundleProvider {
7
12
  private updateContext: UpdateContext;
8
- private filePath: string = ''
13
+ private path: string = ''
9
14
 
10
15
  constructor(context: common.UIAbilityContext) {
11
16
  super();
12
17
  this.updateContext = new UpdateContext(context);
18
+ this.path = this.updateContext.getBundleUrl();
13
19
  }
20
+
14
21
  getURL(): string {
15
- return this.updateContext.getBundleUrl()?.substring(1);
22
+ return this.path;
16
23
  }
17
24
 
18
- async getBundle(): Promise<ArrayBuffer> {
25
+ async getBundle(): Promise<FileJSBundle> {
19
26
  try {
20
- this.filePath = this.updateContext.getBundleUrl();
21
- const res = fileIo.accessSync(this.filePath);
22
- if (res) {
23
- const file = fileIo.openSync(this.filePath, fileIo.OpenMode.READ_ONLY);
24
- try {
25
- const stat = await fileIo.stat(this.filePath);
26
- const fileSize = stat.size;
27
- const buffer = new ArrayBuffer(fileSize);
28
- const bytesRead = fileIo.readSync(file.fd, buffer, {
29
- offset: 0,
30
- length: fileSize
31
- });
32
-
33
- if (bytesRead !== fileSize) {
34
- throw new Error(`Failed to read entire file: read ${bytesRead} of ${fileSize} bytes`);
35
- }
36
- return buffer;
37
- } finally {
38
- fileIo.closeSync(file.fd);
27
+ const status = await fs.access(this.path, fs.OpenMode.READ_ONLY);
28
+ if (status) {
29
+ return {
30
+ filePath: this.path
39
31
  }
40
32
  }
41
33
  throw new Error('Update bundle not found');
42
34
  } catch (error) {
43
35
  throw new JSBundleProviderError({
44
- whatHappened: `Couldn't load JSBundle from ${this.filePath}`,
36
+ whatHappened: `Couldn't load JSBundle from ${this.path}`,
45
37
  extraData: error,
46
- howCanItBeFixed: [`Check if a bundle exists at "${this.filePath}" on your device.`]
38
+ howCanItBeFixed: [`Check if a bundle exists at "${this.path}" on your device.`]
47
39
  })
48
40
  }
49
41
  }
@@ -1,9 +1,10 @@
1
- import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
1
+ import {
2
+ TurboModule,
3
+ TurboModuleContext,
4
+ } from '@rnoh/react-native-openharmony/ts';
2
5
  import common from '@ohos.app.ability.common';
3
6
  import dataPreferences from '@ohos.data.preferences';
4
7
  import { bundleManager } from '@kit.AbilityKit';
5
- import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
6
- import { BusinessError } from '@ohos.base';
7
8
  import logger from './Logger';
8
9
  import { UpdateModuleImpl } from './UpdateModuleImpl';
9
10
  import { UpdateContext } from './UpdateContext';
@@ -23,50 +24,60 @@ export class PushyTurboModule extends TurboModule {
23
24
  EventHub.getInstance().setRNInstance(ctx.rnInstance);
24
25
  }
25
26
 
26
-
27
- getConstants(): Object {
28
- logger.debug(TAG, ',call getConstants');
29
- const context = this.mUiCtx;
30
- const preferencesManager = dataPreferences.getPreferencesSync(context,{ name: 'update' });
31
- const isFirstTime = preferencesManager.getSync('isFirstTime', false) as boolean;
32
- const rolledBackVersion = preferencesManager.getSync('rolledBackVersion', '') as string;
33
- const uuid = preferencesManager.getSync('uuid', '') as string;
34
- const currentVersion = preferencesManager.getSync('currentVersion', '') as string;
35
- const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
36
- const buildTime = preferencesManager.getSync('buildTime', '') as string;
37
- const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
38
- let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
39
- let packageVersion = '';
40
- try {
41
- const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
42
- packageVersion = bundleInfo?.versionName || 'Unknown';
43
- } catch (error) {
44
- console.error('Failed to get bundle info:', error);
45
- }
46
-
47
- if (isFirstTime) {
48
- preferencesManager.deleteSync('isFirstTime');
49
- }
50
-
51
- if (rolledBackVersion) {
52
- preferencesManager.deleteSync('rolledBackVersion');
53
- }
54
-
55
- return {
56
- downloadRootDir: `${context.filesDir}/_update`,
57
- currentVersionInfo,
58
- packageVersion,
59
- currentVersion,
60
- buildTime,
61
- isUsingBundleUrl,
62
- isFirstTime,
63
- rolledBackVersion,
64
- uuid,
65
- };
66
- }
67
-
68
-
69
- setLocalHashInfo(hash: string, info: string): boolean {
27
+ getConstants(): Object {
28
+ logger.debug(TAG, ',call getConstants');
29
+ const context = this.mUiCtx;
30
+ const preferencesManager = dataPreferences.getPreferencesSync(context, {
31
+ name: 'update',
32
+ });
33
+ const isFirstTime = preferencesManager.getSync(
34
+ 'isFirstTime',
35
+ false,
36
+ ) as boolean;
37
+ const rolledBackVersion = preferencesManager.getSync(
38
+ 'rolledBackVersion',
39
+ '',
40
+ ) as string;
41
+ const uuid = preferencesManager.getSync('uuid', '') as string;
42
+ const currentVersion = preferencesManager.getSync(
43
+ 'currentVersion',
44
+ '',
45
+ ) as string;
46
+ const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
47
+ const buildTime = preferencesManager.getSync('buildTime', '') as string;
48
+ const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
49
+ let bundleFlags =
50
+ bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
51
+ let packageVersion = '';
52
+ try {
53
+ const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
54
+ packageVersion = bundleInfo?.versionName || 'Unknown';
55
+ } catch (error) {
56
+ console.error('Failed to get bundle info:', error);
57
+ }
58
+
59
+ if (isFirstTime) {
60
+ preferencesManager.deleteSync('isFirstTime');
61
+ }
62
+
63
+ if (rolledBackVersion) {
64
+ preferencesManager.deleteSync('rolledBackVersion');
65
+ }
66
+
67
+ return {
68
+ downloadRootDir: `${context.filesDir}/_update`,
69
+ currentVersionInfo,
70
+ packageVersion,
71
+ currentVersion,
72
+ buildTime,
73
+ isUsingBundleUrl,
74
+ isFirstTime,
75
+ rolledBackVersion,
76
+ uuid,
77
+ };
78
+ }
79
+
80
+ setLocalHashInfo(hash: string, info: string): boolean {
70
81
  logger.debug(TAG, ',call setLocalHashInfo');
71
82
  return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
72
83
  }
@@ -75,9 +86,9 @@ getConstants(): Object {
75
86
  return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
76
87
  }
77
88
 
78
- async setUuid(uuid: string): Promise<boolean> {
89
+ async setUuid(uuid: string): Promise<boolean> {
79
90
  logger.debug(TAG, ',call setUuid');
80
- return UpdateModuleImpl.setUuid(this.context,uuid);
91
+ return UpdateModuleImpl.setUuid(this.context, uuid);
81
92
  }
82
93
 
83
94
  async reloadUpdate(options: { hash: string }): Promise<void> {
@@ -95,31 +106,45 @@ getConstants(): Object {
95
106
  return UpdateModuleImpl.markSuccess(this.context);
96
107
  }
97
108
 
98
- async downloadPatchFromPpk(options: { updateUrl: string; hash: string; originHash: string }): Promise<void> {
109
+ async downloadPatchFromPpk(options: {
110
+ updateUrl: string;
111
+ hash: string;
112
+ originHash: string;
113
+ }): Promise<void> {
99
114
  logger.debug(TAG, ',call downloadPatchFromPpk');
100
115
  return UpdateModuleImpl.downloadPatchFromPpk(this.context, options);
101
116
  }
102
117
 
103
- async downloadPatchFromPackage(options: { updateUrl: string; hash: string }): Promise<void> {
118
+ async downloadPatchFromPackage(options: {
119
+ updateUrl: string;
120
+ hash: string;
121
+ }): Promise<void> {
104
122
  logger.debug(TAG, ',call downloadPatchFromPackage');
105
123
  return UpdateModuleImpl.downloadPatchFromPackage(this.context, options);
106
124
  }
107
125
 
108
- async downloadFullUpdate(options: { updateUrl: string; hash: string }): Promise<void> {
126
+ async downloadFullUpdate(options: {
127
+ updateUrl: string;
128
+ hash: string;
129
+ }): Promise<void> {
109
130
  logger.debug(TAG, ',call downloadFullUpdate');
110
131
  return UpdateModuleImpl.downloadFullUpdate(this.context, options);
111
132
  }
112
133
 
113
- async downloadAndInstallApk(options: { url: string; target: string; hash: string }): Promise<void> {
134
+ async downloadAndInstallApk(options: {
135
+ url: string;
136
+ target: string;
137
+ hash: string;
138
+ }): Promise<void> {
114
139
  logger.debug(TAG, ',call downloadAndInstallApk');
115
140
  return UpdateModuleImpl.downloadAndInstallApk(this.mUiCtx, options);
116
141
  }
117
142
 
118
- addListener(eventName: string): void {
143
+ addListener(_eventName: string): void {
119
144
  logger.debug(TAG, ',call addListener');
120
145
  }
121
146
 
122
- removeListeners(count: number): void {
147
+ removeListeners(_count: number): void {
123
148
  logger.debug(TAG, ',call removeListeners');
124
149
  }
125
150
  }
@@ -101,6 +101,7 @@ export class UpdateContext {
101
101
  params.hash = hash;
102
102
  params.listener = listener;
103
103
  params.targetFile = `${this.rootDir}/${hash}.ppk`;
104
+ params.unzipDirectory = `${this.rootDir}/${hash}`;
104
105
  const downloadTask = new DownloadTask(this.context);
105
106
  await downloadTask.execute(params);
106
107
  } catch (e) {
@@ -162,8 +163,8 @@ export class UpdateContext {
162
163
  const downloadTask = new DownloadTask(this.context);
163
164
  return await downloadTask.execute(params);
164
165
  } catch (e) {
165
- throw e;
166
166
  console.error('Failed to download APK patch:', e);
167
+ throw e;
167
168
  }
168
169
  }
169
170
 
@@ -191,11 +192,11 @@ export class UpdateContext {
191
192
  public static getBundleUrl(
192
193
  context: common.UIAbilityContext,
193
194
  defaultAssetsUrl?: string,
194
- ): string {
195
+ ) {
195
196
  return new UpdateContext(context).getBundleUrl(defaultAssetsUrl);
196
197
  }
197
198
 
198
- public getBundleUrl(defaultAssetsUrl?: string): string {
199
+ public getBundleUrl(defaultAssetsUrl?: string) {
199
200
  UpdateContext.isUsingBundleUrl = true;
200
201
  const currentVersion = this.getCurrentVersion();
201
202
  if (!currentVersion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.34.9",
3
+ "version": "10.35.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/core.ts CHANGED
@@ -47,7 +47,7 @@ export const currentVersionInfo = _currentVersionInfo;
47
47
 
48
48
  export const isFirstTime: boolean = PushyConstants.isFirstTime;
49
49
  export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
50
- export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
50
+ export const isRolledBack: boolean = !!rolledBackVersion;
51
51
 
52
52
  export const buildTime: string = PushyConstants.buildTime;
53
53
  let uuid = PushyConstants.uuid;