react-native-update 10.16.0 → 10.17.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.16.0",
3
+ "version": "10.17.0",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/client.ts CHANGED
@@ -43,11 +43,13 @@ export class Pushy {
43
43
  lastChecking?: number;
44
44
  lastRespJson?: Promise<any>;
45
45
 
46
- progressHandlers: Record<string, EmitterSubscription> = {};
47
- downloadedHash?: string;
46
+ static progressHandlers: Record<string, EmitterSubscription> = {};
47
+ static downloadedHash?: string;
48
48
 
49
- marked = false;
50
- applyingUpdate = false;
49
+ static apkStatus: 'downloading' | 'downloaded' | null = null;
50
+
51
+ static marked = false;
52
+ static applyingUpdate = false;
51
53
  version = cInfo.pushy;
52
54
  loggerPromise = (() => {
53
55
  let resolve: (value?: unknown) => void = () => {};
@@ -121,21 +123,21 @@ export class Pushy {
121
123
  getCheckUrl = (endpoint: string = this.options.server!.main) => {
122
124
  return `${endpoint}/checkUpdate/${this.options.appKey}`;
123
125
  };
124
- assertHash = (hash: string) => {
125
- if (!this.downloadedHash) {
126
+ static assertHash = (hash: string) => {
127
+ if (!Pushy.downloadedHash) {
126
128
  return;
127
129
  }
128
- if (hash !== this.downloadedHash) {
129
- log(`use downloaded hash ${this.downloadedHash} first`);
130
+ if (hash !== Pushy.downloadedHash) {
131
+ log(`use downloaded hash ${Pushy.downloadedHash} first`);
130
132
  return;
131
133
  }
132
134
  return true;
133
135
  };
134
136
  markSuccess = () => {
135
- if (this.marked || __DEV__ || !isFirstTime) {
137
+ if (Pushy.marked || __DEV__ || !isFirstTime) {
136
138
  return;
137
139
  }
138
- this.marked = true;
140
+ Pushy.marked = true;
139
141
  PushyModule.markSuccess();
140
142
  this.report({ type: 'markSuccess' });
141
143
  };
@@ -146,9 +148,9 @@ export class Pushy {
146
148
  );
147
149
  return;
148
150
  }
149
- if (this.assertHash(hash) && !this.applyingUpdate) {
151
+ if (Pushy.assertHash(hash) && !Pushy.applyingUpdate) {
150
152
  log('switchVersion: ' + hash);
151
- this.applyingUpdate = true;
153
+ Pushy.applyingUpdate = true;
152
154
  return PushyModule.reloadUpdate({ hash });
153
155
  }
154
156
  };
@@ -160,7 +162,7 @@ export class Pushy {
160
162
  );
161
163
  return;
162
164
  }
163
- if (this.assertHash(hash)) {
165
+ if (Pushy.assertHash(hash)) {
164
166
  log('switchVersionLater: ' + hash);
165
167
  return PushyModule.setNeedUpdate({ hash });
166
168
  }
@@ -314,15 +316,15 @@ export class Pushy {
314
316
  log(`rolledback hash ${rolledBackVersion}, ignored`);
315
317
  return;
316
318
  }
317
- if (this.downloadedHash === hash) {
318
- log(`duplicated downloaded hash ${this.downloadedHash}, ignored`);
319
- return this.downloadedHash;
319
+ if (Pushy.downloadedHash === hash) {
320
+ log(`duplicated downloaded hash ${Pushy.downloadedHash}, ignored`);
321
+ return Pushy.downloadedHash;
320
322
  }
321
- if (this.progressHandlers[hash]) {
323
+ if (Pushy.progressHandlers[hash]) {
322
324
  return;
323
325
  }
324
326
  if (onDownloadProgress) {
325
- this.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
327
+ Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
326
328
  'RCTPushyDownloadProgress',
327
329
  progressData => {
328
330
  if (progressData.hash === hash) {
@@ -389,9 +391,9 @@ export class Pushy {
389
391
  }
390
392
  }
391
393
  }
392
- if (this.progressHandlers[hash]) {
393
- this.progressHandlers[hash].remove();
394
- delete this.progressHandlers[hash];
394
+ if (Pushy.progressHandlers[hash]) {
395
+ Pushy.progressHandlers[hash].remove();
396
+ delete Pushy.progressHandlers[hash];
395
397
  }
396
398
  if (__DEV__) {
397
399
  return hash;
@@ -417,7 +419,7 @@ export class Pushy {
417
419
  description,
418
420
  metaInfo,
419
421
  });
420
- this.downloadedHash = hash;
422
+ Pushy.downloadedHash = hash;
421
423
  return hash;
422
424
  };
423
425
  downloadAndInstallApk = async (
@@ -427,7 +429,14 @@ export class Pushy {
427
429
  if (Platform.OS !== 'android') {
428
430
  return;
429
431
  }
430
- this.report({ type: 'downloadingApk' });
432
+ if (Pushy.apkStatus === 'downloading') {
433
+ return;
434
+ }
435
+ if (Pushy.apkStatus === 'downloaded') {
436
+ this.report({ type: 'errorInstallApk' });
437
+ this.throwIfEnabled(new Error('errorInstallApk'));
438
+ return;
439
+ }
431
440
  if (Platform.Version <= 23) {
432
441
  try {
433
442
  const granted = await PermissionsAndroid.request(
@@ -444,12 +453,14 @@ export class Pushy {
444
453
  return;
445
454
  }
446
455
  }
456
+ Pushy.apkStatus = 'downloading';
457
+ this.report({ type: 'downloadingApk' });
447
458
  const progressKey = 'downloadingApk';
448
459
  if (onDownloadProgress) {
449
- if (this.progressHandlers[progressKey]) {
450
- this.progressHandlers[progressKey].remove();
460
+ if (Pushy.progressHandlers[progressKey]) {
461
+ Pushy.progressHandlers[progressKey].remove();
451
462
  }
452
- this.progressHandlers[progressKey] = pushyNativeEventEmitter.addListener(
463
+ Pushy.progressHandlers[progressKey] = pushyNativeEventEmitter.addListener(
453
464
  'RCTPushyDownloadProgress',
454
465
  (progressData: ProgressData) => {
455
466
  if (progressData.hash === progressKey) {
@@ -463,12 +474,14 @@ export class Pushy {
463
474
  target: 'update.apk',
464
475
  hash: progressKey,
465
476
  }).catch(() => {
477
+ Pushy.apkStatus = null;
466
478
  this.report({ type: 'errorDownloadAndInstallApk' });
467
479
  this.throwIfEnabled(new Error('errorDownloadAndInstallApk'));
468
480
  });
469
- if (this.progressHandlers[progressKey]) {
470
- this.progressHandlers[progressKey].remove();
471
- delete this.progressHandlers[progressKey];
481
+ Pushy.apkStatus = 'downloaded';
482
+ if (Pushy.progressHandlers[progressKey]) {
483
+ Pushy.progressHandlers[progressKey].remove();
484
+ delete Pushy.progressHandlers[progressKey];
472
485
  }
473
486
  };
474
487
  }
package/src/type.ts CHANGED
@@ -38,7 +38,8 @@ export type EventType =
38
38
  | 'downloadingApk'
39
39
  | 'rejectStoragePermission'
40
40
  | 'errorStoragePermission'
41
- | 'errorDownloadAndInstallApk';
41
+ | 'errorDownloadAndInstallApk'
42
+ | 'errorInstallApk';
42
43
 
43
44
  export interface EventData {
44
45
  currentVersion: string;