xref: /MusicFree/src/entry/useBootstrap.tsx (revision cf2d630eca034addcb92030a5268105bce30ef82)
1*cf2d630eS猫头猫import useDialog from '@/components/dialogs/useDialog';
2*cf2d630eS猫头猫import checkUpdate from '@/utils/checkUpdate';
3*cf2d630eS猫头猫import Toast from '@/utils/toast';
4*cf2d630eS猫头猫import {useEffect} from 'react';
5*cf2d630eS猫头猫import RNFS from 'react-native-fs';
6*cf2d630eS猫头猫
7*cf2d630eS猫头猫export default function () {
8*cf2d630eS猫头猫    const {showDialog} = useDialog();
9*cf2d630eS猫头猫    useEffect(() => {
10*cf2d630eS猫头猫        checkUpdate().then(updateInfo => {
11*cf2d630eS猫头猫            if (updateInfo?.needUpdate) {
12*cf2d630eS猫头猫                const {data} = updateInfo;
13*cf2d630eS猫头猫                showDialog('DownloadDialog', {
14*cf2d630eS猫头猫                    title: '发现新版本',
15*cf2d630eS猫头猫                    content: data.changeLog,
16*cf2d630eS猫头猫                    fromUrl: data.download[0],
17*cf2d630eS猫头猫                    toFile: `${
18*cf2d630eS猫头猫                        RNFS.DownloadDirectoryPath
19*cf2d630eS猫头猫                    }/musicfree_${data.version.replace(/\./g, '_')}.apk`,
20*cf2d630eS猫头猫                    afterDownload() {
21*cf2d630eS猫头猫                        Toast.success('下载成功');
22*cf2d630eS猫头猫                        //todo: 默认安装
23*cf2d630eS猫头猫                    },
24*cf2d630eS猫头猫                });
25*cf2d630eS猫头猫            }
26*cf2d630eS猫头猫        });
27*cf2d630eS猫头猫    }, []);
28*cf2d630eS猫头猫}
29