diff --git a/src/main/utils/updateChecker.ts b/src/main/utils/updateChecker.ts index eb848cd..631239c 100644 --- a/src/main/utils/updateChecker.ts +++ b/src/main/utils/updateChecker.ts @@ -3,7 +3,8 @@ import db from '#/datastore' import axios from 'axios' import pkg from 'root/package.json' const version = pkg.version -let release = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo/package.json' +const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest' +const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json' const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest' const checkVersion = async () => { @@ -15,12 +16,15 @@ const checkVersion = async () => { if (showTip) { let res: any try { - res = await axios.get(release) + res = await axios.get(releaseUrl).catch(async () => { + const result = await axios.get(releaseUrlBackup) + return result + }) } catch (err) { console.log(err) } if (res.status === 200) { - const latest = res.data.version + const latest = res.data.version || res.data.name const result = compareVersion2Update(version, latest) if (result) { dialog.showMessageBox({ diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index ae6ced0..bc04235 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -305,7 +305,8 @@ import { } from 'electron' import { Component, Vue } from 'vue-property-decorator' import db from '#/datastore' -const release = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest' +const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest' +const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json' const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest' const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) => void) => { if (!/\$url/.test(value)) { @@ -484,11 +485,16 @@ export default class extends Vue { } checkUpdate () { this.checkUpdateVisible = true - this.$http.get(release) + this.$http.get(releaseUrl) .then(res => { this.latestVersion = res.data.name - }).catch(err => { - console.log(err) + }).catch(async () => { + this.$http.get(releaseUrlBackup) + .then(res => { + this.latestVersion = res.data.version + }).catch(() => { + this.latestVersion = '网络错误暂时无法获取' + }) }) } confirmCheckVersion () {