From f2aa1573fa0c69ef4ef84062dcb5c84f6e448ebb Mon Sep 17 00:00:00 2001 From: zinface Date: Tue, 18 Aug 2026 11:36:43 +0800 Subject: [PATCH] =?UTF-8?q?electron(titleBar):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=8A=B6=E6=80=81IPC=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E4=B8=8E=E6=A1=A5=E6=8E=A5=E5=99=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/index.ts | 8 ++++++++ electron/preload/index.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/electron/main/index.ts b/electron/main/index.ts index 6b514806..b84443b3 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -843,6 +843,14 @@ app.whenReady().then(() => { }); }); +ipcMain.handle('window:state', () => { + const win = BrowserWindow.getFocusedWindow() + if (!win) return 'normal' + if (win.isMaximized()) return 'maximized' + if (win.isMinimized()) return 'minimized' + return 'normal' +}) + // New window example arg: new windows url // ipcMain.handle('open-win', (_, arg) => { // const childWindow = new BrowserWindow({ diff --git a/electron/preload/index.ts b/electron/preload/index.ts index da219272..27f490b5 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -51,6 +51,7 @@ type WindowControlBridge = { minimize: () => void; toggleMaximize: () => void; close: () => void; + state: () => Promise<| 'normal' | 'maximized' | 'minimized'>; }; type UpdateCenterStateListener = (snapshot: UpdateCenterSnapshot) => void; @@ -110,6 +111,7 @@ contextBridge.exposeInMainWorld("windowControls", { minimize: () => ipcRenderer.send("window-control-minimize"), toggleMaximize: () => ipcRenderer.send("window-control-toggle-maximize"), close: () => ipcRenderer.send("window-control-close"), + state: () => ipcRenderer.invoke("window:state"), } satisfies WindowControlBridge); contextBridge.exposeInMainWorld("updateCenter", {