修复 MAC 系统下软件关闭时再次从 dock 打开时报错的Bug
parent
73072daa46
commit
a432080141
|
@ -0,0 +1,3 @@
|
|||
### 修复
|
||||
|
||||
- 修复 MAC 系统下软件关闭时再次从 dock 打开时报错的Bug
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in New Issue