PicList/src/main/utils/updateChecker.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-12-23 03:38:19 -05:00
import { dialog, shell } from 'electron'
import db from '~/main/apis/core/datastore'
2019-12-19 06:17:21 -05:00
import pkg from 'root/package.json'
import { lt } from 'semver'
2022-08-20 04:44:55 -04:00
import { T } from '~/main/i18n'
import { getLatestVersion } from '#/utils/getLatestVersion'
2017-12-23 03:38:19 -05:00
const version = pkg.version
// 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'
2017-12-23 03:38:19 -05:00
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) {
const res: string = await getLatestVersion()
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) => {
try {
return lt(current, latest)
} catch (e) {
return false
2017-12-23 03:38:19 -05:00
}
}
export default checkVersion