xref: /MusicFree/src/utils/checkUpdate.ts (revision b882a19d884fffa32f7c8cef31652b909dceaa0f)
1import axios from 'axios';
2import {compare} from 'compare-versions';
3import DeviceInfo from 'react-native-device-info';
4
5const updateList = [
6    'https://gitee.com/maotoumao/MusicFree/raw/master/release/version.json',
7    'https://raw.githubusercontent.com/maotoumao/MusicFree/master/release/version.json',
8];
9
10interface IUpdateInfo {
11    needUpdate: boolean;
12    data: {
13        version: string;
14        changeLog: string[];
15        download: string[];
16    };
17}
18
19export default async function checkUpdate(): Promise<IUpdateInfo | undefined> {
20    const currentVersion = DeviceInfo.getVersion();
21    for (let i = 0; i < updateList.length; ++i) {
22        try {
23            const rawInfo = (await axios.get(updateList[i])).data;
24            if (compare(rawInfo.version, currentVersion, '>')) {
25                return {
26                    needUpdate: true,
27                    data: rawInfo,
28                };
29            }
30        } catch {}
31    }
32}
33