1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 08:41:37 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

add return value for downloadupdate

This commit is contained in:
sunnylqm
2024-11-23 16:09:43 +08:00
parent 9a49025884
commit 2192000d53
5 changed files with 15 additions and 15 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.15.3",
"version": "10.16.0",
"description": "react-native hot update",
"main": "src/index",
"scripts": {
@@ -69,7 +69,7 @@
"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",

View File

@@ -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;

View File

@@ -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(
'提示',

View File

@@ -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"