refactor: 升级优化,修复没有关掉的问题

pull/180/head
xiaojunnuo 4 years ago
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() app.quit()
} }
@ -129,12 +136,12 @@ if (!isFirstInstance) {
} else { } else {
app.on('before-quit', async (event) => { app.on('before-quit', async (event) => {
log.info('before-quit') log.info('before-quit')
event.preventDefault() // event.preventDefault()
// if (tray) { // // if (tray) {
// tray.displayBalloon({ title: '正在关闭,请稍候...', content: '正在关闭中,请稍候。。。' }) // // tray.displayBalloon({ title: '正在关闭,请稍候...', content: '正在关闭中,请稍候。。。' })
// } // // }
await bridge.devSidecar.api.shutdown() // await bridge.devSidecar.api.shutdown()
app.exit() // app.exit()
}) })
app.on('second-instance', (event, commandLine, workingDirectory) => { app.on('second-instance', (event, commandLine, workingDirectory) => {
log.info('new app started', commandLine) log.info('new app started', commandLine)
@ -187,7 +194,7 @@ if (!isFirstInstance) {
updateUrl = 'http://localhost/dev-sidecar/' updateUrl = 'http://localhost/dev-sidecar/'
} }
// 自动更新 // 自动更新
updateHandle(win, updateUrl) updateHandle(app, win, beforeQuit, updateUrl)
// 百度分析 // 百度分析
ebtMain(ipcMain, isDevelopment) ebtMain(ipcMain, isDevelopment)

@ -8,7 +8,7 @@ import path from 'path'
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const isMac = process.platform === 'darwin' const isMac = process.platform === 'darwin'
// 检测更新在你想要检查更新的时候执行renderer事件触发后的操作自行编写 // 检测更新在你想要检查更新的时候执行renderer事件触发后的操作自行编写
function updateHandle (win, updateUrl) { function updateHandle (app, win, beforeQuit, updateUrl) {
// // 更新前,删除本地安装包 ↓ // // 更新前,删除本地安装包 ↓
// const updaterCacheDirName = 'dev-sidecar-updater' // const updaterCacheDirName = 'dev-sidecar-updater'
// const updatePendingPath = path.join(autoUpdater.app.baseCachePath, updaterCacheDirName, 'pending') // const updatePendingPath = path.join(autoUpdater.app.baseCachePath, updaterCacheDirName, 'pending')
@ -68,7 +68,14 @@ function updateHandle (win, updateUrl) {
ipcMain.on('update', (e, arg) => { ipcMain.on('update', (e, arg) => {
if (arg.key === 'doUpdateNow') { if (arg.key === 'doUpdateNow') {
// some code here to handle event // some code here to handle event
beforeQuit().then(() => {
autoUpdater.quitAndInstall() autoUpdater.quitAndInstall()
if (app) {
setTimeout(() => {
app.exit()
}, 1000)
}
})
} else if (arg.key === 'checkForUpdate') { } else if (arg.key === 'checkForUpdate') {
// 执行自动更新检查 // 执行自动更新检查
log.info('autoUpdater checkForUpdates') log.info('autoUpdater checkForUpdates')

Loading…
Cancel
Save