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", "name": "react-native-update",
"version": "10.6.0", "version": "10.7.0",
"description": "react-native hot update", "description": "react-native hot update",
"main": "src/index", "main": "src/index",
"scripts": { "scripts": {

View File

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

View File

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