尝试修复Mac系统点击关闭时再打开的BUG
parent
2f57345bd2
commit
73072daa46
|
@ -1,11 +1,10 @@
|
||||||
const { mainOn } = require('../../common/icp')
|
const { mainOn } = require('../../common/icp')
|
||||||
|
|
||||||
module.exports = win => {
|
|
||||||
mainOn('progress', (event, params) => {
|
mainOn('progress', (event, params) => {
|
||||||
// console.log(params)
|
// console.log(params)
|
||||||
win.setProgressBar(params.status, {
|
global.mainWindow && global.mainWindow.setProgressBar(params.status, {
|
||||||
mode: params.mode || 'normal',
|
mode: params.mode || 'normal',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
// const { app } = require('electron')
|
// const { app } = require('electron')
|
||||||
const { mainOn } = require('../../common/icp')
|
const { mainOn } = require('../../common/icp')
|
||||||
|
|
||||||
module.exports = win => {
|
|
||||||
mainOn('min', event => {
|
mainOn('min', event => {
|
||||||
if (win) {
|
if (global.mainWindow) {
|
||||||
win.minimize()
|
global.mainWindow.minimize()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// mainOn('max', event => {
|
// mainOn('max', event => {
|
||||||
// if (win) {
|
// if (global.mainWindow) {
|
||||||
// win.maximize()
|
// global.mainWindow.maximize()
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
mainOn('close', event => {
|
mainOn('close', event => {
|
||||||
if (win) {
|
if (global.mainWindow) {
|
||||||
// window.destroy()
|
// global.mainWindowdow.destroy()
|
||||||
// console.log('close')
|
// console.log('close')
|
||||||
// app.quit()
|
// app.quit()
|
||||||
win.close()
|
global.mainWindow.close()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ app.on('second-instance', (event, argv, cwd) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
require('./events')
|
require('./events')
|
||||||
const progressBar = require('./events/progressBar')
|
require('./events/progressBar')
|
||||||
const trafficLight = require('./events/trafficLight')
|
require('./events/trafficLight')
|
||||||
const autoUpdate = require('./utils/autoUpdate')
|
const autoUpdate = require('./utils/autoUpdate')
|
||||||
const { isLinux, isMac } = require('../common/utils')
|
const { isLinux, isMac } = require('../common/utils')
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ const isDev = process.env.NODE_ENV !== 'production'
|
||||||
|
|
||||||
let mainWindow
|
let mainWindow
|
||||||
let winURL
|
let winURL
|
||||||
|
let isCheckedUpdate = false
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
global.__static = path.join(__dirname, '../static')
|
global.__static = path.join(__dirname, '../static')
|
||||||
|
@ -43,7 +44,7 @@ function createWindow() {
|
||||||
/**
|
/**
|
||||||
* Initial window options
|
* Initial window options
|
||||||
*/
|
*/
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = global.mainWindow = new BrowserWindow({
|
||||||
height: 590,
|
height: 590,
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
width: 920,
|
width: 920,
|
||||||
|
@ -63,14 +64,15 @@ function createWindow() {
|
||||||
mainWindow.loadURL(winURL)
|
mainWindow.loadURL(winURL)
|
||||||
|
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
if (!isMac) mainWindow = null
|
mainWindow = global.mainWindow = null
|
||||||
})
|
})
|
||||||
|
|
||||||
// mainWindow.webContents.openDevTools()
|
// mainWindow.webContents.openDevTools()
|
||||||
|
|
||||||
trafficLight(mainWindow)
|
if (!isDev && !isCheckedUpdate) {
|
||||||
progressBar(mainWindow)
|
autoUpdate()
|
||||||
if (!isDev) autoUpdate(mainWindow)
|
isCheckedUpdate = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMac) {
|
if (isMac) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ log.info('App starting...')
|
||||||
|
|
||||||
function sendStatusToWindow(text) {
|
function sendStatusToWindow(text) {
|
||||||
log.info(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', () => {
|
autoUpdater.on('checking-for-update', () => {
|
||||||
sendStatusToWindow('Checking for update...')
|
sendStatusToWindow('Checking for update...')
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-available', info => {
|
autoUpdater.on('update-available', info => {
|
||||||
sendStatusToWindow('Update available.')
|
sendStatusToWindow('Update available.')
|
||||||
win.webContents.send('update-available', info)
|
global.mainWindow.webContents.send('update-available', info)
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-not-available', info => {
|
autoUpdater.on('update-not-available', info => {
|
||||||
sendStatusToWindow('Update not available.')
|
sendStatusToWindow('Update not available.')
|
||||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
||||||
win.webContents.send('update-not-available')
|
global.mainWindow.webContents.send('update-not-available')
|
||||||
}, 5000)
|
}, 5000)
|
||||||
})
|
})
|
||||||
autoUpdater.on('error', () => {
|
autoUpdater.on('error', () => {
|
||||||
sendStatusToWindow('Error in auto-updater.')
|
sendStatusToWindow('Error in auto-updater.')
|
||||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
||||||
win.webContents.send('update-error')
|
global.mainWindow.webContents.send('update-error')
|
||||||
}, 6000)
|
}, 6000)
|
||||||
})
|
})
|
||||||
autoUpdater.on('download-progress', progressObj => {
|
autoUpdater.on('download-progress', progressObj => {
|
||||||
|
@ -83,7 +83,7 @@ module.exports = win => {
|
||||||
autoUpdater.on('update-downloaded', info => {
|
autoUpdater.on('update-downloaded', info => {
|
||||||
sendStatusToWindow('Update downloaded.')
|
sendStatusToWindow('Update downloaded.')
|
||||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
||||||
win.webContents.send('update-downloaded')
|
global.mainWindow.webContents.send('update-downloaded')
|
||||||
}, 2000)
|
}, 2000)
|
||||||
})
|
})
|
||||||
mainOn('quit-update', () => {
|
mainOn('quit-update', () => {
|
||||||
|
|
Loading…
Reference in New Issue