From 41263b9f23c01ab6aa219cb511dbc8d46b15e819 Mon Sep 17 00:00:00 2001 From: liuweitao Date: Thu, 9 Apr 2026 23:59:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=90=8E=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=81=A2=E5=A4=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 退出时 `replacementState` 判断条件有误,`replaceWindow` 为 null 时 走 `getBounds()` 分支创建了空对象,导致 `??` 短路未加载已保存的窗口 状态。同时调整 `saveWindowState` 在 `win.hide()` 之前调用,确保获取 正确的窗口 bounds。 --- src/main/windows/MainWindow.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/windows/MainWindow.ts b/src/main/windows/MainWindow.ts index a816bccc..13b3ba68 100644 --- a/src/main/windows/MainWindow.ts +++ b/src/main/windows/MainWindow.ts @@ -97,12 +97,14 @@ export function forceReplaceClose(win: BrowserWindow): void { } export function createMainWindow(options: CreateMainWindowOptions = {}): BrowserWindow { - const replacementState = options.replaceWindow?.isDestroyed() - ? null - : { - ...options.replaceWindow?.getBounds(), - isMaximized: options.replaceWindow?.isMaximized(), - }; + const replacementState = + options.replaceWindow && !options.replaceWindow.isDestroyed() + ? { + ...options.replaceWindow.getBounds(), + isMaximized: options.replaceWindow.isMaximized(), + } + : null; + const state = replacementState ?? loadWindowState(); const isMac = process.platform === 'darwin'; @@ -265,6 +267,7 @@ export function createMainWindow(options: CreateMainWindowOptions = {}): Browser if (win.isDestroyed()) { return; } + saveWindowState(win); forceClose = true; win.hide(); win.close(); @@ -368,8 +371,10 @@ export function createMainWindow(options: CreateMainWindowOptions = {}): Browser }); win.on('close', (e) => { - // Skip confirmation if force close, or quitting for update - if (forceClose || autoUpdaterService.isQuittingForUpdate()) { + if (forceClose) { + return; + } + if (autoUpdaterService.isQuittingForUpdate()) { saveWindowState(win); return; }