From a432080141a7cf6831c7fba7ee35da017def9d5d Mon Sep 17 00:00:00 2001 From: lyswhut Date: Tue, 10 Sep 2019 09:03:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20MAC=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=B8=8B=E8=BD=AF=E4=BB=B6=E5=85=B3=E9=97=AD=E6=97=B6=E5=86=8D?= =?UTF-8?q?=E6=AC=A1=E4=BB=8E=20dock=20=E6=89=93=E5=BC=80=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 3 +++ src/main/index.js | 11 +++++++---- src/main/utils/autoUpdate.js | 34 +++++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index e69de29b..f73ff859 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -0,0 +1,3 @@ +### 修复 + +- 修复 MAC 系统下软件关闭时再次从 dock 打开时报错的Bug diff --git a/src/main/index.js b/src/main/index.js index 86745584..7c664076 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -30,7 +30,7 @@ const isDev = process.env.NODE_ENV !== 'production' let mainWindow let winURL -let isCheckedUpdate = false +let isFirstCheckedUpdate = true if (isDev) { global.__static = path.join(__dirname, '../static') @@ -63,15 +63,18 @@ function createWindow() { mainWindow.loadURL(winURL) + mainWindow.on('close', () => { + mainWindow.setProgressBar(-1) + }) mainWindow.on('closed', () => { mainWindow = global.mainWindow = null }) // mainWindow.webContents.openDevTools() - if (!isDev && !isCheckedUpdate) { - autoUpdate() - isCheckedUpdate = true + if (!isDev) { + autoUpdate(isFirstCheckedUpdate) + isFirstCheckedUpdate = false } } diff --git a/src/main/utils/autoUpdate.js b/src/main/utils/autoUpdate.js index afdf805b..e295d946 100644 --- a/src/main/utils/autoUpdate.js +++ b/src/main/utils/autoUpdate.js @@ -56,35 +56,47 @@ function sendStatusToWindow(text) { // }) +let waitEvent = [] +const handleSendEvent = action => { + if (global.mainWindow) { + setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成 + global.mainWindow.webContents.send(action.type, action.info) + }, 2000) + } else { + waitEvent.push(action) + } +} -module.exports = () => { +module.exports = isFirstCheckedUpdate => { + if (!isFirstCheckedUpdate) { + waitEvent.forEach((event, index) => { + setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还没启动完成 + global.mainWindow.webContents.send(event.type, event.info) + }, 2000 * (index + 1)) + }) + return + } autoUpdater.on('checking-for-update', () => { sendStatusToWindow('Checking for update...') }) autoUpdater.on('update-available', info => { sendStatusToWindow('Update available.') - global.mainWindow.webContents.send('update-available', info) + handleSendEvent({ type: 'update-available', info }) }) autoUpdater.on('update-not-available', info => { sendStatusToWindow('Update not available.') - setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成 - global.mainWindow.webContents.send('update-not-available') - }, 5000) + handleSendEvent({ type: 'update-not-available' }) }) autoUpdater.on('error', () => { sendStatusToWindow('Error in auto-updater.') - setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成 - global.mainWindow.webContents.send('update-error') - }, 6000) + handleSendEvent({ type: 'update-error' }) }) autoUpdater.on('download-progress', progressObj => { sendStatusToWindow('Download progress...') }) autoUpdater.on('update-downloaded', info => { sendStatusToWindow('Update downloaded.') - setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成 - global.mainWindow.webContents.send('update-downloaded') - }, 2000) + handleSendEvent({ type: 'update-downloaded' }) }) mainOn('quit-update', () => { setTimeout(() => {