Skip to content

Commit

Permalink
🐛 Fix: releaseUrl may can't get latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Jan 9, 2020
1 parent 3caeccc commit ee46ab1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/main/utils/updateChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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({
Expand Down
14 changes: 10 additions & 4 deletions src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit ee46ab1

Please sign in to comment.