Skip to content

Commit

Permalink
✨ Feature: add beta-version update support
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Apr 30, 2020
1 parent 2aeca50 commit ad6acd8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ docs/dist/
.env.local
.env.*.local
dist_electron/
test.js
20 changes: 10 additions & 10 deletions src/main/utils/updateChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { dialog, shell } from 'electron'
import db from '#/datastore'
import axios from 'axios'
import pkg from 'root/package.json'
import { lt } from 'semver'
const version = pkg.version
const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json'
Expand Down Expand Up @@ -51,18 +52,17 @@ const checkVersion = async () => {

// if true -> update else return false
const compareVersion2Update = (current: string, latest: string) => {
const currentVersion = current.split('.').map(item => parseInt(item))
const latestVersion = latest.split('.').map(item => parseInt(item))

for (let i = 0; i < 3; i++) {
if (currentVersion[i] < latestVersion[i]) {
return true
}
if (currentVersion[i] > latestVersion[i]) {
return false
try {
if (latest.includes('Beta')) {
const isCheckBetaUpdate = db.get('settings.checkBetaUpdate') !== false
if (!isCheckBetaUpdate) {
return false
}
}
return lt(current, latest)
} catch (e) {
return false
}
return false
}

export default checkVersion
17 changes: 16 additions & 1 deletion src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
@change="updateHelperChange"
></el-switch>
</el-form-item>
<el-form-item
v-show="form.updateHelper"
label="接受Beta版本更新"
>
<el-switch
v-model="form.checkBetaUpdate"
active-text=""
inactive-text=""
@change="checkBetaUpdateChange"
></el-switch>
</el-form-item>
<el-form-item
label="开机自启"
>
Expand Down Expand Up @@ -347,7 +358,8 @@ export default class extends Vue {
uploadNotification: db.get('settings.uploadNotification') || false,
miniWindowOntop: db.get('settings.miniWindowOntop') || false,
logLevel,
autoCopyUrl: db.get('settings.autoCopy') === undefined ? true : db.get('settings.autoCopy')
autoCopyUrl: db.get('settings.autoCopy') === undefined ? true : db.get('settings.autoCopy'),
checkBetaUpdate: db.get('settings.checkBetaUpdate') === undefined ? true : db.get('settings.checkBetaUpdate')
}
picBed: IPicBedType[] = []
logFileVisible = false
Expand Down Expand Up @@ -452,6 +464,9 @@ export default class extends Vue {
updateHelperChange (val: boolean) {
db.set('settings.showUpdateTip', val)
}
checkBetaUpdateChange (val: boolean) {
db.set('settings.checkBetaUpdate', val)
}
handleShowPicBedListChange (val: string[]) {
const list = this.picBed.map(item => {
if (!val.includes(item.name)) {
Expand Down
1 change: 1 addition & 0 deletions src/universal/types/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface ISettingForm {
miniWindowOntop: boolean
logLevel: string[]
autoCopyUrl: boolean
checkBetaUpdate: boolean
}

interface IShortKeyMap {
Expand Down

0 comments on commit ad6acd8

Please sign in to comment.