mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 10:21:37 +08:00
v10.17.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.16.0",
|
||||
"version": "10.17.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
@@ -74,5 +74,6 @@
|
||||
"react-native": "0.73",
|
||||
"ts-jest": "^29.2.5",
|
||||
"typescript": "^5.6.3"
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
|
||||
}
|
||||
|
@@ -43,11 +43,13 @@ export class Pushy {
|
||||
lastChecking?: number;
|
||||
lastRespJson?: Promise<any>;
|
||||
|
||||
progressHandlers: Record<string, EmitterSubscription> = {};
|
||||
downloadedHash?: string;
|
||||
static progressHandlers: Record<string, EmitterSubscription> = {};
|
||||
static downloadedHash?: string;
|
||||
|
||||
marked = false;
|
||||
applyingUpdate = false;
|
||||
static apkStatus: 'downloading' | 'downloaded' | null = null;
|
||||
|
||||
static marked = false;
|
||||
static applyingUpdate = false;
|
||||
version = cInfo.pushy;
|
||||
loggerPromise = (() => {
|
||||
let resolve: (value?: unknown) => void = () => {};
|
||||
@@ -121,21 +123,21 @@ export class Pushy {
|
||||
getCheckUrl = (endpoint: string = this.options.server!.main) => {
|
||||
return `${endpoint}/checkUpdate/${this.options.appKey}`;
|
||||
};
|
||||
assertHash = (hash: string) => {
|
||||
if (!this.downloadedHash) {
|
||||
static assertHash = (hash: string) => {
|
||||
if (!Pushy.downloadedHash) {
|
||||
return;
|
||||
}
|
||||
if (hash !== this.downloadedHash) {
|
||||
log(`use downloaded hash ${this.downloadedHash} first`);
|
||||
if (hash !== Pushy.downloadedHash) {
|
||||
log(`use downloaded hash ${Pushy.downloadedHash} first`);
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
markSuccess = () => {
|
||||
if (this.marked || __DEV__ || !isFirstTime) {
|
||||
if (Pushy.marked || __DEV__ || !isFirstTime) {
|
||||
return;
|
||||
}
|
||||
this.marked = true;
|
||||
Pushy.marked = true;
|
||||
PushyModule.markSuccess();
|
||||
this.report({ type: 'markSuccess' });
|
||||
};
|
||||
@@ -146,9 +148,9 @@ export class Pushy {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (this.assertHash(hash) && !this.applyingUpdate) {
|
||||
if (Pushy.assertHash(hash) && !Pushy.applyingUpdate) {
|
||||
log('switchVersion: ' + hash);
|
||||
this.applyingUpdate = true;
|
||||
Pushy.applyingUpdate = true;
|
||||
return PushyModule.reloadUpdate({ hash });
|
||||
}
|
||||
};
|
||||
@@ -160,7 +162,7 @@ export class Pushy {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (this.assertHash(hash)) {
|
||||
if (Pushy.assertHash(hash)) {
|
||||
log('switchVersionLater: ' + hash);
|
||||
return PushyModule.setNeedUpdate({ hash });
|
||||
}
|
||||
@@ -314,15 +316,15 @@ export class Pushy {
|
||||
log(`rolledback hash ${rolledBackVersion}, ignored`);
|
||||
return;
|
||||
}
|
||||
if (this.downloadedHash === hash) {
|
||||
log(`duplicated downloaded hash ${this.downloadedHash}, ignored`);
|
||||
return this.downloadedHash;
|
||||
if (Pushy.downloadedHash === hash) {
|
||||
log(`duplicated downloaded hash ${Pushy.downloadedHash}, ignored`);
|
||||
return Pushy.downloadedHash;
|
||||
}
|
||||
if (this.progressHandlers[hash]) {
|
||||
if (Pushy.progressHandlers[hash]) {
|
||||
return;
|
||||
}
|
||||
if (onDownloadProgress) {
|
||||
this.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
|
||||
Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
|
||||
'RCTPushyDownloadProgress',
|
||||
progressData => {
|
||||
if (progressData.hash === hash) {
|
||||
@@ -389,9 +391,9 @@ export class Pushy {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.progressHandlers[hash]) {
|
||||
this.progressHandlers[hash].remove();
|
||||
delete this.progressHandlers[hash];
|
||||
if (Pushy.progressHandlers[hash]) {
|
||||
Pushy.progressHandlers[hash].remove();
|
||||
delete Pushy.progressHandlers[hash];
|
||||
}
|
||||
if (__DEV__) {
|
||||
return hash;
|
||||
@@ -417,7 +419,7 @@ export class Pushy {
|
||||
description,
|
||||
metaInfo,
|
||||
});
|
||||
this.downloadedHash = hash;
|
||||
Pushy.downloadedHash = hash;
|
||||
return hash;
|
||||
};
|
||||
downloadAndInstallApk = async (
|
||||
@@ -427,7 +429,14 @@ export class Pushy {
|
||||
if (Platform.OS !== 'android') {
|
||||
return;
|
||||
}
|
||||
this.report({ type: 'downloadingApk' });
|
||||
if (Pushy.apkStatus === 'downloading') {
|
||||
return;
|
||||
}
|
||||
if (Pushy.apkStatus === 'downloaded') {
|
||||
this.report({ type: 'errorInstallApk' });
|
||||
this.throwIfEnabled(new Error('errorInstallApk'));
|
||||
return;
|
||||
}
|
||||
if (Platform.Version <= 23) {
|
||||
try {
|
||||
const granted = await PermissionsAndroid.request(
|
||||
@@ -444,12 +453,14 @@ export class Pushy {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Pushy.apkStatus = 'downloading';
|
||||
this.report({ type: 'downloadingApk' });
|
||||
const progressKey = 'downloadingApk';
|
||||
if (onDownloadProgress) {
|
||||
if (this.progressHandlers[progressKey]) {
|
||||
this.progressHandlers[progressKey].remove();
|
||||
if (Pushy.progressHandlers[progressKey]) {
|
||||
Pushy.progressHandlers[progressKey].remove();
|
||||
}
|
||||
this.progressHandlers[progressKey] = pushyNativeEventEmitter.addListener(
|
||||
Pushy.progressHandlers[progressKey] = pushyNativeEventEmitter.addListener(
|
||||
'RCTPushyDownloadProgress',
|
||||
(progressData: ProgressData) => {
|
||||
if (progressData.hash === progressKey) {
|
||||
@@ -463,12 +474,14 @@ export class Pushy {
|
||||
target: 'update.apk',
|
||||
hash: progressKey,
|
||||
}).catch(() => {
|
||||
Pushy.apkStatus = null;
|
||||
this.report({ type: 'errorDownloadAndInstallApk' });
|
||||
this.throwIfEnabled(new Error('errorDownloadAndInstallApk'));
|
||||
});
|
||||
if (this.progressHandlers[progressKey]) {
|
||||
this.progressHandlers[progressKey].remove();
|
||||
delete this.progressHandlers[progressKey];
|
||||
Pushy.apkStatus = 'downloaded';
|
||||
if (Pushy.progressHandlers[progressKey]) {
|
||||
Pushy.progressHandlers[progressKey].remove();
|
||||
delete Pushy.progressHandlers[progressKey];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -38,7 +38,8 @@ export type EventType =
|
||||
| 'downloadingApk'
|
||||
| 'rejectStoragePermission'
|
||||
| 'errorStoragePermission'
|
||||
| 'errorDownloadAndInstallApk';
|
||||
| 'errorDownloadAndInstallApk'
|
||||
| 'errorInstallApk';
|
||||
|
||||
export interface EventData {
|
||||
currentVersion: string;
|
||||
|
Reference in New Issue
Block a user