mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-07 15:45:14 +08:00
add return value for downloadupdate
This commit is contained in:
@@ -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(
|
||||
'提示',
|
||||
|
Reference in New Issue
Block a user