From 794c23f2963faf2f597a8f01e4848e79c9396e33 Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Thu, 24 Apr 2025 16:55:51 +0800 Subject: [PATCH] feat(WindowService): add maximize functionality and disable electron-window-state maxmize (#5292) * feat(WindowService): add maximize functionality and clean up window close logic - Introduced a new `maximize` option in the window state configuration. - Added `setupMaximize` method to handle window maximization based on the launch state. - Removed redundant logic from the window close event handler for clarity. * add code * update code --- src/main/services/WindowService.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index cc839ad6ae..62700f81c5 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -41,7 +41,8 @@ export class WindowService { const mainWindowState = windowStateKeeper({ defaultWidth: 1080, defaultHeight: 670, - fullScreen: false + fullScreen: false, + maximize: false }) const theme = configManager.getTheme() @@ -86,6 +87,7 @@ export class WindowService { private setupMainWindow(mainWindow: BrowserWindow, mainWindowState: any) { mainWindowState.manage(mainWindow) + this.setupMaximize(mainWindow, mainWindowState.isMaximized) this.setupContextMenu(mainWindow) this.setupWindowEvents(mainWindow) this.setupWebContentsHandlers(mainWindow) @@ -93,6 +95,17 @@ export class WindowService { this.loadMainWindowContent(mainWindow) } + private setupMaximize(mainWindow: BrowserWindow, isMaximized: boolean) { + if (isMaximized) { + // 如果是从托盘启动,则需要延迟最大化,否则显示的就不是重启前的最大化窗口了 + configManager.getLaunchToTray() + ? mainWindow.once('show', () => { + mainWindow.maximize() + }) + : mainWindow.maximize() + } + } + private setupContextMenu(mainWindow: BrowserWindow) { if (!this.contextMenu) { const locale = locales[configManager.getLanguage()]