mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 18:00:40 +08:00
Compare commits
12 Commits
v10.0.0-be
...
v10.0.2
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4231d377e6 | ||
![]() |
9c06bac91b | ||
![]() |
4923aff184 | ||
![]() |
f6a38c1f48 | ||
![]() |
92cfbb3fdf | ||
![]() |
64ef8e129d | ||
![]() |
ce51b2ca81 | ||
![]() |
6c1662fce1 | ||
![]() |
d9e4575964 | ||
![]() |
190103687c | ||
![]() |
f6f055be64 | ||
![]() |
05e5c5a1a7 |
@@ -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.0.0-beta.1",
|
"react-native-update": "^10.0.0-beta.3",
|
||||||
"react-native-vector-icons": "^10.0.3"
|
"react-native-vector-icons": "^10.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@@ -33,7 +33,8 @@ function App() {
|
|||||||
const [showUpdateBanner, setShowUpdateBanner] = useState(false);
|
const [showUpdateBanner, setShowUpdateBanner] = useState(false);
|
||||||
const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false);
|
const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false);
|
||||||
const snackbarVisible =
|
const snackbarVisible =
|
||||||
showUpdateSnackbar && updateInfo?.update && !useDefaultAlert;
|
!useDefaultAlert && showUpdateSnackbar && updateInfo?.update;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
|
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
|
||||||
@@ -48,6 +49,7 @@ function App() {
|
|||||||
client?.setOptions({
|
client?.setOptions({
|
||||||
useAlert: v,
|
useAlert: v,
|
||||||
});
|
});
|
||||||
|
setShowUpdateSnackbar(!v);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
@@ -66,7 +68,11 @@ function App() {
|
|||||||
<Text>
|
<Text>
|
||||||
下载进度:{received} / {total}
|
下载进度:{received} / {total}
|
||||||
</Text>
|
</Text>
|
||||||
<TouchableOpacity onPress={checkUpdate}>
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
checkUpdate();
|
||||||
|
setShowUpdateSnackbar(true);
|
||||||
|
}}>
|
||||||
<Text style={styles.instructions}>点击这里检查更新</Text>
|
<Text style={styles.instructions}>点击这里检查更新</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
||||||
@@ -83,7 +89,7 @@ function App() {
|
|||||||
<TestConsole visible={showTestConsole} />
|
<TestConsole visible={showTestConsole} />
|
||||||
{snackbarVisible && (
|
{snackbarVisible && (
|
||||||
<Snackbar
|
<Snackbar
|
||||||
visible={true}
|
visible={snackbarVisible}
|
||||||
onDismiss={() => {
|
onDismiss={() => {
|
||||||
setShowUpdateSnackbar(false);
|
setShowUpdateSnackbar(false);
|
||||||
}}
|
}}
|
||||||
@@ -95,10 +101,13 @@ function App() {
|
|||||||
setShowUpdateBanner(true);
|
setShowUpdateBanner(true);
|
||||||
},
|
},
|
||||||
}}>
|
}}>
|
||||||
<Text>有新版本({updateInfo.version})可用,是否更新?</Text>
|
<Text style={{color: 'white'}}>
|
||||||
|
有新版本({updateInfo.name})可用,是否更新?
|
||||||
|
</Text>
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
)}
|
)}
|
||||||
<Banner
|
<Banner
|
||||||
|
style={{width: '100%', position: 'absolute', top: 0}}
|
||||||
visible={showUpdateBanner}
|
visible={showUpdateBanner}
|
||||||
actions={[
|
actions={[
|
||||||
{
|
{
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
|
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
"appId": 10977,
|
"appId": 27509,
|
||||||
"appKey": "bUYKfZgtC9VirZsQbAt8qken2Gq2uxe3"
|
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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.0.0-beta.1:
|
react-native-update@^10.0.0-beta.3:
|
||||||
version "10.0.0-beta.1"
|
version "10.0.0-beta.3"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.0-beta.1.tgz#bc49a7197dd19c16ba798ea13324b4b292edd052"
|
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.0-beta.3.tgz#cad099ebb40ff04b31ba2df13930517039e4fae3"
|
||||||
integrity sha512-PFTsut8SL+vqAPtBUzPg9KKU9mFgCktKttifzM8B4puSoburlSN2UnD+eDWxLkXyIWQtoQAqAmXPE1/zA/e7dw==
|
integrity sha512-Ak1ylgHbOUeaNsq3ItZGRenqqAwYKSTlB6T4sBn4PPNGaMmIMt6uIKKWrQqcNyc9WEy9LlFM6kSqQXBQdaVatw==
|
||||||
dependencies:
|
dependencies:
|
||||||
nanoid "^3.3.3"
|
nanoid "^3.3.3"
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "10.0.0-beta.2",
|
"version": "10.0.2",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@@ -31,6 +31,7 @@ export class Pushy {
|
|||||||
server: defaultServer,
|
server: defaultServer,
|
||||||
autoMarkSuccess: true,
|
autoMarkSuccess: true,
|
||||||
useAlert: true,
|
useAlert: true,
|
||||||
|
strategy: 'both',
|
||||||
};
|
};
|
||||||
|
|
||||||
lastChecking: number;
|
lastChecking: number;
|
||||||
@@ -261,6 +262,7 @@ export class Pushy {
|
|||||||
data: { newVersion: hash },
|
data: { newVersion: hash },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
log('downloaded hash:', hash);
|
||||||
setLocalHashInfo(hash, {
|
setLocalHashInfo(hash, {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
@@ -12,6 +12,7 @@ export const defaultContext = {
|
|||||||
markSuccess: noop,
|
markSuccess: noop,
|
||||||
dismissError: noop,
|
dismissError: noop,
|
||||||
downloadUpdate: noop,
|
downloadUpdate: noop,
|
||||||
|
downloadAndInstallApk: noop,
|
||||||
currentHash: '',
|
currentHash: '',
|
||||||
packageVersion: '',
|
packageVersion: '',
|
||||||
};
|
};
|
||||||
@@ -23,6 +24,7 @@ export const PushyContext = createContext<{
|
|||||||
markSuccess: () => void;
|
markSuccess: () => void;
|
||||||
dismissError: () => void;
|
dismissError: () => void;
|
||||||
downloadUpdate: () => void;
|
downloadUpdate: () => void;
|
||||||
|
downloadAndInstallApk: (url: string) => void;
|
||||||
currentHash: string;
|
currentHash: string;
|
||||||
packageVersion: string;
|
packageVersion: string;
|
||||||
client?: Pushy;
|
client?: Pushy;
|
||||||
|
@@ -14,7 +14,7 @@ import {
|
|||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { Pushy } from './client';
|
import { Pushy } from './client';
|
||||||
import { currentVersion, isFirstTime, packageVersion } from './core';
|
import { currentVersion, isFirstTime, packageVersion } from './core';
|
||||||
import { CheckResult } from './type';
|
import { CheckResult, ProgressData } from './type';
|
||||||
import { PushyContext } from './context';
|
import { PushyContext } from './context';
|
||||||
|
|
||||||
export const PushyProvider = ({
|
export const PushyProvider = ({
|
||||||
@@ -24,24 +24,23 @@ export const PushyProvider = ({
|
|||||||
client: Pushy;
|
client: Pushy;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
const { strategy, useAlert } = client.options;
|
const { options } = client;
|
||||||
const stateListener = useRef<NativeEventSubscription>();
|
const stateListener = useRef<NativeEventSubscription>();
|
||||||
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
|
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
|
||||||
|
const [progress, setProgress] = useState<ProgressData>();
|
||||||
const [lastError, setLastError] = useState<Error>();
|
const [lastError, setLastError] = useState<Error>();
|
||||||
|
|
||||||
const dismissError = useCallback(() => {
|
const dismissError = useCallback(() => {
|
||||||
if (lastError) {
|
|
||||||
setLastError(undefined);
|
setLastError(undefined);
|
||||||
}
|
}, []);
|
||||||
}, [lastError]);
|
|
||||||
|
|
||||||
const showAlert = useCallback(
|
const showAlert = useCallback(
|
||||||
(...args: Parameters<typeof Alert.alert>) => {
|
(...args: Parameters<typeof Alert.alert>) => {
|
||||||
if (useAlert) {
|
if (options.useAlert) {
|
||||||
Alert.alert(...args);
|
Alert.alert(...args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[useAlert],
|
[options],
|
||||||
);
|
);
|
||||||
|
|
||||||
const switchVersion = useCallback(() => {
|
const switchVersion = useCallback(() => {
|
||||||
@@ -61,7 +60,7 @@ export const PushyProvider = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const hash = await client.downloadUpdate(updateInfo);
|
const hash = await client.downloadUpdate(updateInfo, setProgress);
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -88,6 +87,15 @@ export const PushyProvider = ({
|
|||||||
}
|
}
|
||||||
}, [client, showAlert, updateInfo]);
|
}, [client, showAlert, updateInfo]);
|
||||||
|
|
||||||
|
const downloadAndInstallApk = useCallback(
|
||||||
|
(downloadUrl: string) => {
|
||||||
|
if (Platform.OS === 'android' && downloadUrl) {
|
||||||
|
client.downloadAndInstallApk(downloadUrl, setProgress);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[client],
|
||||||
|
);
|
||||||
|
|
||||||
const checkUpdate = useCallback(async () => {
|
const checkUpdate = useCallback(async () => {
|
||||||
let info: CheckResult;
|
let info: CheckResult;
|
||||||
try {
|
try {
|
||||||
@@ -106,7 +114,7 @@ export const PushyProvider = ({
|
|||||||
onPress: () => {
|
onPress: () => {
|
||||||
if (downloadUrl) {
|
if (downloadUrl) {
|
||||||
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
|
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
|
||||||
client.downloadAndInstallApk(downloadUrl);
|
downloadAndInstallApk(downloadUrl);
|
||||||
} else {
|
} else {
|
||||||
Linking.openURL(downloadUrl);
|
Linking.openURL(downloadUrl);
|
||||||
}
|
}
|
||||||
@@ -130,12 +138,13 @@ export const PushyProvider = ({
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [client, downloadUpdate, showAlert]);
|
}, [client, downloadAndInstallApk, downloadUpdate, showAlert]);
|
||||||
|
|
||||||
const markSuccess = client.markSuccess;
|
const markSuccess = client.markSuccess;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isFirstTime) {
|
const { strategy, dismissErrorAfter, autoMarkSuccess } = options;
|
||||||
|
if (isFirstTime && autoMarkSuccess) {
|
||||||
markSuccess();
|
markSuccess();
|
||||||
}
|
}
|
||||||
if (strategy === 'both' || strategy === 'onAppResume') {
|
if (strategy === 'both' || strategy === 'onAppResume') {
|
||||||
@@ -152,7 +161,6 @@ export const PushyProvider = ({
|
|||||||
checkUpdate();
|
checkUpdate();
|
||||||
}
|
}
|
||||||
let dismissErrorTimer: ReturnType<typeof setTimeout>;
|
let dismissErrorTimer: ReturnType<typeof setTimeout>;
|
||||||
const { dismissErrorAfter } = client.options;
|
|
||||||
if (typeof dismissErrorAfter === 'number' && dismissErrorAfter > 0) {
|
if (typeof dismissErrorAfter === 'number' && dismissErrorAfter > 0) {
|
||||||
dismissErrorTimer = setTimeout(() => {
|
dismissErrorTimer = setTimeout(() => {
|
||||||
dismissError();
|
dismissError();
|
||||||
@@ -162,7 +170,7 @@ export const PushyProvider = ({
|
|||||||
stateListener.current && stateListener.current.remove();
|
stateListener.current && stateListener.current.remove();
|
||||||
clearTimeout(dismissErrorTimer);
|
clearTimeout(dismissErrorTimer);
|
||||||
};
|
};
|
||||||
}, [checkUpdate, client.options, dismissError, markSuccess, strategy]);
|
}, [checkUpdate, options, dismissError, markSuccess]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PushyContext.Provider
|
<PushyContext.Provider
|
||||||
@@ -178,6 +186,8 @@ export const PushyProvider = ({
|
|||||||
downloadUpdate,
|
downloadUpdate,
|
||||||
packageVersion,
|
packageVersion,
|
||||||
currentHash: currentVersion,
|
currentHash: currentVersion,
|
||||||
|
progress,
|
||||||
|
downloadAndInstallApk,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
Reference in New Issue
Block a user