1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
sunnylqm 2024-06-25 11:45:10 +08:00
parent b62e6d64cf
commit 4fb0c691e6
No known key found for this signature in database
3 changed files with 28 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.6.0",
"version": "10.7.0",
"description": "react-native hot update",
"main": "src/index",
"scripts": {

View File

@ -41,7 +41,19 @@ export const PushyProvider = ({
setLastError(undefined);
}, []);
const showAlert = useCallback(
const alertUpdate = useCallback(
(...args: Parameters<typeof Alert.alert>) => {
if (
options.updateStrategy === 'alwaysAlert' ||
options.updateStrategy === 'alertUpdateAndIgnoreError'
) {
Alert.alert(...args);
}
},
[options.updateStrategy],
);
const alertError = useCallback(
(...args: Parameters<typeof Alert.alert>) => {
if (options.updateStrategy === 'alwaysAlert') {
Alert.alert(...args);
@ -78,7 +90,7 @@ export const PushyProvider = ({
} else if (options.updateStrategy === 'silentAndLater') {
return client.switchVersionLater(hash);
}
showAlert('提示', '下载完毕,是否立即更新?', [
alertUpdate('提示', '下载完毕,是否立即更新?', [
{
text: '下次再说',
style: 'cancel',
@ -96,10 +108,10 @@ export const PushyProvider = ({
]);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
alertError('更新失败', e.message);
}
},
[client, options.updateStrategy, showAlert],
[alertError, client, options.updateStrategy, alertUpdate],
);
const downloadAndInstallApk = useCallback(
@ -122,7 +134,7 @@ export const PushyProvider = ({
info = await client.checkUpdate();
} catch (e: any) {
setLastError(e);
showAlert('更新检查失败', e.message);
alertError('更新检查失败', e.message);
return;
}
if (!info) {
@ -141,7 +153,7 @@ export const PushyProvider = ({
}
return;
}
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
alertUpdate('提示', '您的应用版本已更新,点击更新下载安装新版本', [
{
text: '更新',
onPress: () => {
@ -161,7 +173,7 @@ export const PushyProvider = ({
) {
return downloadUpdate(info);
}
showAlert(
alertUpdate(
'提示',
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
[
@ -177,11 +189,12 @@ export const PushyProvider = ({
);
}
}, [
alertError,
client,
downloadAndInstallApk,
downloadUpdate,
options.updateStrategy,
showAlert,
alertUpdate,
]);
const markSuccess = client.markSuccess;

View File

@ -69,7 +69,12 @@ export interface PushyOptions {
appKey: string;
server?: PushyServerConfig;
logger?: UpdateEventsLogger;
updateStrategy?: 'alwaysAlert' | 'silentAndNow' | 'silentAndLater' | null;
updateStrategy?:
| 'alwaysAlert'
| 'alertUpdateAndIgnoreError'
| 'silentAndNow'
| 'silentAndLater'
| null;
checkStrategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
autoMarkSuccess?: boolean;
dismissErrorAfter?: number;