diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index 1ff2f881..5dea34b9 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -17,7 +17,6 @@ export class WindowService { private mainWindow: BrowserWindow | null = null private miniWindow: BrowserWindow | null = null private isPinnedMiniWindow: boolean = false - private wasFullScreen: boolean = false //hacky-fix: store the focused status of mainWindow before miniWindow shows //to restore the focus status when miniWindow hides private wasMainWindowFocused: boolean = false @@ -41,7 +40,8 @@ export class WindowService { const mainWindowState = windowStateKeeper({ defaultWidth: 1080, - defaultHeight: 670 + defaultHeight: 670, + fullScreen: false }) const theme = configManager.getTheme() @@ -53,7 +53,7 @@ export class WindowService { height: mainWindowState.height, minWidth: 1080, minHeight: 600, - show: false, // 初始不显示 + show: false, autoHideMenuBar: true, transparent: isMac, vibrancy: 'sidebar', @@ -138,12 +138,10 @@ export class WindowService { // 处理全屏相关事件 mainWindow.on('enter-full-screen', () => { - this.wasFullScreen = true mainWindow.webContents.send(IpcChannel.FullscreenStatusChanged, true) }) mainWindow.on('leave-full-screen', () => { - this.wasFullScreen = 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() mainWindow.hide() @@ -316,16 +304,29 @@ export class WindowService { this.mainWindow.restore() 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)会导致窗口进入"假弹出"状态 - // 因此在 Linux 环境下不执行这两行代码 + /** + * About setVisibleOnAllWorkspaces + * + * [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) { 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.focus() if (!isLinux) { @@ -338,7 +339,9 @@ export class WindowService { public toggleMainWindow() { // 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 }