Skip to content

Commit

Permalink
v10.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Jun 25, 2024
1 parent b62e6d6 commit 4fb0c69
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
29 changes: 21 additions & 8 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -78,7 +90,7 @@ export const PushyProvider = ({
} else if (options.updateStrategy === 'silentAndLater') {
return client.switchVersionLater(hash);
}
showAlert('提示', '下载完毕,是否立即更新?', [
alertUpdate('提示', '下载完毕,是否立即更新?', [
{
text: '下次再说',
style: 'cancel',
Expand All @@ -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(
Expand All @@ -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) {
Expand All @@ -141,7 +153,7 @@ export const PushyProvider = ({
}
return;
}
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
alertUpdate('提示', '您的应用版本已更新,点击更新下载安装新版本', [
{
text: '更新',
onPress: () => {
Expand All @@ -161,7 +173,7 @@ export const PushyProvider = ({
) {
return downloadUpdate(info);
}
showAlert(
alertUpdate(
'提示',
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
[
Expand All @@ -177,11 +189,12 @@ export const PushyProvider = ({
);
}
}, [
alertError,
client,
downloadAndInstallApk,
downloadUpdate,
options.updateStrategy,
showAlert,
alertUpdate,
]);

const markSuccess = client.markSuccess;
Expand Down
7 changes: 6 additions & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4fb0c69

Please sign in to comment.