fix: [mac] issues related to fullscreen mode (#4618)
This commit is contained in:
parent
d5fcef39d3
commit
0db4c8b475
@ -17,7 +17,6 @@ export class WindowService {
|
|||||||
private mainWindow: BrowserWindow | null = null
|
private mainWindow: BrowserWindow | null = null
|
||||||
private miniWindow: BrowserWindow | null = null
|
private miniWindow: BrowserWindow | null = null
|
||||||
private isPinnedMiniWindow: boolean = false
|
private isPinnedMiniWindow: boolean = false
|
||||||
private wasFullScreen: boolean = false
|
|
||||||
//hacky-fix: store the focused status of mainWindow before miniWindow shows
|
//hacky-fix: store the focused status of mainWindow before miniWindow shows
|
||||||
//to restore the focus status when miniWindow hides
|
//to restore the focus status when miniWindow hides
|
||||||
private wasMainWindowFocused: boolean = false
|
private wasMainWindowFocused: boolean = false
|
||||||
@ -41,7 +40,8 @@ export class WindowService {
|
|||||||
|
|
||||||
const mainWindowState = windowStateKeeper({
|
const mainWindowState = windowStateKeeper({
|
||||||
defaultWidth: 1080,
|
defaultWidth: 1080,
|
||||||
defaultHeight: 670
|
defaultHeight: 670,
|
||||||
|
fullScreen: false
|
||||||
})
|
})
|
||||||
|
|
||||||
const theme = configManager.getTheme()
|
const theme = configManager.getTheme()
|
||||||
@ -53,7 +53,7 @@ export class WindowService {
|
|||||||
height: mainWindowState.height,
|
height: mainWindowState.height,
|
||||||
minWidth: 1080,
|
minWidth: 1080,
|
||||||
minHeight: 600,
|
minHeight: 600,
|
||||||
show: false, // 初始不显示
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
transparent: isMac,
|
transparent: isMac,
|
||||||
vibrancy: 'sidebar',
|
vibrancy: 'sidebar',
|
||||||
@ -138,12 +138,10 @@ export class WindowService {
|
|||||||
|
|
||||||
// 处理全屏相关事件
|
// 处理全屏相关事件
|
||||||
mainWindow.on('enter-full-screen', () => {
|
mainWindow.on('enter-full-screen', () => {
|
||||||
this.wasFullScreen = true
|
|
||||||
mainWindow.webContents.send(IpcChannel.FullscreenStatusChanged, true)
|
mainWindow.webContents.send(IpcChannel.FullscreenStatusChanged, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('leave-full-screen', () => {
|
mainWindow.on('leave-full-screen', () => {
|
||||||
this.wasFullScreen = false
|
|
||||||
mainWindow.webContents.send(IpcChannel.FullscreenStatusChanged, false)
|
mainWindow.webContents.send(IpcChannel.FullscreenStatusChanged, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -275,16 +273,6 @@ export class WindowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//上述逻辑以下,是“开启托盘+设置关闭时最小化到托盘”的情况
|
//上述逻辑以下,是“开启托盘+设置关闭时最小化到托盘”的情况
|
||||||
// 如果是Windows或Linux,且处于全屏状态,则退出应用
|
|
||||||
if (this.wasFullScreen) {
|
|
||||||
if (isWin || isLinux) {
|
|
||||||
return app.quit()
|
|
||||||
} else {
|
|
||||||
event.preventDefault()
|
|
||||||
mainWindow.setFullScreen(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
mainWindow.hide()
|
mainWindow.hide()
|
||||||
@ -316,16 +304,29 @@ export class WindowService {
|
|||||||
this.mainWindow.restore()
|
this.mainWindow.restore()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//[macOS] Known Issue
|
|
||||||
// setVisibleOnAllWorkspaces true/false will NOT bring window to current desktop in Mac (works fine with Windows)
|
|
||||||
// AppleScript may be a solution, but it's not worth
|
|
||||||
|
|
||||||
// [Linux] Known Issue
|
/**
|
||||||
// setVisibleOnAllWorkspaces 在 Linux 环境下(特别是 KDE Wayland)会导致窗口进入"假弹出"状态
|
* About setVisibleOnAllWorkspaces
|
||||||
// 因此在 Linux 环境下不执行这两行代码
|
*
|
||||||
|
* [macOS] Known Issue
|
||||||
|
* setVisibleOnAllWorkspaces true/false will NOT bring window to current desktop in Mac (works fine with Windows)
|
||||||
|
* AppleScript may be a solution, but it's not worth
|
||||||
|
*
|
||||||
|
* [Linux] Known Issue
|
||||||
|
* setVisibleOnAllWorkspaces 在 Linux 环境下(特别是 KDE Wayland)会导致窗口进入"假弹出"状态
|
||||||
|
* 因此在 Linux 环境下不执行这两行代码
|
||||||
|
*/
|
||||||
if (!isLinux) {
|
if (!isLinux) {
|
||||||
this.mainWindow.setVisibleOnAllWorkspaces(true)
|
this.mainWindow.setVisibleOnAllWorkspaces(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[macOS] After being closed in fullscreen, the fullscreen behavior will become strange when window shows again
|
||||||
|
// So we need to set it to FALSE explicitly.
|
||||||
|
// althougle other platforms don't have the issue, but it's a good practice to do so
|
||||||
|
if (this.mainWindow.isFullScreen()) {
|
||||||
|
this.mainWindow.setFullScreen(false)
|
||||||
|
}
|
||||||
|
|
||||||
this.mainWindow.show()
|
this.mainWindow.show()
|
||||||
this.mainWindow.focus()
|
this.mainWindow.focus()
|
||||||
if (!isLinux) {
|
if (!isLinux) {
|
||||||
@ -338,7 +339,9 @@ export class WindowService {
|
|||||||
|
|
||||||
public toggleMainWindow() {
|
public toggleMainWindow() {
|
||||||
// should not toggle main window when in full screen
|
// should not toggle main window when in full screen
|
||||||
if (this.wasFullScreen) {
|
// but if the main window is close to tray when it's in full screen, we can show it again
|
||||||
|
// (it's a bug in macos, because we can close the window when it's in full screen, and the state will be remained)
|
||||||
|
if (this.mainWindow?.isFullScreen() && this.mainWindow?.isVisible()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user