mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-07-12 16:11:27 +08:00
🔨 Refactor: optimize auto update
This commit is contained in:
@@ -15,7 +15,6 @@ import { IWindowList } from '#/types/enum'
|
||||
import pasteTemplate from '~/main/utils/pasteTemplate'
|
||||
import pkg from 'root/package.json'
|
||||
import { ensureFilePath, handleCopyUrl } from '~/main/utils/common'
|
||||
import { privacyManager } from '~/main/utils/privacyManager'
|
||||
// import { T } from '#/i18n'
|
||||
import { T } from '~/main/i18n'
|
||||
import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion'
|
||||
@@ -50,12 +49,6 @@ export function createMenu () {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: T('PRIVACY_AGREEMENT'),
|
||||
click () {
|
||||
privacyManager.show(false)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: T('RELOAD_APP'),
|
||||
click () {
|
||||
@@ -115,12 +108,6 @@ export function createContextMenu () {
|
||||
// @ts-ignore
|
||||
submenu
|
||||
},
|
||||
{
|
||||
label: T('PRIVACY_AGREEMENT'),
|
||||
click () {
|
||||
privacyManager.show(false)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: T('RELOAD_APP'),
|
||||
click () {
|
||||
|
||||
@@ -43,6 +43,7 @@ import getManageApi from '../manage/Main'
|
||||
import UpDownTaskQueue from '../manage/datastore/upDownTaskQueue'
|
||||
import { T } from '~/main/i18n'
|
||||
import { UpdateInfo, autoUpdater } from 'electron-updater'
|
||||
import updateChecker from '../utils/updateChecker'
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
|
||||
const handleStartUpFiles = (argv: string[], cwd: string) => {
|
||||
@@ -77,11 +78,14 @@ autoUpdater.on('update-available', (info: UpdateInfo) => {
|
||||
buttons: ['Yes', 'No'],
|
||||
message: T('TIPS_FIND_NEW_VERSION', {
|
||||
v: info.version
|
||||
})
|
||||
}),
|
||||
checkboxLabel: T('NO_MORE_NOTICE'),
|
||||
checkboxChecked: false
|
||||
}).then((result) => {
|
||||
if (result.response === 0) {
|
||||
autoUpdater.downloadUpdate()
|
||||
}
|
||||
db.set('settings.showUpdateTip', !result.checkboxChecked)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -151,8 +155,7 @@ class LifeCycle {
|
||||
}
|
||||
createTray()
|
||||
db.set('needReload', false)
|
||||
// updateChecker()
|
||||
autoUpdater.checkForUpdatesAndNotify()
|
||||
updateChecker()
|
||||
// 不需要阻塞
|
||||
process.nextTick(() => {
|
||||
shortKeyHandler.init()
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { dialog, shell } from 'electron'
|
||||
import db from '~/main/apis/core/datastore'
|
||||
import pkg from 'root/package.json'
|
||||
import { lt } from 'semver'
|
||||
import { T } from '~/main/i18n'
|
||||
import { getLatestVersion } from '#/utils/getLatestVersion'
|
||||
const version = pkg.version
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
// 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'
|
||||
// const downloadUrl = 'https://github.com/Kuingsmile/PicList/releases/latest'
|
||||
|
||||
const checkVersion = async () => {
|
||||
let showTip = db.get('settings.showUpdateTip')
|
||||
@@ -18,25 +14,7 @@ const checkVersion = async () => {
|
||||
if (showTip) {
|
||||
const res: string = await getLatestVersion()
|
||||
if (res !== '') {
|
||||
const latest = res
|
||||
const result = compareVersion2Update(version, latest)
|
||||
if (result) {
|
||||
dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: T('FIND_NEW_VERSION'),
|
||||
buttons: ['Yes', 'No'],
|
||||
message: T('TIPS_FIND_NEW_VERSION', {
|
||||
v: latest
|
||||
}),
|
||||
checkboxLabel: T('NO_MORE_NOTICE'),
|
||||
checkboxChecked: false
|
||||
}).then(res => {
|
||||
if (res.response === 0) { // if selected yes
|
||||
shell.openExternal(downloadUrl)
|
||||
}
|
||||
db.set('settings.showUpdateTip', !res.checkboxChecked)
|
||||
})
|
||||
}
|
||||
autoUpdater.checkForUpdatesAndNotify()
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
@@ -45,13 +23,4 @@ const checkVersion = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// if true -> update else return false
|
||||
const compareVersion2Update = (current: string, latest: string) => {
|
||||
try {
|
||||
return lt(current, latest)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default checkVersion
|
||||
|
||||
Reference in New Issue
Block a user