尝试修复Mac系统点击关闭时再打开的BUG

pull/96/head
lyswhut 2019-09-10 02:03:09 +08:00
parent 2f57345bd2
commit 73072daa46
4 changed files with 41 additions and 41 deletions

View File

@ -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',
})
})

View File

@ -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()
}
})

View File

@ -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) {

View File

@ -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', () => {