Skip to content

Commit

Permalink
fix a wrong dep
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Mar 8, 2024
1 parent e39d4fa commit 2df04cb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
70 changes: 39 additions & 31 deletions Example/testHotUpdate/src/TestConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ const UUID = '00000000-0000-0000-0000-000000000000';
const DownloadUrl =
'http://cos.pgyer.com/697913e94d7441f20c686e2b0996a1aa.apk?sign=7a8f11b1df82cba45c8ac30b1acec88c&t=1680404102&response-content-disposition=attachment%3Bfilename%3DtestHotupdate_1.0.apk';

const CustomDialog = ({title, visible, onConfirm}) => {
if (!visible) {
return null;
}

const CustomDialog = ({title, visible, onConfirm}) => {
if (!visible) {
return null;
}

return (
<View style={styles.overlay}>
<View style={styles.dialog}>
<Text style={styles.title}>{title}</Text>
<TouchableOpacity testID='done' style={styles.button} onLongPress={onConfirm}>
<Text style={styles.buttonText}>确认</Text>
</TouchableOpacity>
</View>
return (
<View style={styles.overlay}>
<View style={styles.dialog}>
<Text style={styles.title}>{title}</Text>
<TouchableOpacity
testID="done"
style={styles.button}
onLongPress={onConfirm}>
<Text style={styles.buttonText}>确认</Text>
</TouchableOpacity>
</View>
);
};
</View>
);
};
export default function TestConsole({visible}) {
const [text, setText] = useState('');
const [running, setRunning] = useState(false);
Expand Down Expand Up @@ -132,9 +134,8 @@ export default function TestConsole({visible}) {
testID={NativeTestMethod[i].name}
onLongPress={() => {
NativeTestMethod[i].invoke();
}}
>
<Text>{NativeTestMethod[i].name}</Text>
}}>
<Text>{NativeTestMethod[i].name}</Text>
</TouchableOpacity>,
);
}
Expand Down Expand Up @@ -164,8 +165,14 @@ export default function TestConsole({visible}) {
/>
{running && <ActivityIndicator />}
<TouchableOpacity
style={{backgroundColor:'rgb(0,140,237)', justifyContent: 'center',
alignItems: 'center',paddingTop:10,paddingBottom:10,marginBottom:5}}
style={{
backgroundColor: 'rgb(0,140,237)',
justifyContent: 'center',
alignItems: 'center',
paddingTop: 10,
paddingBottom: 10,
marginBottom: 5,
}}
testID="submit"
onLongPress={async () => {
setRunning(true);
Expand All @@ -190,22 +197,23 @@ export default function TestConsole({visible}) {
}
setAlertVisible(true);
setAlertMsg('done');
} catch (e: any) {
} catch (e) {
setAlertVisible(true);
setAlertMsg(e.message);
}
setRunning(false);
}}
>
<Text style={{color:'white'}}>执行</Text>
}}>
<Text style={{color: 'white'}}>执行</Text>
</TouchableOpacity>
<Button title="重置" onPress={() => setText('')} />
{renderTestView()}
<CustomDialog
title={alertMsg}
visible={alertVisible}
onConfirm={()=>{setAlertVisible(false)}}
/>
<Button title="重置" onPress={() => setText('')} />
{renderTestView()}
<CustomDialog
title={alertMsg}
visible={alertVisible}
onConfirm={() => {
setAlertVisible(false);
}}
/>
</SafeAreaView>
</Modal>
);
Expand Down
59 changes: 32 additions & 27 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const PushyProvider = ({
const { options } = client;
const stateListener = useRef<NativeEventSubscription>();
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
const updateInfoRef = useRef(updateInfo);
const [progress, setProgress] = useState<ProgressData>();
const [lastError, setLastError] = useState<Error>();
const lastChecking = useRef(0);
Expand Down Expand Up @@ -61,37 +62,40 @@ export const PushyProvider = ({
}
}, [client, updateInfo]);

const downloadUpdate = useCallback(async () => {
if (!updateInfo || !updateInfo.update) {
return;
}
try {
const hash = await client.downloadUpdate(updateInfo, setProgress);
if (!hash) {
const downloadUpdate = useCallback(
async (info: CheckResult | undefined = updateInfoRef.current) => {
if (!info || !info.update) {
return;
}
stateListener.current && stateListener.current.remove();
showAlert('提示', '下载完毕,是否立即更新?', [
{
text: '下次再说',
style: 'cancel',
onPress: () => {
client.switchVersionLater(hash);
try {
const hash = await client.downloadUpdate(info, setProgress);
if (!hash) {
return;
}
stateListener.current && stateListener.current.remove();
showAlert('提示', '下载完毕,是否立即更新?', [
{
text: '下次再说',
style: 'cancel',
onPress: () => {
client.switchVersionLater(hash);
},
},
},
{
text: '立即更新',
style: 'default',
onPress: () => {
client.switchVersion(hash);
{
text: '立即更新',
style: 'default',
onPress: () => {
client.switchVersion(hash);
},
},
},
]);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
}
}, [client, showAlert, updateInfo]);
]);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
}
},
[client, showAlert],
);

const downloadAndInstallApk = useCallback(
async (downloadUrl: string) => {
Expand All @@ -116,6 +120,7 @@ export const PushyProvider = ({
showAlert('更新检查失败', e.message);
return;
}
updateInfoRef.current = info;
setUpdateInfo(info);
if (info.expired) {
const { downloadUrl } = info;
Expand Down

0 comments on commit 2df04cb

Please sign in to comment.