optimize: 创建窗口失败时,记录日志并退出软件。
parent
aa58f5a881
commit
95de18a60f
|
@ -179,25 +179,35 @@ 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 || {}
|
||||||
win = new BrowserWindow({
|
|
||||||
width: windowSize.width || 900,
|
try {
|
||||||
height: windowSize.height || 750,
|
win = new BrowserWindow({
|
||||||
title: 'DevSidecar',
|
width: windowSize.width || 900,
|
||||||
webPreferences: {
|
height: windowSize.height || 750,
|
||||||
enableRemoteModule: true,
|
title: 'DevSidecar',
|
||||||
contextIsolation: false,
|
webPreferences: {
|
||||||
nativeWindowOpen: true, // ADD THIS
|
enableRemoteModule: true,
|
||||||
// preload: path.join(__dirname, 'preload.js'),
|
contextIsolation: false,
|
||||||
// Use pluginOptions.nodeIntegration, leave this alone
|
nativeWindowOpen: true, // ADD THIS
|
||||||
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
|
// preload: path.join(__dirname, 'preload.js'),
|
||||||
nodeIntegration: true, // process.env.ELECTRON_NODE_INTEGRATION
|
// Use pluginOptions.nodeIntegration, leave this alone
|
||||||
},
|
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
|
||||||
show: !startHideWindow,
|
nodeIntegration: true, // process.env.ELECTRON_NODE_INTEGRATION
|
||||||
icon: path.join(__static, 'icon.png'),
|
},
|
||||||
})
|
show: !startHideWindow,
|
||||||
|
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