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')