react-native-update 10.26.0 → 10.26.3

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.
@@ -65,9 +65,13 @@ export class DownloadTask {
65
65
  0,
66
66
  params.targetFile.lastIndexOf('/'),
67
67
  );
68
- await fileIo.mkdir(targetDir);
68
+ const exists = fileIo.accessSync(targetDir);
69
+ if(!exists){
70
+ await fileIo.mkdir(targetDir);
71
+ }
69
72
  }
70
73
  } catch (error) {
74
+ throw error;
71
75
  }
72
76
 
73
77
  const response = await httpRequest.request(params.url, {
@@ -78,12 +82,11 @@ export class DownloadTask {
78
82
  'Content-Type': 'application/octet-stream',
79
83
  },
80
84
  });
81
-
82
85
  if (response.responseCode > 299) {
83
86
  throw new Error(`Server error: ${response.responseCode}`);
84
87
  }
85
88
 
86
- const contentLength = parseInt(response.header['Content-Length'] || '0');
89
+ const contentLength = parseInt(response.header['content-length'] || '0');
87
90
  const writer = await fileIo.open(
88
91
  params.targetFile,
89
92
  fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE,
@@ -102,8 +105,12 @@ export class DownloadTask {
102
105
  this.onProgressUpdate(received, contentLength);
103
106
  }
104
107
  await fileIo.close(writer);
105
- const stat = await fileIo.stat(params.targetFile);
106
- const fileSize = stat.size;
108
+ const stats = await fileIo.stat(params.targetFile);
109
+ const fileSize = stats.size;
110
+ if (fileSize !== contentLength) {
111
+ throw new Error(`Download incomplete: expected ${contentLength} bytes but got ${stats.size} bytes`);
112
+ }
113
+
107
114
  } catch (error) {
108
115
  console.error('Download failed:', error);
109
116
  throw error;
@@ -113,7 +120,7 @@ export class DownloadTask {
113
120
  }
114
121
 
115
122
  private onProgressUpdate(received: number, total: number): void {
116
- this.eventHub.emit('downloadProgress', {
123
+ this.eventHub.emit('RCTPushyDownloadProgress', {
117
124
  received,
118
125
  total,
119
126
  hash: this.hash,
@@ -288,8 +295,8 @@ export class DownloadTask {
288
295
  }
289
296
  }
290
297
 
291
- if(entry.filename !== '.DS_Store'){
292
- await zip.decompressFile(entry.filename, params.unzipDirectory);
298
+ if(fn !== '.DS_Store'){
299
+ await zip.decompressFile(fn, params.unzipDirectory);
293
300
  }
294
301
  }
295
302
 
@@ -491,4 +498,4 @@ export class DownloadTask {
491
498
  params.listener?.onDownloadFailed(error);
492
499
  }
493
500
  }
494
- }
501
+ }
@@ -3,6 +3,7 @@ type EventCallback = (data: any) => void;
3
3
  export class EventHub {
4
4
  private static instance: EventHub;
5
5
  private listeners: Map<string, Set<EventCallback>>;
6
+ private rnInstance: any;
6
7
 
7
8
  private constructor() {
8
9
  this.listeners = new Map();
@@ -27,12 +28,12 @@ export class EventHub {
27
28
  }
28
29
 
29
30
  public emit(event: string, data: any): void {
30
- this.listeners.get(event)?.forEach(callback => {
31
- try {
32
- callback(data);
33
- } catch (error) {
34
- console.error(`Error in event listener for ${event}:`, error);
35
- }
36
- });
31
+ if (this.rnInstance) {
32
+ this.rnInstance.emitDeviceEvent(event, data);
33
+ }
34
+ }
35
+
36
+ setRNInstance(instance: any) {
37
+ this.rnInstance = instance;
37
38
  }
38
39
  }
@@ -7,6 +7,7 @@ import { BusinessError } from '@ohos.base';
7
7
  import logger from './Logger';
8
8
  import { UpdateModuleImpl } from './UpdateModuleImpl';
9
9
  import { UpdateContext } from './UpdateContext';
10
+ import { EventHub } from './EventHub';
10
11
 
11
12
  const TAG = "PushyTurboModule"
12
13
 
@@ -18,9 +19,8 @@ export class PushyTurboModule extends TurboModule {
18
19
  super(ctx);
19
20
  logger.debug(TAG, ",PushyTurboModule constructor");
20
21
  this.mUiCtx = ctx.uiAbilityContext
21
- let rnInstance = ctx.rnInstance
22
22
  this.context = new UpdateContext(this.mUiCtx)
23
- // rnInstance.emitDeviceEvent("Pushy",{code: err.code, message: err.message});
23
+ EventHub.getInstance().setRNInstance(ctx.rnInstance)
24
24
  }
25
25
 
26
26
 
@@ -31,11 +31,14 @@ export class UpdateContext {
31
31
  this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
32
32
  const packageVersion = this.getPackageVersion();
33
33
  const storedVersion = this.preferences.getSync('packageVersion', '');
34
- if (packageVersion !== storedVersion) {
35
- this.preferences.clear();
36
- this.preferences.putSync('packageVersion', packageVersion);
37
- this.preferences.flush();
38
- this.cleanUp();
34
+ if(!storedVersion){
35
+ this.preferences.putSync('packageVersion', packageVersion);
36
+ this.preferences.flush();
37
+ } else if (storedVersion && packageVersion !== storedVersion) {
38
+ this.preferences.clear();
39
+ this.preferences.putSync('packageVersion', packageVersion);
40
+ this.preferences.flush();
41
+ this.cleanUp();
39
42
  }
40
43
  } catch (e) {
41
44
  console.error('Failed to init preferences:', e);
@@ -137,8 +140,9 @@ export class UpdateContext {
137
140
  params.unzipDirectory = `${this.rootDir}/${hash}`;
138
141
 
139
142
  const downloadTask = new DownloadTask(this.context);
140
- await downloadTask.execute(params);
143
+ return await downloadTask.execute(params);
141
144
  } catch (e) {
145
+ throw e;
142
146
  console.error('Failed to download APK patch:', e);
143
147
  }
144
148
  }
@@ -152,14 +156,13 @@ export class UpdateContext {
152
156
 
153
157
  const lastVersion = this.getKv('currentVersion');
154
158
  this.setKv('currentVersion', hash);
155
-
156
159
  if (lastVersion && lastVersion !== hash) {
157
160
  this.setKv('lastVersion', lastVersion);
158
161
  }
159
162
 
160
163
  this.setKv('firstTime', 'true');
161
164
  this.setKv('firstTimeOk', 'false');
162
- this.setKv('rolledBackVersion', null);
165
+ this.setKv('rolledBackVersion', "");
163
166
  } catch (e) {
164
167
  console.error('Failed to switch version:', e);
165
168
  }
@@ -211,7 +214,7 @@ export class UpdateContext {
211
214
  }
212
215
 
213
216
  public getCurrentVersion() : string {
214
- const currentVersion = this.preferences.getSync('currentVersion', '') as string;
217
+ const currentVersion = this.getKv('currentVersion');
215
218
  return currentVersion;
216
219
  }
217
220
 
@@ -56,7 +56,7 @@ export class UpdateModuleImpl {
56
56
  options: { updateUrl: string; hash: string }
57
57
  ): Promise<void> {
58
58
  try {
59
- await updateContext.downloadPatchFromPackage(options.updateUrl, options.hash, {
59
+ return await updateContext.downloadPatchFromPackage(options.updateUrl, options.hash, {
60
60
  onDownloadCompleted: (params: DownloadTaskParams) => {
61
61
  return Promise.resolve();
62
62
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.26.0",
3
+ "version": "10.26.3",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -9,7 +9,11 @@ import {
9
9
  promiseAny,
10
10
  testUrls,
11
11
  } from './utils';
12
- import { EmitterSubscription, Platform } from 'react-native';
12
+ import {
13
+ EmitterSubscription,
14
+ Platform,
15
+ DeviceEventEmitter,
16
+ } from 'react-native';
13
17
  import { PermissionsAndroid } from './permissions';
14
18
  import {
15
19
  PushyModule,
@@ -350,14 +354,26 @@ export class Pushy {
350
354
  return;
351
355
  }
352
356
  if (onDownloadProgress) {
353
- Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
354
- 'RCTPushyDownloadProgress',
355
- progressData => {
356
- if (progressData.hash === hash) {
357
- onDownloadProgress(progressData);
358
- }
359
- },
360
- );
357
+ // @ts-expect-error harmony not in existing platforms
358
+ if (Platform.OS === 'harmony') {
359
+ Pushy.progressHandlers[hash] = DeviceEventEmitter.addListener(
360
+ 'RCTPushyDownloadProgress',
361
+ progressData => {
362
+ if (progressData.hash === hash) {
363
+ onDownloadProgress(progressData);
364
+ }
365
+ },
366
+ );
367
+ } else {
368
+ Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
369
+ 'RCTPushyDownloadProgress',
370
+ progressData => {
371
+ if (progressData.hash === hash) {
372
+ onDownloadProgress(progressData);
373
+ }
374
+ },
375
+ );
376
+ }
361
377
  }
362
378
  let succeeded = '';
363
379
  this.report({ type: 'downloading' });
package/src/core.ts CHANGED
@@ -4,7 +4,9 @@ const {
4
4
  version: v,
5
5
  } = require('react-native/Libraries/Core/ReactNativeVersion');
6
6
  const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
7
- const isTurboModuleEnabled = (global as any).__turboModuleProxy != null;
7
+ const isTurboModuleEnabled =
8
+ // https://github.com/facebook/react-native/pull/48362
9
+ (global as any).__turboModuleProxy || (global as any).RN$Bridgeless;
8
10
 
9
11
  export const PushyModule =
10
12
  Platform.OS === 'web'
package/src/provider.tsx CHANGED
@@ -247,7 +247,9 @@ export const UpdateProvider = ({
247
247
  }
248
248
  const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options;
249
249
  if (autoMarkSuccess) {
250
- markSuccess();
250
+ setTimeout(() => {
251
+ markSuccess();
252
+ }, 1000);
251
253
  }
252
254
  if (checkStrategy === 'both' || checkStrategy === 'onAppResume') {
253
255
  stateListener.current = AppState.addEventListener(
@@ -276,7 +278,7 @@ export const UpdateProvider = ({
276
278
 
277
279
  const parseTestPayload = useCallback(
278
280
  (payload: UpdateTestPayload) => {
279
- if (payload && payload.type && payload.type.startsWith('__rnUpdate')) {
281
+ if (payload && payload.type && payload.type.startsWith('__rnPushy')) {
280
282
  const logger = options.logger || (() => {});
281
283
  options.logger = ({ type, data }) => {
282
284
  logger({ type, data });