From 346c0fe8b82a0bd555bcd55f7910146d1ce67e8e Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 19 Nov 2020 10:38:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=8D=87=E7=BA=A7=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89=E5=85=B3?= =?UTF-8?q?=E6=8E=89=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/gui/src/background.js | 23 +++++++++++++++-------- packages/gui/src/bridge/update-handle.js | 11 +++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index e192923..e5f22e2 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -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) diff --git a/packages/gui/src/bridge/update-handle.js b/packages/gui/src/bridge/update-handle.js index b84a6d1..1dc2d2f 100644 --- a/packages/gui/src/bridge/update-handle.js +++ b/packages/gui/src/bridge/update-handle.js @@ -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')