react-native-update 10.28.0 → 10.28.2
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.
|
@@ -99,7 +99,7 @@ public class UpdateModule extends NativePushySpec {
|
|
|
99
99
|
|
|
100
100
|
@Override
|
|
101
101
|
public void restartApp(Promise promise) {
|
|
102
|
-
UpdateModuleImpl.restartApp(
|
|
102
|
+
UpdateModuleImpl.restartApp(mContext, promise);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
@Override
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
setLocalHashInfo,
|
|
27
27
|
isFirstTime,
|
|
28
28
|
isRolledBack,
|
|
29
|
+
getCurrentVersionInfo,
|
|
29
30
|
} from './core';
|
|
30
31
|
|
|
31
32
|
const SERVER_PRESETS = {
|
|
@@ -60,6 +61,31 @@ const defaultClientOptions: ClientOptions = {
|
|
|
60
61
|
throwError: false,
|
|
61
62
|
};
|
|
62
63
|
|
|
64
|
+
export const sharedState: {
|
|
65
|
+
progressHandlers: Record<string, EmitterSubscription>;
|
|
66
|
+
downloadedHash?: string;
|
|
67
|
+
apkStatus: 'downloading' | 'downloaded' | null;
|
|
68
|
+
marked: boolean;
|
|
69
|
+
applyingUpdate: boolean;
|
|
70
|
+
} = {
|
|
71
|
+
progressHandlers: {},
|
|
72
|
+
downloadedHash: undefined,
|
|
73
|
+
apkStatus: null,
|
|
74
|
+
marked: false,
|
|
75
|
+
applyingUpdate: false,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const assertHash = (hash: string) => {
|
|
79
|
+
if (!sharedState.downloadedHash) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (hash !== sharedState.downloadedHash) {
|
|
83
|
+
log(`use downloaded hash ${sharedState.downloadedHash} first`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
};
|
|
88
|
+
|
|
63
89
|
// for China users
|
|
64
90
|
export class Pushy {
|
|
65
91
|
options = defaultClientOptions;
|
|
@@ -67,13 +93,6 @@ export class Pushy {
|
|
|
67
93
|
lastChecking?: number;
|
|
68
94
|
lastRespJson?: Promise<any>;
|
|
69
95
|
|
|
70
|
-
static progressHandlers: Record<string, EmitterSubscription> = {};
|
|
71
|
-
static downloadedHash?: string;
|
|
72
|
-
|
|
73
|
-
static apkStatus: 'downloading' | 'downloaded' | null = null;
|
|
74
|
-
|
|
75
|
-
static marked = false;
|
|
76
|
-
static applyingUpdate = false;
|
|
77
96
|
version = cInfo.rnu;
|
|
78
97
|
loggerPromise = (() => {
|
|
79
98
|
let resolve: (value?: unknown) => void = () => {};
|
|
@@ -128,6 +147,7 @@ export class Pushy {
|
|
|
128
147
|
log(type + ' ' + message);
|
|
129
148
|
await this.loggerPromise.promise;
|
|
130
149
|
const { logger = noop, appKey } = this.options;
|
|
150
|
+
const info = await getCurrentVersionInfo();
|
|
131
151
|
logger({
|
|
132
152
|
type,
|
|
133
153
|
data: {
|
|
@@ -137,6 +157,7 @@ export class Pushy {
|
|
|
137
157
|
packageVersion,
|
|
138
158
|
buildTime,
|
|
139
159
|
message,
|
|
160
|
+
...info,
|
|
140
161
|
...data,
|
|
141
162
|
},
|
|
142
163
|
});
|
|
@@ -149,16 +170,6 @@ export class Pushy {
|
|
|
149
170
|
getCheckUrl = (endpoint: string = this.options.server!.main) => {
|
|
150
171
|
return `${endpoint}/checkUpdate/${this.options.appKey}`;
|
|
151
172
|
};
|
|
152
|
-
static assertHash = (hash: string) => {
|
|
153
|
-
if (!this.downloadedHash) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (hash !== this.downloadedHash) {
|
|
157
|
-
log(`use downloaded hash ${Pushy.downloadedHash} first`);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
return true;
|
|
161
|
-
};
|
|
162
173
|
assertDebug = () => {
|
|
163
174
|
if (__DEV__ && !this.options.debug) {
|
|
164
175
|
console.info(
|
|
@@ -169,10 +180,10 @@ export class Pushy {
|
|
|
169
180
|
return true;
|
|
170
181
|
};
|
|
171
182
|
markSuccess = () => {
|
|
172
|
-
if (
|
|
183
|
+
if (sharedState.marked || __DEV__ || !isFirstTime) {
|
|
173
184
|
return;
|
|
174
185
|
}
|
|
175
|
-
|
|
186
|
+
sharedState.marked = true;
|
|
176
187
|
PushyModule.markSuccess();
|
|
177
188
|
this.report({ type: 'markSuccess' });
|
|
178
189
|
};
|
|
@@ -180,9 +191,9 @@ export class Pushy {
|
|
|
180
191
|
if (!assertDev('switchVersion()')) {
|
|
181
192
|
return;
|
|
182
193
|
}
|
|
183
|
-
if (
|
|
194
|
+
if (assertHash(hash) && !sharedState.applyingUpdate) {
|
|
184
195
|
log('switchVersion: ' + hash);
|
|
185
|
-
|
|
196
|
+
sharedState.applyingUpdate = true;
|
|
186
197
|
return PushyModule.reloadUpdate({ hash });
|
|
187
198
|
}
|
|
188
199
|
};
|
|
@@ -191,7 +202,7 @@ export class Pushy {
|
|
|
191
202
|
if (!assertDev('switchVersionLater()')) {
|
|
192
203
|
return;
|
|
193
204
|
}
|
|
194
|
-
if (
|
|
205
|
+
if (assertHash(hash)) {
|
|
195
206
|
log('switchVersionLater: ' + hash);
|
|
196
207
|
return PushyModule.setNeedUpdate({ hash });
|
|
197
208
|
}
|
|
@@ -346,18 +357,18 @@ export class Pushy {
|
|
|
346
357
|
log(`rolledback hash ${rolledBackVersion}, ignored`);
|
|
347
358
|
return;
|
|
348
359
|
}
|
|
349
|
-
if (
|
|
350
|
-
log(`duplicated downloaded hash ${
|
|
351
|
-
return
|
|
360
|
+
if (sharedState.downloadedHash === hash) {
|
|
361
|
+
log(`duplicated downloaded hash ${sharedState.downloadedHash}, ignored`);
|
|
362
|
+
return sharedState.downloadedHash;
|
|
352
363
|
}
|
|
353
|
-
if (
|
|
364
|
+
if (sharedState.progressHandlers[hash]) {
|
|
354
365
|
return;
|
|
355
366
|
}
|
|
356
367
|
const patchStartTime = Date.now();
|
|
357
368
|
if (onDownloadProgress) {
|
|
358
369
|
// @ts-expect-error harmony not in existing platforms
|
|
359
370
|
if (Platform.OS === 'harmony') {
|
|
360
|
-
|
|
371
|
+
sharedState.progressHandlers[hash] = DeviceEventEmitter.addListener(
|
|
361
372
|
'RCTPushyDownloadProgress',
|
|
362
373
|
progressData => {
|
|
363
374
|
if (progressData.hash === hash) {
|
|
@@ -366,14 +377,15 @@ export class Pushy {
|
|
|
366
377
|
},
|
|
367
378
|
);
|
|
368
379
|
} else {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
380
|
+
sharedState.progressHandlers[hash] =
|
|
381
|
+
pushyNativeEventEmitter.addListener(
|
|
382
|
+
'RCTPushyDownloadProgress',
|
|
383
|
+
progressData => {
|
|
384
|
+
if (progressData.hash === hash) {
|
|
385
|
+
onDownloadProgress(progressData);
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
);
|
|
377
389
|
}
|
|
378
390
|
}
|
|
379
391
|
let succeeded = '';
|
|
@@ -441,9 +453,9 @@ export class Pushy {
|
|
|
441
453
|
}
|
|
442
454
|
}
|
|
443
455
|
}
|
|
444
|
-
if (
|
|
445
|
-
|
|
446
|
-
delete
|
|
456
|
+
if (sharedState.progressHandlers[hash]) {
|
|
457
|
+
sharedState.progressHandlers[hash].remove();
|
|
458
|
+
delete sharedState.progressHandlers[hash];
|
|
447
459
|
}
|
|
448
460
|
if (__DEV__) {
|
|
449
461
|
return hash;
|
|
@@ -479,7 +491,7 @@ export class Pushy {
|
|
|
479
491
|
description,
|
|
480
492
|
metaInfo,
|
|
481
493
|
});
|
|
482
|
-
|
|
494
|
+
sharedState.downloadedHash = hash;
|
|
483
495
|
return hash;
|
|
484
496
|
};
|
|
485
497
|
downloadAndInstallApk = async (
|
|
@@ -489,10 +501,10 @@ export class Pushy {
|
|
|
489
501
|
if (Platform.OS !== 'android') {
|
|
490
502
|
return;
|
|
491
503
|
}
|
|
492
|
-
if (
|
|
504
|
+
if (sharedState.apkStatus === 'downloading') {
|
|
493
505
|
return;
|
|
494
506
|
}
|
|
495
|
-
if (
|
|
507
|
+
if (sharedState.apkStatus === 'downloaded') {
|
|
496
508
|
this.report({ type: 'errorInstallApk' });
|
|
497
509
|
this.throwIfEnabled(new Error('errorInstallApk'));
|
|
498
510
|
return;
|
|
@@ -513,35 +525,36 @@ export class Pushy {
|
|
|
513
525
|
return;
|
|
514
526
|
}
|
|
515
527
|
}
|
|
516
|
-
|
|
528
|
+
sharedState.apkStatus = 'downloading';
|
|
517
529
|
this.report({ type: 'downloadingApk' });
|
|
518
530
|
const progressKey = 'downloadingApk';
|
|
519
531
|
if (onDownloadProgress) {
|
|
520
|
-
if (
|
|
521
|
-
|
|
532
|
+
if (sharedState.progressHandlers[progressKey]) {
|
|
533
|
+
sharedState.progressHandlers[progressKey].remove();
|
|
522
534
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
535
|
+
sharedState.progressHandlers[progressKey] =
|
|
536
|
+
pushyNativeEventEmitter.addListener(
|
|
537
|
+
'RCTPushyDownloadProgress',
|
|
538
|
+
(progressData: ProgressData) => {
|
|
539
|
+
if (progressData.hash === progressKey) {
|
|
540
|
+
onDownloadProgress(progressData);
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
);
|
|
531
544
|
}
|
|
532
545
|
await PushyModule.downloadAndInstallApk({
|
|
533
546
|
url,
|
|
534
547
|
target: 'update.apk',
|
|
535
548
|
hash: progressKey,
|
|
536
549
|
}).catch(() => {
|
|
537
|
-
|
|
550
|
+
sharedState.apkStatus = null;
|
|
538
551
|
this.report({ type: 'errorDownloadAndInstallApk' });
|
|
539
552
|
this.throwIfEnabled(new Error('errorDownloadAndInstallApk'));
|
|
540
553
|
});
|
|
541
|
-
|
|
542
|
-
if (
|
|
543
|
-
|
|
544
|
-
delete
|
|
554
|
+
sharedState.apkStatus = 'downloaded';
|
|
555
|
+
if (sharedState.progressHandlers[progressKey]) {
|
|
556
|
+
sharedState.progressHandlers[progressKey].remove();
|
|
557
|
+
delete sharedState.progressHandlers[progressKey];
|
|
545
558
|
}
|
|
546
559
|
};
|
|
547
560
|
restartApp = async () => {
|
package/src/provider.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
Platform,
|
|
13
13
|
Linking,
|
|
14
14
|
} from 'react-native';
|
|
15
|
-
import { Pushy, Cresc } from './client';
|
|
15
|
+
import { Pushy, Cresc, sharedState } from './client';
|
|
16
16
|
import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
|
|
17
17
|
import { CheckResult, ProgressData, UpdateTestPayload } from './type';
|
|
18
18
|
import { UpdateContext } from './context';
|
|
@@ -171,7 +171,7 @@ export const UpdateProvider = ({
|
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
const rollout = info.config?.rollout?.[packageVersion];
|
|
174
|
-
if (rollout) {
|
|
174
|
+
if (info.update && rollout) {
|
|
175
175
|
if (!isInRollout(rollout)) {
|
|
176
176
|
log(`not in ${rollout}% rollout, ignored`);
|
|
177
177
|
return;
|
|
@@ -182,8 +182,15 @@ export const UpdateProvider = ({
|
|
|
182
182
|
updateInfoRef.current = info;
|
|
183
183
|
setUpdateInfo(info);
|
|
184
184
|
if (info.expired) {
|
|
185
|
+
if (
|
|
186
|
+
options.onPackageExpired &&
|
|
187
|
+
(await options.onPackageExpired(info)) === false
|
|
188
|
+
) {
|
|
189
|
+
log('onPackageExpired returned false, skipping');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
185
192
|
const { downloadUrl } = info;
|
|
186
|
-
if (downloadUrl &&
|
|
193
|
+
if (downloadUrl && sharedState.apkStatus === null) {
|
|
187
194
|
if (options.updateStrategy === 'silentAndNow') {
|
|
188
195
|
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
|
|
189
196
|
downloadAndInstallApk(downloadUrl);
|
|
@@ -234,7 +241,7 @@ export const UpdateProvider = ({
|
|
|
234
241
|
client,
|
|
235
242
|
alertError,
|
|
236
243
|
throwErrorIfEnabled,
|
|
237
|
-
options
|
|
244
|
+
options,
|
|
238
245
|
alertUpdate,
|
|
239
246
|
downloadAndInstallApk,
|
|
240
247
|
downloadUpdate,
|
package/src/type.ts
CHANGED
|
@@ -54,6 +54,9 @@ export interface EventData {
|
|
|
54
54
|
message?: string;
|
|
55
55
|
rolledBackVersion?: string;
|
|
56
56
|
newVersion?: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
metaInfo?: string;
|
|
57
60
|
[key: string]: any;
|
|
58
61
|
}
|
|
59
62
|
|
|
@@ -89,6 +92,7 @@ export interface ClientOptions {
|
|
|
89
92
|
beforeCheckUpdate?: () => Promise<boolean>;
|
|
90
93
|
beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
|
|
91
94
|
afterDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
|
|
95
|
+
onPackageExpired?: (info: CheckResult) => Promise<boolean>;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
export interface UpdateTestPayload {
|
package/src/utils.ts
CHANGED
|
@@ -62,7 +62,7 @@ const ping =
|
|
|
62
62
|
if (!pingFinished) {
|
|
63
63
|
log('ping timeout', url);
|
|
64
64
|
}
|
|
65
|
-
},
|
|
65
|
+
}, 5000),
|
|
66
66
|
),
|
|
67
67
|
]);
|
|
68
68
|
};
|
|
@@ -81,6 +81,7 @@ export const testUrls = async (urls?: string[]) => {
|
|
|
81
81
|
try {
|
|
82
82
|
const ret = await promiseAny(urls.map(ping));
|
|
83
83
|
if (ret) {
|
|
84
|
+
log('ping success, use url:', ret);
|
|
84
85
|
return ret;
|
|
85
86
|
}
|
|
86
87
|
} catch {}
|