mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 02:56:11 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
946a5db7e9 | ||
![]() |
d4f21a39f5 | ||
![]() |
2192000d53 | ||
![]() |
9a49025884 |
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
presets: ['module:metro-react-native-babel-preset'],
|
||||
presets: ['module:@react-native/babel-preset'],
|
||||
env: {
|
||||
production: {
|
||||
plugins: ['react-native-paper/babel'],
|
||||
|
Binary file not shown.
@@ -11,13 +11,13 @@
|
||||
"lint": "eslint .",
|
||||
"postinstall": "patch-package",
|
||||
"apk": "cd android && ./gradlew assembleRelease",
|
||||
"dev": "react-native bundle-harmony --dev"
|
||||
"dev:harmony": "react-native bundle-harmony --dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"patch-package": "^8.0.0",
|
||||
"postinstall-postinstall": "^2.1.0",
|
||||
"react": "18.3.1",
|
||||
"react-native": "0.75.4",
|
||||
"react-native": "0.76.1",
|
||||
"react-native-camera-kit": "^14.0.0-beta15",
|
||||
"react-native-paper": "^5.12.5",
|
||||
"react-native-safe-area-context": "^4.11.1",
|
||||
@@ -25,23 +25,29 @@
|
||||
"react-native-vector-icons": "^10.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.25.9",
|
||||
"@babel/preset-env": "^7.25.9",
|
||||
"@babel/runtime": "^7.25.9",
|
||||
"@react-native/babel-preset": "0.75.4",
|
||||
"@react-native/eslint-config": "0.75.4",
|
||||
"@react-native/metro-config": "0.75.4",
|
||||
"@react-native/typescript-config": "0.75.4",
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-test-renderer": "^18.3.0",
|
||||
"babel-jest": "^29.7.0",
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.3",
|
||||
"@babel/runtime": "^7.25.0",
|
||||
"@react-native-community/cli": "15.0.0-alpha.2",
|
||||
"@react-native-community/cli-platform-android": "15.0.0-alpha.2",
|
||||
"@react-native-community/cli-platform-ios": "15.0.0-alpha.2",
|
||||
"@react-native/babel-preset": "0.76.1",
|
||||
"@react-native/eslint-config": "0.76.1",
|
||||
"@react-native/metro-config": "0.76.1",
|
||||
"@react-native/typescript-config": "0.76.1",
|
||||
"@types/react": "^18.2.6",
|
||||
"@types/react-test-renderer": "^18.0.0",
|
||||
"babel-jest": "^29.6.3",
|
||||
"eslint": "^8.19.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest": "^29.6.3",
|
||||
"prettier": "2.8.8",
|
||||
"react-test-renderer": "18.3.1",
|
||||
"typescript": "5.6.3"
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"trustedDependencies": [
|
||||
"postinstall-postinstall"
|
||||
]
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.15.3",
|
||||
"version": "10.17.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
@@ -69,10 +69,11 @@
|
||||
"fs-extra": "^11.2.0",
|
||||
"jest": "^29.7.0",
|
||||
"pod-install": "^0.2.2",
|
||||
"prettier": "^3",
|
||||
"prettier": "^2",
|
||||
"react": "18.2.0",
|
||||
"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];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ export const PushyContext = createContext<{
|
||||
switchVersionLater: () => Promise<void>;
|
||||
markSuccess: () => void;
|
||||
dismissError: () => void;
|
||||
downloadUpdate: () => Promise<void>;
|
||||
downloadUpdate: () => Promise<boolean | void>;
|
||||
downloadAndInstallApk: (url: string) => Promise<void>;
|
||||
getCurrentVersionInfo: () => Promise<{
|
||||
name?: string;
|
||||
|
@@ -90,18 +90,20 @@ export const PushyProvider = ({
|
||||
const downloadUpdate = useCallback(
|
||||
async (info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
if (!info || !info.update) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const hash = await client.downloadUpdate(info, setProgress);
|
||||
if (!hash) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
stateListener.current && stateListener.current.remove();
|
||||
if (options.updateStrategy === 'silentAndNow') {
|
||||
return client.switchVersion(hash);
|
||||
client.switchVersion(hash);
|
||||
return true;
|
||||
} else if (options.updateStrategy === 'silentAndLater') {
|
||||
return client.switchVersionLater(hash);
|
||||
client.switchVersionLater(hash);
|
||||
return true;
|
||||
}
|
||||
alertUpdate('提示', '下载完毕,是否立即更新?', [
|
||||
{
|
||||
@@ -119,10 +121,12 @@ export const PushyProvider = ({
|
||||
},
|
||||
},
|
||||
]);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
setLastError(e);
|
||||
alertError('更新失败', e.message);
|
||||
throwErrorIfEnabled(e);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -202,7 +206,8 @@ export const PushyProvider = ({
|
||||
options.updateStrategy === 'silentAndNow' ||
|
||||
options.updateStrategy === 'silentAndLater'
|
||||
) {
|
||||
return downloadUpdate(info);
|
||||
downloadUpdate(info);
|
||||
return;
|
||||
}
|
||||
alertUpdate(
|
||||
'提示',
|
||||
|
@@ -38,7 +38,8 @@ export type EventType =
|
||||
| 'downloadingApk'
|
||||
| 'rejectStoragePermission'
|
||||
| 'errorStoragePermission'
|
||||
| 'errorDownloadAndInstallApk';
|
||||
| 'errorDownloadAndInstallApk'
|
||||
| 'errorInstallApk';
|
||||
|
||||
export interface EventData {
|
||||
currentVersion: string;
|
||||
|
@@ -41,12 +41,12 @@ const ping =
|
||||
Promise.race([
|
||||
fetch(url, {
|
||||
method: 'HEAD',
|
||||
}).then(({ status }) => (status === 200 ? url : null)),
|
||||
})
|
||||
.then(({ status }) => (status === 200 ? url : null))
|
||||
.catch(() => null),
|
||||
new Promise(r => setTimeout(() => r(null), 2000)),
|
||||
]);
|
||||
|
||||
const canUseGoogle = ping('https://www.google.com');
|
||||
|
||||
export function joinUrls(paths: string[], fileName?: string) {
|
||||
if (fileName) {
|
||||
return paths.map(path => 'https://' + path + '/' + fileName);
|
||||
@@ -57,8 +57,5 @@ export const testUrls = async (urls?: string[]) => {
|
||||
if (!urls?.length) {
|
||||
return null;
|
||||
}
|
||||
if (await canUseGoogle) {
|
||||
return urls[0];
|
||||
}
|
||||
return promiseAny(urls.map(ping)).catch(() => null);
|
||||
};
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
# bun ./bun.lockb --hash: F85D92799AFF262A-7ffac79fcf85c731-89BCC22943BFB132-7245a25635ad115c
|
||||
# bun ./bun.lockb --hash: 2058EE9308759DAF-113fc986523daaf8-AF755908B492C9F6-6a66f4ed28448ee4
|
||||
|
||||
|
||||
"@ampproject/remapping@^2.2.0":
|
||||
@@ -8022,16 +8022,11 @@ prelude-ls@^1.2.1:
|
||||
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz"
|
||||
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
|
||||
|
||||
prettier@>=2:
|
||||
prettier@>=2, prettier@^2:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz"
|
||||
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
|
||||
|
||||
prettier@^3:
|
||||
version "3.3.3"
|
||||
resolved "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz"
|
||||
integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==
|
||||
|
||||
prettier-linter-helpers@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz"
|
||||
|
Reference in New Issue
Block a user