Skip to content

Commit 2192000

Browse files
committed
add return value for downloadupdate
1 parent 9a49025 commit 2192000

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

bun.lockb

-320 Bytes
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update",
3-
"version": "10.15.3",
3+
"version": "10.16.0",
44
"description": "react-native hot update",
55
"main": "src/index",
66
"scripts": {
@@ -69,7 +69,7 @@
6969
"fs-extra": "^11.2.0",
7070
"jest": "^29.7.0",
7171
"pod-install": "^0.2.2",
72-
"prettier": "^3",
72+
"prettier": "^2",
7373
"react": "18.2.0",
7474
"react-native": "0.73",
7575
"ts-jest": "^29.2.5",

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const PushyContext = createContext<{
2525
switchVersionLater: () => Promise<void>;
2626
markSuccess: () => void;
2727
dismissError: () => void;
28-
downloadUpdate: () => Promise<void>;
28+
downloadUpdate: () => Promise<boolean | void>;
2929
downloadAndInstallApk: (url: string) => Promise<void>;
3030
getCurrentVersionInfo: () => Promise<{
3131
name?: string;

src/provider.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,20 @@ export const PushyProvider = ({
9090
const downloadUpdate = useCallback(
9191
async (info: CheckResult | undefined = updateInfoRef.current) => {
9292
if (!info || !info.update) {
93-
return;
93+
return false;
9494
}
9595
try {
9696
const hash = await client.downloadUpdate(info, setProgress);
9797
if (!hash) {
98-
return;
98+
return false;
9999
}
100100
stateListener.current && stateListener.current.remove();
101101
if (options.updateStrategy === 'silentAndNow') {
102-
return client.switchVersion(hash);
102+
client.switchVersion(hash);
103+
return true;
103104
} else if (options.updateStrategy === 'silentAndLater') {
104-
return client.switchVersionLater(hash);
105+
client.switchVersionLater(hash);
106+
return true;
105107
}
106108
alertUpdate('提示', '下载完毕,是否立即更新?', [
107109
{
@@ -119,10 +121,12 @@ export const PushyProvider = ({
119121
},
120122
},
121123
]);
124+
return true;
122125
} catch (e: any) {
123126
setLastError(e);
124127
alertError('更新失败', e.message);
125128
throwErrorIfEnabled(e);
129+
return false;
126130
}
127131
},
128132
[
@@ -202,7 +206,8 @@ export const PushyProvider = ({
202206
options.updateStrategy === 'silentAndNow' ||
203207
options.updateStrategy === 'silentAndLater'
204208
) {
205-
return downloadUpdate(info);
209+
downloadUpdate(info);
210+
return;
206211
}
207212
alertUpdate(
208213
'提示',

yarn.lock

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
22
# yarn lockfile v1
3-
# bun ./bun.lockb --hash: F85D92799AFF262A-7ffac79fcf85c731-89BCC22943BFB132-7245a25635ad115c
3+
# bun ./bun.lockb --hash: 2058EE9308759DAF-113fc986523daaf8-AF755908B492C9F6-6a66f4ed28448ee4
44

55

66
"@ampproject/remapping@^2.2.0":
@@ -8022,16 +8022,11 @@ prelude-ls@^1.2.1:
80228022
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz"
80238023
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
80248024

8025-
prettier@>=2:
8025+
prettier@>=2, prettier@^2:
80268026
version "2.8.8"
80278027
resolved "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz"
80288028
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
80298029

8030-
prettier@^3:
8031-
version "3.3.3"
8032-
resolved "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz"
8033-
integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==
8034-
80358030
prettier-linter-helpers@^1.0.0:
80368031
version "1.0.0"
80378032
resolved "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz"

0 commit comments

Comments
 (0)