修复 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 mainWindow
|
||||||
let winURL
|
let winURL
|
||||||
let isCheckedUpdate = false
|
let isFirstCheckedUpdate = true
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
global.__static = path.join(__dirname, '../static')
|
global.__static = path.join(__dirname, '../static')
|
||||||
|
@ -63,15 +63,18 @@ function createWindow() {
|
||||||
|
|
||||||
mainWindow.loadURL(winURL)
|
mainWindow.loadURL(winURL)
|
||||||
|
|
||||||
|
mainWindow.on('close', () => {
|
||||||
|
mainWindow.setProgressBar(-1)
|
||||||
|
})
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
mainWindow = global.mainWindow = null
|
mainWindow = global.mainWindow = null
|
||||||
})
|
})
|
||||||
|
|
||||||
// mainWindow.webContents.openDevTools()
|
// mainWindow.webContents.openDevTools()
|
||||||
|
|
||||||
if (!isDev && !isCheckedUpdate) {
|
if (!isDev) {
|
||||||
autoUpdate()
|
autoUpdate(isFirstCheckedUpdate)
|
||||||
isCheckedUpdate = true
|
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', () => {
|
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.')
|
||||||
global.mainWindow.webContents.send('update-available', info)
|
handleSendEvent({ type: 'update-available', info })
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-not-available', info => {
|
autoUpdater.on('update-not-available', info => {
|
||||||
sendStatusToWindow('Update not available.')
|
sendStatusToWindow('Update not available.')
|
||||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
handleSendEvent({ type: 'update-not-available' })
|
||||||
global.mainWindow.webContents.send('update-not-available')
|
|
||||||
}, 5000)
|
|
||||||
})
|
})
|
||||||
autoUpdater.on('error', () => {
|
autoUpdater.on('error', () => {
|
||||||
sendStatusToWindow('Error in auto-updater.')
|
sendStatusToWindow('Error in auto-updater.')
|
||||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
handleSendEvent({ type: 'update-error' })
|
||||||
global.mainWindow.webContents.send('update-error')
|
|
||||||
}, 6000)
|
|
||||||
})
|
})
|
||||||
autoUpdater.on('download-progress', progressObj => {
|
autoUpdater.on('download-progress', progressObj => {
|
||||||
sendStatusToWindow('Download progress...')
|
sendStatusToWindow('Download progress...')
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-downloaded', info => {
|
autoUpdater.on('update-downloaded', info => {
|
||||||
sendStatusToWindow('Update downloaded.')
|
sendStatusToWindow('Update downloaded.')
|
||||||
setTimeout(() => { // 延迟发送事件,过早发送可能渲染进程还启动完成
|
handleSendEvent({ type: 'update-downloaded' })
|
||||||
global.mainWindow.webContents.send('update-downloaded')
|
|
||||||
}, 2000)
|
|
||||||
})
|
})
|
||||||
mainOn('quit-update', () => {
|
mainOn('quit-update', () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
Loading…
Reference in New Issue