mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 01:16:09 +08:00
fix: new version
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
} from 'react-native';
|
||||
import { Pushy } from './client';
|
||||
import { isFirstTime } from './core';
|
||||
import { UpdateAvailableResult, CheckResult } from './type';
|
||||
import { CheckResult } from './type';
|
||||
import { PushyContext } from './context';
|
||||
|
||||
export const PushyProvider = ({
|
||||
@@ -56,38 +56,37 @@ export const PushyProvider = ({
|
||||
}
|
||||
}, [client, updateInfo]);
|
||||
|
||||
const doUpdate = useCallback(
|
||||
async (info: UpdateAvailableResult) => {
|
||||
try {
|
||||
const hash = await client.downloadUpdate(info);
|
||||
if (!hash) {
|
||||
return;
|
||||
}
|
||||
setUpdateInfo(info);
|
||||
stateListener.current && stateListener.current.remove();
|
||||
showAlert('Download complete', 'Do you want to apply the update now?', [
|
||||
{
|
||||
text: '下次再说',
|
||||
style: 'cancel',
|
||||
onPress: () => {
|
||||
client.switchVersionLater(hash);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '立即更新',
|
||||
style: 'default',
|
||||
onPress: () => {
|
||||
client.switchVersion(hash);
|
||||
},
|
||||
},
|
||||
]);
|
||||
} catch (err) {
|
||||
setLastError(err);
|
||||
showAlert('Failed to update', err.message);
|
||||
const downloadUpdate = useCallback(async () => {
|
||||
if (!updateInfo || !('update' in updateInfo)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const hash = await client.downloadUpdate(updateInfo);
|
||||
if (!hash) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
[client, showAlert],
|
||||
);
|
||||
stateListener.current && stateListener.current.remove();
|
||||
showAlert('Download complete', 'Do you want to apply the update now?', [
|
||||
{
|
||||
text: '下次再说',
|
||||
style: 'cancel',
|
||||
onPress: () => {
|
||||
client.switchVersionLater(hash);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '立即更新',
|
||||
style: 'default',
|
||||
onPress: () => {
|
||||
client.switchVersion(hash);
|
||||
},
|
||||
},
|
||||
]);
|
||||
} catch (err) {
|
||||
setLastError(err);
|
||||
showAlert('Failed to update', err.message);
|
||||
}
|
||||
}, [client, showAlert, updateInfo]);
|
||||
|
||||
const checkUpdate = useCallback(async () => {
|
||||
let info: CheckResult;
|
||||
@@ -98,9 +97,9 @@ export const PushyProvider = ({
|
||||
showAlert('Failed to check update', err.message);
|
||||
return;
|
||||
}
|
||||
setUpdateInfo(info);
|
||||
if ('expired' in info) {
|
||||
const { downloadUrl } = info;
|
||||
setUpdateInfo(info);
|
||||
showAlert(
|
||||
'Major update',
|
||||
'A full update is required to download and install to continue.',
|
||||
@@ -129,13 +128,13 @@ export const PushyProvider = ({
|
||||
text: '确定',
|
||||
style: 'default',
|
||||
onPress: () => {
|
||||
doUpdate(info as UpdateAvailableResult);
|
||||
downloadUpdate();
|
||||
},
|
||||
},
|
||||
],
|
||||
);
|
||||
}
|
||||
}, [client, doUpdate, showAlert]);
|
||||
}, [client, downloadUpdate, showAlert]);
|
||||
|
||||
const markSuccess = client.markSuccess;
|
||||
|
||||
@@ -179,6 +178,8 @@ export const PushyProvider = ({
|
||||
updateInfo,
|
||||
lastError,
|
||||
markSuccess,
|
||||
client,
|
||||
downloadUpdate,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
Reference in New Issue
Block a user