mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 10:21:37 +08:00
v10.6.0-beta.0
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
"react-native": "0.69.8",
|
"react-native": "0.69.8",
|
||||||
"react-native-paper": "^5.12.1",
|
"react-native-paper": "^5.12.1",
|
||||||
"react-native-safe-area-context": "^4.8.2",
|
"react-native-safe-area-context": "^4.8.2",
|
||||||
"react-native-update": "^10.5.3",
|
"react-native-update": "^10.5.4",
|
||||||
"react-native-vector-icons": "^10.0.3"
|
"react-native-vector-icons": "^10.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@@ -6231,10 +6231,10 @@ react-native-safe-area-context@^4.8.2:
|
|||||||
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.8.2.tgz#e6b3d8acf3c6afcb4b5db03a97f9c37df7668f65"
|
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.8.2.tgz#e6b3d8acf3c6afcb4b5db03a97f9c37df7668f65"
|
||||||
integrity sha512-ffUOv8BJQ6RqO3nLml5gxJ6ab3EestPiyWekxdzO/1MQ7NF8fW1Mzh1C5QE9yq573Xefnc7FuzGXjtesZGv7cQ==
|
integrity sha512-ffUOv8BJQ6RqO3nLml5gxJ6ab3EestPiyWekxdzO/1MQ7NF8fW1Mzh1C5QE9yq573Xefnc7FuzGXjtesZGv7cQ==
|
||||||
|
|
||||||
react-native-update@^10.2.6:
|
react-native-update@^10.5.4:
|
||||||
version "10.2.6"
|
version "10.5.4"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.2.6.tgz#976c1d1b48ac3522677b5ecbfe3e64fa04df1839"
|
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.5.4.tgz#00bb26ad021bb85b12f0daa435fb118259c816e1"
|
||||||
integrity sha512-x72ga106wEWsinHSN/ANk+YygvGq6hyTEVOCibakps7Wb+5JgTiMeE0p2+GOOPhuxMavEHiil5WdhYOipI3/Qg==
|
integrity sha512-6/AmsS8lOy5dJC4urWtFvhGmnqGJbabN2xnMVkZz5thLiMjcrNXipzpAN6FlHezdyPq/7wrsDCzpcgBnQKQRRg==
|
||||||
dependencies:
|
dependencies:
|
||||||
nanoid "^3.3.3"
|
nanoid "^3.3.3"
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "10.5.4",
|
"version": "10.6.0-beta.0",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "src/index",
|
"main": "src/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@@ -18,7 +18,7 @@ const defaultServer = {
|
|||||||
main: 'https://update.react-native.cn/api',
|
main: 'https://update.react-native.cn/api',
|
||||||
backups: ['https://update.reactnative.cn/api'],
|
backups: ['https://update.reactnative.cn/api'],
|
||||||
queryUrl:
|
queryUrl:
|
||||||
'https://raw.githubusercontent.com/reactnativecn/react-native-pushy/master/endpoints.json',
|
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
|
||||||
};
|
};
|
||||||
|
|
||||||
const empty = {};
|
const empty = {};
|
||||||
@@ -33,8 +33,8 @@ export class Pushy {
|
|||||||
appKey: '',
|
appKey: '',
|
||||||
server: defaultServer,
|
server: defaultServer,
|
||||||
autoMarkSuccess: true,
|
autoMarkSuccess: true,
|
||||||
useAlert: true,
|
updateStrategy: 'alwaysAsk',
|
||||||
strategy: 'both',
|
checkStrategy: 'both',
|
||||||
logger: noop,
|
logger: noop,
|
||||||
debug: false,
|
debug: false,
|
||||||
};
|
};
|
||||||
|
@@ -43,7 +43,7 @@ export const PushyProvider = ({
|
|||||||
|
|
||||||
const showAlert = useCallback(
|
const showAlert = useCallback(
|
||||||
(...args: Parameters<typeof Alert.alert>) => {
|
(...args: Parameters<typeof Alert.alert>) => {
|
||||||
if (options.useAlert) {
|
if (options.updateStrategy === 'alwaysAlert') {
|
||||||
Alert.alert(...args);
|
Alert.alert(...args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -73,6 +73,11 @@ export const PushyProvider = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stateListener.current && stateListener.current.remove();
|
stateListener.current && stateListener.current.remove();
|
||||||
|
if (options.updateStrategy === 'silentAndNow') {
|
||||||
|
return client.switchVersion(hash);
|
||||||
|
} else if (options.updateStrategy === 'silentAndLater') {
|
||||||
|
return client.switchVersionLater(hash);
|
||||||
|
}
|
||||||
showAlert('提示', '下载完毕,是否立即更新?', [
|
showAlert('提示', '下载完毕,是否立即更新?', [
|
||||||
{
|
{
|
||||||
text: '下次再说',
|
text: '下次再说',
|
||||||
@@ -94,7 +99,7 @@ export const PushyProvider = ({
|
|||||||
showAlert('更新失败', e.message);
|
showAlert('更新失败', e.message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[client, showAlert],
|
[client, options.updateStrategy, showAlert],
|
||||||
);
|
);
|
||||||
|
|
||||||
const downloadAndInstallApk = useCallback(
|
const downloadAndInstallApk = useCallback(
|
||||||
@@ -128,6 +133,14 @@ export const PushyProvider = ({
|
|||||||
if (info.expired) {
|
if (info.expired) {
|
||||||
const { downloadUrl } = info;
|
const { downloadUrl } = info;
|
||||||
if (downloadUrl) {
|
if (downloadUrl) {
|
||||||
|
if (options.updateStrategy === 'silentAndNow') {
|
||||||
|
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
|
||||||
|
downloadAndInstallApk(downloadUrl);
|
||||||
|
} else {
|
||||||
|
Linking.openURL(downloadUrl);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
|
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
|
||||||
{
|
{
|
||||||
text: '更新',
|
text: '更新',
|
||||||
@@ -142,6 +155,12 @@ export const PushyProvider = ({
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} else if (info.update) {
|
} else if (info.update) {
|
||||||
|
if (
|
||||||
|
options.updateStrategy === 'silentAndNow' ||
|
||||||
|
options.updateStrategy === 'silentAndLater'
|
||||||
|
) {
|
||||||
|
return downloadUpdate(info);
|
||||||
|
}
|
||||||
showAlert(
|
showAlert(
|
||||||
'提示',
|
'提示',
|
||||||
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
|
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
|
||||||
@@ -157,7 +176,13 @@ export const PushyProvider = ({
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [client, downloadAndInstallApk, downloadUpdate, showAlert]);
|
}, [
|
||||||
|
client,
|
||||||
|
downloadAndInstallApk,
|
||||||
|
downloadUpdate,
|
||||||
|
options.updateStrategy,
|
||||||
|
showAlert,
|
||||||
|
]);
|
||||||
|
|
||||||
const markSuccess = client.markSuccess;
|
const markSuccess = client.markSuccess;
|
||||||
|
|
||||||
@@ -168,11 +193,11 @@ export const PushyProvider = ({
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { strategy, dismissErrorAfter, autoMarkSuccess } = options;
|
const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options;
|
||||||
if (isFirstTime && autoMarkSuccess) {
|
if (isFirstTime && autoMarkSuccess) {
|
||||||
markSuccess();
|
markSuccess();
|
||||||
}
|
}
|
||||||
if (strategy === 'both' || strategy === 'onAppResume') {
|
if (checkStrategy === 'both' || checkStrategy === 'onAppResume') {
|
||||||
stateListener.current = AppState.addEventListener(
|
stateListener.current = AppState.addEventListener(
|
||||||
'change',
|
'change',
|
||||||
nextAppState => {
|
nextAppState => {
|
||||||
@@ -182,7 +207,7 @@ export const PushyProvider = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (strategy === 'both' || strategy === 'onAppStart') {
|
if (checkStrategy === 'both' || checkStrategy === 'onAppStart') {
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
}
|
}
|
||||||
let dismissErrorTimer: ReturnType<typeof setTimeout>;
|
let dismissErrorTimer: ReturnType<typeof setTimeout>;
|
||||||
|
@@ -69,8 +69,8 @@ export interface PushyOptions {
|
|||||||
appKey: string;
|
appKey: string;
|
||||||
server?: PushyServerConfig;
|
server?: PushyServerConfig;
|
||||||
logger?: UpdateEventsLogger;
|
logger?: UpdateEventsLogger;
|
||||||
useAlert?: boolean;
|
updateStrategy?: 'alwaysAlert' | 'silentAndNow' | 'silentAndLater' | null;
|
||||||
strategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
|
checkStrategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
|
||||||
autoMarkSuccess?: boolean;
|
autoMarkSuccess?: boolean;
|
||||||
dismissErrorAfter?: number;
|
dismissErrorAfter?: number;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
|
12
src/utils.ts
12
src/utils.ts
@@ -18,13 +18,15 @@ export const emptyModule = new EmptyModule();
|
|||||||
|
|
||||||
const ping =
|
const ping =
|
||||||
Platform.OS === 'web'
|
Platform.OS === 'web'
|
||||||
? () => Promise.resolve(true)
|
? Promise.resolve
|
||||||
: async (url: string) =>
|
: async (url: string) =>
|
||||||
Promise.race([
|
Promise.race([
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
}).then(({ status }) => status === 200),
|
})
|
||||||
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
.then(({ status }) => (status === 200 ? url : null))
|
||||||
|
.catch(() => null),
|
||||||
|
new Promise(r => setTimeout(() => r(null), 2000)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const canUseGoogle = ping('https://www.google.com');
|
const canUseGoogle = ping('https://www.google.com');
|
||||||
@@ -33,7 +35,5 @@ export const testUrls = async (urls?: string[]) => {
|
|||||||
if (!urls?.length || (await canUseGoogle)) {
|
if (!urls?.length || (await canUseGoogle)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Promise.race(urls.map(url => ping(url).then(() => url))).catch(
|
return Promise.race(urls.map(ping)).catch(() => null);
|
||||||
() => null,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user