From 73072daa463d6248b79cc2fa0403f07b212ae98f Mon Sep 17 00:00:00 2001 From: lyswhut Date: Tue, 10 Sep 2019 02:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8DMac?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=82=B9=E5=87=BB=E5=85=B3=E9=97=AD=E6=97=B6?= =?UTF-8?q?=E5=86=8D=E6=89=93=E5=BC=80=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/events/progressBar.js | 15 ++++++------- src/main/events/trafficLight.js | 39 ++++++++++++++++----------------- src/main/index.js | 16 ++++++++------ src/main/utils/autoUpdate.js | 12 +++++----- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/events/progressBar.js b/src/main/events/progressBar.js index 115e5919..ed3098c6 100644 --- a/src/main/events/progressBar.js +++ b/src/main/events/progressBar.js @@ -1,11 +1,10 @@ const { mainOn } = require('../../common/icp') -module.exports = win => { - mainOn('progress', (event, params) => { - // console.log(params) - win.setProgressBar(params.status, { - mode: params.mode || 'normal', - }) - }) -} + +mainOn('progress', (event, params) => { + // console.log(params) + global.mainWindow && global.mainWindow.setProgressBar(params.status, { + mode: params.mode || 'normal', + }) +}) diff --git a/src/main/events/trafficLight.js b/src/main/events/trafficLight.js index e2ba49f9..94b96919 100644 --- a/src/main/events/trafficLight.js +++ b/src/main/events/trafficLight.js @@ -1,23 +1,22 @@ // const { app } = require('electron') const { mainOn } = require('../../common/icp') -module.exports = win => { - mainOn('min', event => { - if (win) { - win.minimize() - } - }) - // mainOn('max', event => { - // if (win) { - // win.maximize() - // } - // }) - mainOn('close', event => { - if (win) { - // window.destroy() - // console.log('close') - // app.quit() - win.close() - } - }) -} + +mainOn('min', event => { + if (global.mainWindow) { + global.mainWindow.minimize() + } +}) +// mainOn('max', event => { +// if (global.mainWindow) { +// global.mainWindow.maximize() +// } +// }) +mainOn('close', event => { + if (global.mainWindow) { + // global.mainWindowdow.destroy() + // console.log('close') + // app.quit() + global.mainWindow.close() + } +}) diff --git a/src/main/index.js b/src/main/index.js index c2550c70..86745584 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -16,8 +16,8 @@ app.on('second-instance', (event, argv, cwd) => { }) require('./events') -const progressBar = require('./events/progressBar') -const trafficLight = require('./events/trafficLight') +require('./events/progressBar') +require('./events/trafficLight') const autoUpdate = require('./utils/autoUpdate') const { isLinux, isMac } = require('../common/utils') @@ -30,6 +30,7 @@ const isDev = process.env.NODE_ENV !== 'production' let mainWindow let winURL +let isCheckedUpdate = false if (isDev) { global.__static = path.join(__dirname, '../static') @@ -43,7 +44,7 @@ function createWindow() { /** * Initial window options */ - mainWindow = new BrowserWindow({ + mainWindow = global.mainWindow = new BrowserWindow({ height: 590, useContentSize: true, width: 920, @@ -63,14 +64,15 @@ function createWindow() { mainWindow.loadURL(winURL) mainWindow.on('closed', () => { - if (!isMac) mainWindow = null + mainWindow = global.mainWindow = null }) // mainWindow.webContents.openDevTools() - trafficLight(mainWindow) - progressBar(mainWindow) - if (!isDev) autoUpdate(mainWindow) + if (!isDev && !isCheckedUpdate) { + autoUpdate() + isCheckedUpdate = true + } } if (isMac) { diff --git a/src/main/utils/autoUpdate.js b/src/main/utils/autoUpdate.js index 0a9e64bf..afdf805b 100644 --- a/src/main/utils/autoUpdate.js +++ b/src/main/utils/autoUpdate.js @@ -21,7 +21,7 @@ log.info('App starting...') function sendStatusToWindow(text) { log.info(text) - // win.webContents.send('message', text) + // global.mainWindow.webContents.send('message', text) } @@ -57,24 +57,24 @@ function sendStatusToWindow(text) { // }) -module.exports = win => { +module.exports = () => { autoUpdater.on('checking-for-update', () => { sendStatusToWindow('Checking for update...') }) autoUpdater.on('update-available', info => { sendStatusToWindow('Update available.') - win.webContents.send('update-available', info) + global.mainWindow.webContents.send('update-available', info) }) autoUpdater.on('update-not-available', info => { sendStatusToWindow('Update not available.') setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成 - win.webContents.send('update-not-available') + global.mainWindow.webContents.send('update-not-available') }, 5000) }) autoUpdater.on('error', () => { sendStatusToWindow('Error in auto-updater.') setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成 - win.webContents.send('update-error') + global.mainWindow.webContents.send('update-error') }, 6000) }) autoUpdater.on('download-progress', progressObj => { @@ -83,7 +83,7 @@ module.exports = win => { autoUpdater.on('update-downloaded', info => { sendStatusToWindow('Update downloaded.') setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成 - win.webContents.send('update-downloaded') + global.mainWindow.webContents.send('update-downloaded') }, 2000) }) mainOn('quit-update', () => {