优化版本更新操作

This commit is contained in:
lyswhut
2023-01-31 17:48:38 +08:00
parent c24b29a42c
commit 6b69cdf12f
22 changed files with 553 additions and 185 deletions
+25 -18
View File
@@ -5,9 +5,11 @@ import { isExistWindow, sendEvent } from './index'
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
autoUpdater.logger = log
autoUpdater.autoDownload = false
// autoUpdater.forceDevUpdateConfig = true
// autoUpdater.autoDownload = false
let isFirstCheckedUpdate = true
// let isFirstCheckedUpdate = true
log.info('App starting...')
@@ -65,14 +67,12 @@ interface WaitEvent {
info: any
}
let waitEvent: WaitEvent[] = []
// let waitEvent: WaitEvent[] = []
const handleSendEvent = (action: WaitEvent) => {
if (isExistWindow()) {
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
sendEvent(action.type, action.info)
}, 2000)
} else {
waitEvent.push(action)
}, 1000)
}
}
@@ -105,9 +105,15 @@ export default () => {
})
mainOn(WIN_MAIN_RENDERER_EVENT_NAME.update_check, () => {
console.log('check')
checkUpdate()
})
mainOn(WIN_MAIN_RENDERER_EVENT_NAME.update_download_update, () => {
if (!autoUpdater.isUpdaterActive()) return
void autoUpdater.downloadUpdate()
})
mainOn(WIN_MAIN_RENDERER_EVENT_NAME.quit_update, () => {
global.lx.isSkipTrayQuit = true
@@ -117,24 +123,25 @@ export default () => {
})
}
export const checkUpdate = () => {
if (!isFirstCheckedUpdate) {
if (waitEvent.length) {
waitEvent.forEach((event, index) => {
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
sendEvent(event.type, event.info)
}, 2000 * (index + 1))
})
waitEvent = []
}
return
}
isFirstCheckedUpdate = false
const checkUpdate = () => {
// if (!isFirstCheckedUpdate) {
// if (waitEvent.length) {
// waitEvent.forEach((event, index) => {
// setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成
// sendEvent(event.type, event.info)
// }, 2000 * (index + 1))
// })
// waitEvent = []
// }
// return
// }
// isFirstCheckedUpdate = false
// 由于集合安装包中不包含win arm版,这将会导致arm版更新失败
if (isWin && process.arch.includes('arm')) {
handleSendEvent({ type: WIN_MAIN_RENDERER_EVENT_NAME.update_error, info: 'failed' })
} else {
autoUpdater.autoDownload = global.lx.appSetting['common.tryAutoUpdate']
void autoUpdater.checkForUpdates()
}
}