react-native-update 10.42.0 → 10.42.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.42.0",
3
+ "version": "10.42.1",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  } from './core';
19
19
  import { PermissionsAndroid } from './permissions';
20
20
  import {
21
+ BeforeReloadContext,
21
22
  CheckResult,
22
23
  ClientOptions,
23
24
  EventType,
@@ -218,6 +219,18 @@ export class Pushy {
218
219
  log('afterCheckUpdate failed:', error?.message || error);
219
220
  });
220
221
  };
222
+ runBeforeReload = async (context: BeforeReloadContext) => {
223
+ const { beforeReload } = this.options;
224
+ if (!beforeReload) {
225
+ return true;
226
+ }
227
+ const shouldReload = await beforeReload(context);
228
+ if (shouldReload === false) {
229
+ log('beforeReload returned false, skipping reload');
230
+ return false;
231
+ }
232
+ return true;
233
+ };
221
234
  getCheckUrl = (endpoint: string) => {
222
235
  return `${endpoint}/checkUpdate/${this.options.appKey}`;
223
236
  };
@@ -325,6 +338,15 @@ export class Pushy {
325
338
  if (assertHash(hash) && !sharedState.applyingUpdate) {
326
339
  log(`switchVersion: ${hash}`);
327
340
  sharedState.applyingUpdate = true;
341
+ try {
342
+ if (!(await this.runBeforeReload({ type: 'switchVersion', hash }))) {
343
+ sharedState.applyingUpdate = false;
344
+ return;
345
+ }
346
+ } catch (e) {
347
+ sharedState.applyingUpdate = false;
348
+ throw e;
349
+ }
328
350
  return PushyModule.reloadUpdate({ hash });
329
351
  }
330
352
  };
@@ -668,6 +690,9 @@ export class Pushy {
668
690
  }
669
691
  };
670
692
  restartApp = async () => {
693
+ if (!(await this.runBeforeReload({ type: 'restartApp' }))) {
694
+ return;
695
+ }
671
696
  return PushyModule.restartApp();
672
697
  };
673
698
  }
package/src/type.ts CHANGED
@@ -88,6 +88,11 @@ export interface UpdateServerConfig {
88
88
  queryUrls?: string[];
89
89
  }
90
90
 
91
+ export interface BeforeReloadContext {
92
+ type: 'switchVersion' | 'restartApp';
93
+ hash?: string;
94
+ }
95
+
91
96
  export interface ClientOptions {
92
97
  appKey: string;
93
98
  server?: UpdateServerConfig;
@@ -109,6 +114,9 @@ export interface ClientOptions {
109
114
  afterCheckUpdate?: (state: UpdateCheckState) => Promise<void> | void;
110
115
  beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean> | boolean;
111
116
  afterDownloadUpdate?: (info: CheckResult) => Promise<boolean> | boolean;
117
+ beforeReload?: (
118
+ context: BeforeReloadContext,
119
+ ) => Promise<boolean | void> | boolean | void;
112
120
  onPackageExpired?: (info: CheckResult) => Promise<boolean> | boolean;
113
121
  overridePackageVersion?: string;
114
122
  }