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