optimize: 创建窗口失败时,记录日志并退出软件。
parent
aa58f5a881
commit
95de18a60f
|
@ -179,9 +179,11 @@ function changeAppConfig (config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWindow (startHideWindow) {
|
function createWindow (startHideWindow, autoQuitIfError = true) {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const windowSize = DevSidecar.api.config.get().app.windowSize || {}
|
const windowSize = DevSidecar.api.config.get().app.windowSize || {}
|
||||||
|
|
||||||
|
try {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
width: windowSize.width || 900,
|
width: windowSize.width || 900,
|
||||||
height: windowSize.height || 750,
|
height: windowSize.height || 750,
|
||||||
|
@ -198,6 +200,14 @@ function createWindow (startHideWindow) {
|
||||||
show: !startHideWindow,
|
show: !startHideWindow,
|
||||||
icon: path.join(__static, 'icon.png'),
|
icon: path.join(__static, 'icon.png'),
|
||||||
})
|
})
|
||||||
|
} catch (e) {
|
||||||
|
log.error('创建窗口失败:', e)
|
||||||
|
dialog.showErrorBox('错误', `创建窗口失败: ${e.message}`)
|
||||||
|
if (autoQuitIfError) {
|
||||||
|
quit()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
winIsHidden = !!startHideWindow
|
winIsHidden = !!startHideWindow
|
||||||
|
|
||||||
Menu.setApplicationMenu(null)
|
Menu.setApplicationMenu(null)
|
||||||
|
@ -309,6 +319,8 @@ function createWindow (startHideWindow) {
|
||||||
registerShowHideShortcut(message)
|
registerShowHideShortcut(message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function beforeQuit () {
|
async function beforeQuit () {
|
||||||
|
@ -429,7 +441,7 @@ try {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// On macOS it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (win == null) {
|
if (win == null) {
|
||||||
createWindow(false)
|
createWindow(false, false)
|
||||||
} else {
|
} else {
|
||||||
showWin()
|
showWin()
|
||||||
}
|
}
|
||||||
|
@ -451,7 +463,9 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
createWindow(startHideWindow)
|
if (!createWindow(startHideWindow)) {
|
||||||
|
return // 创建窗口失败,应用将关闭
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error('createWindow error:', err)
|
log.error('createWindow error:', err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue