2017-12-23 03:38:19 -05:00
|
|
|
import { dialog, shell } from 'electron'
|
2021-07-25 11:25:36 -04:00
|
|
|
import db from '~/main/apis/core/datastore'
|
2019-12-19 06:17:21 -05:00
|
|
|
import pkg from 'root/package.json'
|
2020-04-30 04:47:09 -04:00
|
|
|
import { lt } from 'semver'
|
2022-01-11 08:50:29 -05:00
|
|
|
import { T } from '~/universal/i18n'
|
2022-08-14 08:45:16 -04:00
|
|
|
import { getLatestVersion } from '#/utils/getLatestVersion'
|
2017-12-23 03:38:19 -05:00
|
|
|
const version = pkg.version
|
2022-08-14 08:45:16 -04:00
|
|
|
// const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases'
|
|
|
|
// const releaseUrlBackup = 'https://picgo-1251750343.cos.ap-chengdu.myqcloud.com'
|
2017-12-23 03:38:19 -05:00
|
|
|
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
|
|
|
|
|
|
|
|
const checkVersion = async () => {
|
2019-09-11 07:30:08 -04:00
|
|
|
let showTip = db.get('settings.showUpdateTip')
|
2017-12-23 03:38:19 -05:00
|
|
|
if (showTip === undefined) {
|
2019-09-11 07:30:08 -04:00
|
|
|
db.set('settings.showUpdateTip', true)
|
2017-12-23 03:38:19 -05:00
|
|
|
showTip = true
|
|
|
|
}
|
|
|
|
if (showTip) {
|
2022-08-14 08:45:16 -04:00
|
|
|
const isCheckBetaUpdate = db.get('settings.checkBetaUpdate') !== false
|
|
|
|
const res: string = await getLatestVersion(isCheckBetaUpdate)
|
|
|
|
if (res !== '') {
|
|
|
|
const latest = res
|
2017-12-23 03:38:19 -05:00
|
|
|
const result = compareVersion2Update(version, latest)
|
|
|
|
if (result) {
|
|
|
|
dialog.showMessageBox({
|
|
|
|
type: 'info',
|
2022-01-11 08:50:29 -05:00
|
|
|
title: T('FIND_NEW_VERSION'),
|
2017-12-23 03:38:19 -05:00
|
|
|
buttons: ['Yes', 'No'],
|
2022-01-11 08:50:29 -05:00
|
|
|
message: T('TIPS_FIND_NEW_VERSION', {
|
|
|
|
v: latest
|
|
|
|
}),
|
|
|
|
checkboxLabel: T('NO_MORE_NOTICE'),
|
2017-12-23 03:38:19 -05:00
|
|
|
checkboxChecked: false
|
2019-12-19 06:17:21 -05:00
|
|
|
}).then(res => {
|
|
|
|
if (res.response === 0) { // if selected yes
|
2017-12-23 03:38:19 -05:00
|
|
|
shell.openExternal(downloadUrl)
|
|
|
|
}
|
2019-12-19 06:17:21 -05:00
|
|
|
db.set('settings.showUpdateTip', !res.checkboxChecked)
|
2017-12-23 03:38:19 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if true -> update else return false
|
2019-12-19 06:17:21 -05:00
|
|
|
const compareVersion2Update = (current: string, latest: string) => {
|
2020-04-30 04:47:09 -04:00
|
|
|
try {
|
2020-04-30 06:54:48 -04:00
|
|
|
if (latest.includes('beta')) {
|
2020-04-30 04:47:09 -04:00
|
|
|
const isCheckBetaUpdate = db.get('settings.checkBetaUpdate') !== false
|
|
|
|
if (!isCheckBetaUpdate) {
|
|
|
|
return false
|
|
|
|
}
|
2017-12-23 03:38:19 -05:00
|
|
|
}
|
2020-04-30 04:47:09 -04:00
|
|
|
return lt(current, latest)
|
|
|
|
} catch (e) {
|
|
|
|
return false
|
2017-12-23 03:38:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default checkVersion
|