From a0413158c80c55b7a1a2cb9df7b3347940a25a20 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 3 Jan 2025 11:23:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8macOS=20m1=20?= =?UTF-8?q?=E4=B8=AD=E7=82=B9=E5=87=BB=E5=85=A8=E5=B1=8F=E5=B9=95=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E7=82=B9=E5=87=BB=E5=85=B3=E9=97=AD=E5=90=8E=E9=BB=91?= =?UTF-8?q?=E5=B1=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/services/WindowService.ts | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index fca03c58..7a427658 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -13,6 +13,8 @@ import { configManager } from './ConfigManager' export class WindowService { private static instance: WindowService | null = null private mainWindow: BrowserWindow | null = null + private isQuitting: boolean = false + private wasFullScreen: boolean = false public static getInstance(): WindowService { if (!WindowService.instance) { @@ -42,7 +44,7 @@ export class WindowService { height: mainWindowState.height, minWidth: 1080, minHeight: 600, - show: true, + show: false, // 初始不显示 autoHideMenuBar: true, transparent: isMac, vibrancy: 'under-window', @@ -118,9 +120,20 @@ export class WindowService { } private setupWindowEvents(mainWindow: BrowserWindow) { - mainWindow.on('ready-to-show', () => { + mainWindow.once('ready-to-show', () => { mainWindow.show() }) + + // 处理全屏相关事件 + mainWindow.on('enter-full-screen', () => { + this.wasFullScreen = true + mainWindow.webContents.send('fullscreen-status-changed', true) + }) + + mainWindow.on('leave-full-screen', () => { + this.wasFullScreen = false + mainWindow.webContents.send('fullscreen-status-changed', false) + }) } private setupWebContentsHandlers(mainWindow: BrowserWindow) { @@ -182,6 +195,11 @@ export class WindowService { } private setupWindowLifecycleEvents(mainWindow: BrowserWindow) { + // 监听应用退出事件 + app.on('before-quit', () => { + this.isQuitting = true + }) + mainWindow.on('close', (event) => { const notInTray = !configManager.isTray() @@ -191,9 +209,15 @@ export class WindowService { } // Mac - if (!app.isQuitting) { - event.preventDefault() - mainWindow.hide() + if (!this.isQuitting) { + if (this.wasFullScreen) { + // 如果是全屏状态,直接退出 + this.isQuitting = true + app.quit() + } else { + event.preventDefault() + mainWindow.hide() + } } }) }