Skip to content

Commit d4f21a3

Browse files
committed
v10.17.0
1 parent 2192000 commit d4f21a3

File tree

3 files changed

+47
-32
lines changed

3 files changed

+47
-32
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update",
3-
"version": "10.16.0",
3+
"version": "10.17.0",
44
"description": "react-native hot update",
55
"main": "src/index",
66
"scripts": {
@@ -74,5 +74,6 @@
7474
"react-native": "0.73",
7575
"ts-jest": "^29.2.5",
7676
"typescript": "^5.6.3"
77-
}
77+
},
78+
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
7879
}

src/client.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ export class Pushy {
4343
lastChecking?: number;
4444
lastRespJson?: Promise<any>;
4545

46-
progressHandlers: Record<string, EmitterSubscription> = {};
47-
downloadedHash?: string;
46+
static progressHandlers: Record<string, EmitterSubscription> = {};
47+
static downloadedHash?: string;
4848

49-
marked = false;
50-
applyingUpdate = false;
49+
static apkStatus: 'downloading' | 'downloaded' | null = null;
50+
51+
static marked = false;
52+
static applyingUpdate = false;
5153
version = cInfo.pushy;
5254
loggerPromise = (() => {
5355
let resolve: (value?: unknown) => void = () => {};
@@ -121,21 +123,21 @@ export class Pushy {
121123
getCheckUrl = (endpoint: string = this.options.server!.main) => {
122124
return `${endpoint}/checkUpdate/${this.options.appKey}`;
123125
};
124-
assertHash = (hash: string) => {
125-
if (!this.downloadedHash) {
126+
static assertHash = (hash: string) => {
127+
if (!Pushy.downloadedHash) {
126128
return;
127129
}
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`);
130132
return;
131133
}
132134
return true;
133135
};
134136
markSuccess = () => {
135-
if (this.marked || __DEV__ || !isFirstTime) {
137+
if (Pushy.marked || __DEV__ || !isFirstTime) {
136138
return;
137139
}
138-
this.marked = true;
140+
Pushy.marked = true;
139141
PushyModule.markSuccess();
140142
this.report({ type: 'markSuccess' });
141143
};
@@ -146,9 +148,9 @@ export class Pushy {
146148
);
147149
return;
148150
}
149-
if (this.assertHash(hash) && !this.applyingUpdate) {
151+
if (Pushy.assertHash(hash) && !Pushy.applyingUpdate) {
150152
log('switchVersion: ' + hash);
151-
this.applyingUpdate = true;
153+
Pushy.applyingUpdate = true;
152154
return PushyModule.reloadUpdate({ hash });
153155
}
154156
};
@@ -160,7 +162,7 @@ export class Pushy {
160162
);
161163
return;
162164
}
163-
if (this.assertHash(hash)) {
165+
if (Pushy.assertHash(hash)) {
164166
log('switchVersionLater: ' + hash);
165167
return PushyModule.setNeedUpdate({ hash });
166168
}
@@ -314,15 +316,15 @@ export class Pushy {
314316
log(`rolledback hash ${rolledBackVersion}, ignored`);
315317
return;
316318
}
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;
320322
}
321-
if (this.progressHandlers[hash]) {
323+
if (Pushy.progressHandlers[hash]) {
322324
return;
323325
}
324326
if (onDownloadProgress) {
325-
this.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
327+
Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
326328
'RCTPushyDownloadProgress',
327329
progressData => {
328330
if (progressData.hash === hash) {
@@ -389,9 +391,9 @@ export class Pushy {
389391
}
390392
}
391393
}
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];
395397
}
396398
if (__DEV__) {
397399
return hash;
@@ -417,7 +419,7 @@ export class Pushy {
417419
description,
418420
metaInfo,
419421
});
420-
this.downloadedHash = hash;
422+
Pushy.downloadedHash = hash;
421423
return hash;
422424
};
423425
downloadAndInstallApk = async (
@@ -427,7 +429,14 @@ export class Pushy {
427429
if (Platform.OS !== 'android') {
428430
return;
429431
}
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+
}
431440
if (Platform.Version <= 23) {
432441
try {
433442
const granted = await PermissionsAndroid.request(
@@ -444,12 +453,14 @@ export class Pushy {
444453
return;
445454
}
446455
}
456+
Pushy.apkStatus = 'downloading';
457+
this.report({ type: 'downloadingApk' });
447458
const progressKey = 'downloadingApk';
448459
if (onDownloadProgress) {
449-
if (this.progressHandlers[progressKey]) {
450-
this.progressHandlers[progressKey].remove();
460+
if (Pushy.progressHandlers[progressKey]) {
461+
Pushy.progressHandlers[progressKey].remove();
451462
}
452-
this.progressHandlers[progressKey] = pushyNativeEventEmitter.addListener(
463+
Pushy.progressHandlers[progressKey] = pushyNativeEventEmitter.addListener(
453464
'RCTPushyDownloadProgress',
454465
(progressData: ProgressData) => {
455466
if (progressData.hash === progressKey) {
@@ -463,12 +474,14 @@ export class Pushy {
463474
target: 'update.apk',
464475
hash: progressKey,
465476
}).catch(() => {
477+
Pushy.apkStatus = null;
466478
this.report({ type: 'errorDownloadAndInstallApk' });
467479
this.throwIfEnabled(new Error('errorDownloadAndInstallApk'));
468480
});
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];
472485
}
473486
};
474487
}

src/type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export type EventType =
3838
| 'downloadingApk'
3939
| 'rejectStoragePermission'
4040
| 'errorStoragePermission'
41-
| 'errorDownloadAndInstallApk';
41+
| 'errorDownloadAndInstallApk'
42+
| 'errorInstallApk';
4243

4344
export interface EventData {
4445
currentVersion: string;

0 commit comments

Comments
 (0)