Feature: support auto update now

This commit is contained in:
萌萌哒赫萝
2023-04-05 22:55:35 +08:00
parent ca950dbd44
commit e39cac9f3b
14 changed files with 130 additions and 7 deletions

View File

@@ -4,7 +4,8 @@ import {
globalShortcut,
protocol,
Notification,
Menu
Menu,
dialog
} from 'electron'
import {
createProtocol
@@ -42,6 +43,7 @@ import { manageIpcList } from '../manage/events/ipcList'
import getManageApi from '../manage/Main'
import UpDownTaskQueue from '../manage/datastore/upDownTaskQueue'
import { T } from '~/main/i18n'
import { UpdateInfo, autoUpdater } from 'electron-updater'
const isDevelopment = process.env.NODE_ENV !== 'production'
const handleStartUpFiles = (argv: string[], cwd: string) => {
@@ -61,6 +63,46 @@ const handleStartUpFiles = (argv: string[], cwd: string) => {
}
}
autoUpdater.setFeedURL({
provider: 'generic',
url: 'https://release.piclist.cn/latest',
channel: 'latest'
})
autoUpdater.autoDownload = false
autoUpdater.on('update-available', (info: UpdateInfo) => {
dialog.showMessageBox({
type: 'info',
title: T('FIND_NEW_VERSION'),
buttons: ['Yes', 'No'],
message: T('TIPS_FIND_NEW_VERSION', {
v: info.version
})
}).then((result) => {
if (result.response === 0) {
autoUpdater.downloadUpdate()
}
})
})
autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox({
type: 'info',
title: T('UPDATE_DOWNLOADED'),
buttons: ['Yes', 'No'],
message: T('TIPS_UPDATE_DOWNLOADED')
}).then((result) => {
if (result.response === 0) {
autoUpdater.quitAndInstall()
}
})
})
autoUpdater.on('error', (err) => {
dialog.showErrorBox('error', err.message)
})
class LifeCycle {
private async beforeReady () {
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
@@ -111,6 +153,7 @@ class LifeCycle {
createTray()
db.set('needReload', false)
updateChecker()
autoUpdater.checkForUpdatesAndNotify()
// 不需要阻塞
process.nextTick(() => {
shortKeyHandler.init()

View File

@@ -151,6 +151,7 @@
</el-button>
</el-form-item>
<el-form-item
v-if="false"
:label="$T('SETTINGS_OPEN_UPDATE_HELPER')"
>
<el-switch

View File

@@ -730,6 +730,8 @@ interface ILocales {
TIPS_SHORTCUT_MODIFIED_CONFLICT: string
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: string
TIPS_FIND_NEW_VERSION: string
UPDATE_DOWNLOADED: string
TIPS_UPDATE_DOWNLOADED: string
PRIVACY: string
PRIVACY_TIPS: string
QUIT: string