mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 19:18:13 -05:00
⚡ Perf: remove duplicate check of new version, refactor getLatestVersion func
This commit is contained in:
parent
15d34ac90a
commit
ef917ce26e
@ -1,9 +1,5 @@
|
||||
import db from '~/main/apis/core/datastore'
|
||||
import { getLatestVersion } from '#/utils/getLatestVersion'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
// const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases'
|
||||
// const releaseUrlBackup = 'https://picgo-1251750343.cos.ap-chengdu.myqcloud.com'
|
||||
// const downloadUrl = 'https://github.com/Kuingsmile/PicList/releases/latest'
|
||||
|
||||
const checkVersion = async () => {
|
||||
let showTip = db.get('settings.showUpdateTip')
|
||||
@ -12,10 +8,9 @@ const checkVersion = async () => {
|
||||
showTip = true
|
||||
}
|
||||
if (showTip) {
|
||||
const res: string = await getLatestVersion()
|
||||
if (res !== '') {
|
||||
autoUpdater.checkForUpdatesAndNotify()
|
||||
} else {
|
||||
try {
|
||||
await autoUpdater.checkForUpdatesAndNotify()
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
|
@ -1,21 +1,23 @@
|
||||
import axios from 'axios'
|
||||
import { RELEASE_URL, RELEASE_URL_BACKUP } from './static'
|
||||
import yaml from 'js-yaml'
|
||||
import { RELEASE_URL, RELEASE_URL_BACKUP } from './static'
|
||||
|
||||
export const getLatestVersion = async () => {
|
||||
let res: string = ''
|
||||
export const getLatestVersion = async (): Promise<string> => {
|
||||
try {
|
||||
res = await axios.get(RELEASE_URL).then(r => {
|
||||
const list = r.data as IStringKeyMap[]
|
||||
const normalList = list.filter(item => !item.name.includes('beta'))
|
||||
return normalList[0].name
|
||||
}).catch(async () => {
|
||||
const result = await axios.get(`${RELEASE_URL_BACKUP}/latest.yml`)
|
||||
const r = yaml.load(result.data) as IStringKeyMap
|
||||
return r.version
|
||||
})
|
||||
const { data } = await axios.get(RELEASE_URL)
|
||||
const releases = data as IStringKeyMap[]
|
||||
const normalList = releases.filter(item => !item.name.includes('beta'))
|
||||
const latestRelease = normalList[0]
|
||||
return latestRelease.name
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
try {
|
||||
const { data } = await axios.get(`${RELEASE_URL_BACKUP}/latest.yml`)
|
||||
const r = yaml.load(data) as IStringKeyMap
|
||||
return r.version
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user