fix: Fix app quit exceptionally on MacOS's full screen mode add Add Escape key support for exiting fullscreen mode

This commit is contained in:
suyao 2025-02-28 15:23:21 +08:00 committed by 亢奋猫
parent 84e6caa846
commit fdf4821d56

View File

@ -150,6 +150,17 @@ export class WindowService {
this.wasFullScreen = false
mainWindow.webContents.send('fullscreen-status-changed', false)
})
// 添加Escape键退出全屏的支持
mainWindow.webContents.on('before-input-event', (event, input) => {
// 当按下Escape键且窗口处于全屏状态时退出全屏
if (input.key === 'Escape' && !input.alt && !input.control && !input.meta && !input.shift) {
if (mainWindow.isFullScreen()) {
event.preventDefault()
mainWindow.setFullScreen(false)
}
}
})
}
private setupWebContentsHandlers(mainWindow: BrowserWindow) {
@ -241,11 +252,16 @@ export class WindowService {
return app.quit()
}
// 如果是全屏状态,直接退出
// 如果是Windows或Linux且处于全屏状态则退出应用
if (this.wasFullScreen) {
return app.quit()
if (isWin || isLinux) {
return app.quit()
} else {
event.preventDefault()
mainWindow.setFullScreen(false)
return
}
}
event.preventDefault()
mainWindow.hide()
})