refactor: 升级优化,修复没有关掉的问题
parent
930049dd6d
commit
346c0fe8b8
|
@ -112,7 +112,14 @@ function createWindow () {
|
|||
})
|
||||
}
|
||||
|
||||
function quit (app) {
|
||||
async function beforeQuit () {
|
||||
return bridge.devSidecar.api.shutdown()
|
||||
}
|
||||
async function quit (app, callback) {
|
||||
if (tray) {
|
||||
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
|
||||
}
|
||||
await beforeQuit()
|
||||
app.quit()
|
||||
}
|
||||
|
||||
|
@ -129,12 +136,12 @@ if (!isFirstInstance) {
|
|||
} else {
|
||||
app.on('before-quit', async (event) => {
|
||||
log.info('before-quit')
|
||||
event.preventDefault()
|
||||
// if (tray) {
|
||||
// tray.displayBalloon({ title: '正在关闭,请稍候...', content: '正在关闭中,请稍候。。。' })
|
||||
// }
|
||||
await bridge.devSidecar.api.shutdown()
|
||||
app.exit()
|
||||
// event.preventDefault()
|
||||
// // if (tray) {
|
||||
// // tray.displayBalloon({ title: '正在关闭,请稍候...', content: '正在关闭中,请稍候。。。' })
|
||||
// // }
|
||||
// await bridge.devSidecar.api.shutdown()
|
||||
// app.exit()
|
||||
})
|
||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||
log.info('new app started', commandLine)
|
||||
|
@ -187,7 +194,7 @@ if (!isFirstInstance) {
|
|||
updateUrl = 'http://localhost/dev-sidecar/'
|
||||
}
|
||||
// 自动更新
|
||||
updateHandle(win, updateUrl)
|
||||
updateHandle(app, win, beforeQuit, updateUrl)
|
||||
|
||||
// 百度分析
|
||||
ebtMain(ipcMain, isDevelopment)
|
||||
|
|
|
@ -8,7 +8,7 @@ import path from 'path'
|
|||
// eslint-disable-next-line no-unused-vars
|
||||
const isMac = process.platform === 'darwin'
|
||||
// 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写
|
||||
function updateHandle (win, updateUrl) {
|
||||
function updateHandle (app, win, beforeQuit, updateUrl) {
|
||||
// // 更新前,删除本地安装包 ↓
|
||||
// const updaterCacheDirName = 'dev-sidecar-updater'
|
||||
// const updatePendingPath = path.join(autoUpdater.app.baseCachePath, updaterCacheDirName, 'pending')
|
||||
|
@ -68,7 +68,14 @@ function updateHandle (win, updateUrl) {
|
|||
ipcMain.on('update', (e, arg) => {
|
||||
if (arg.key === 'doUpdateNow') {
|
||||
// some code here to handle event
|
||||
autoUpdater.quitAndInstall()
|
||||
beforeQuit().then(() => {
|
||||
autoUpdater.quitAndInstall()
|
||||
if (app) {
|
||||
setTimeout(() => {
|
||||
app.exit()
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
} else if (arg.key === 'checkForUpdate') {
|
||||
// 执行自动更新检查
|
||||
log.info('autoUpdater checkForUpdates')
|
||||
|
|
Loading…
Reference in New Issue