From 248105e8931b4163b386cc938eb4f5f084204d2a Mon Sep 17 00:00:00 2001 From: std-external <201375710+std-external@users.noreply.github.com> Date: Thu, 26 Nov 2026 11:57:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(window):=20=E8=AE=B0=E4=BD=8F=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=A4=A7=E5=B0=8F=E5=92=8C=E4=BD=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E5=90=8E=E5=9B=9E=E5=88=B0=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E7=9A=84=E6=A0=B7=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前窗口几何完全没有保存:tauri.conf.json 里写死 1100x900,每次启动都是这个 尺寸,也没有任何地方在关闭时记录尺寸、位置或最大化状态,所以用户调过的窗口 一关就丢。 接上官方 tauri-plugin-window-state,只恢复尺寸、位置和最大化三项,可见性与 窗口边框仍由程序自己控制。插件在窗口关闭和进程退出时落盘,下次启动时恢复; 位置只在与现有显示器相交时才套用,拔掉副屏后窗口不会被放到屏幕外。 macOS / Windows / Linux 都生效;Wayland 下位置由合成器决定,只有尺寸能恢复。 --- Cargo.lock | 16 ++++++++++++++++ src-tauri/Cargo.toml | 1 + src-tauri/src/backend.rs | 13 ++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b522b08e..5839b8c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -514,6 +514,7 @@ dependencies = [ "tauri-plugin-single-instance", "tauri-plugin-system-symbols", "tauri-plugin-window-controls", + "tauri-plugin-window-state", "ureq", "url", "webpki-roots 1.0.6", @@ -4686,6 +4687,21 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "tauri-plugin-window-state" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73736611e14142408d15353e21e3cca2f12a3cfb523ad0ce85999b6d2ef1a704" +dependencies = [ + "bitflags 2.11.0", + "log", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.18", +] + [[package]] name = "tauri-runtime" version = "2.11.3" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 85127320..2502b23f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -51,6 +51,7 @@ notify = "8" [target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))'.dependencies] tauri-plugin-system-symbols = "0.3" tauri-plugin-window-controls = "0.1" +tauri-plugin-window-state = "2" game-scanner = { git = "https://github.com/EqualGames/game-scanner", branch = "dependabot/cargo/sysinfo-0.28.2" } tauri-plugin-single-instance = { version = "2.4.3", features = ["deep-link"] } diff --git a/src-tauri/src/backend.rs b/src-tauri/src/backend.rs index bec50fba..249940dc 100644 --- a/src-tauri/src/backend.rs +++ b/src-tauri/src/backend.rs @@ -7693,9 +7693,20 @@ pub fn run() { } #[cfg(desktop)] { + // Remember the window geometry between launches. Only the size, + // position and maximized flag are restored: visibility and + // decorations stay under the app's control. + let window_state_flags = tauri_plugin_window_state::StateFlags::SIZE + | tauri_plugin_window_state::StateFlags::POSITION + | tauri_plugin_window_state::StateFlags::MAXIMIZED; builder = builder .plugin(tauri_plugin_system_symbols::init()) - .plugin(tauri_plugin_window_controls::init()); + .plugin(tauri_plugin_window_controls::init()) + .plugin( + tauri_plugin_window_state::Builder::default() + .with_state_flags(window_state_flags) + .build(), + ); } #[cfg(desktop)] {