1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-17 21:56:11 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

..

2 Commits

Author SHA1 Message Date
sunnylqm
a6d4befca2 v10.7.1 2024-06-25 12:33:53 +08:00
sunnylqm
4fb0c691e6 v10.7.0 2024-06-25 12:26:18 +08:00
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.7.0", "version": "10.7.1",
"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;