diff --git a/package.json b/package.json index fb145e07..e3964384 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "@tauri-apps/plugin-shell": "^2.2.1", "@tauri-apps/plugin-sql": "^2.2.0", "@tauri-apps/plugin-updater": "2.7.1", + "@tauri-apps/plugin-window-state": "^2.2.2", "colorthief": "^2.6.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.11", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a6692c5c..acd21590 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2243,6 +2243,7 @@ dependencies = [ "tauri-plugin-sql", "tauri-plugin-updater", "tauri-plugin-upload", + "tauri-plugin-window-state", "tokio", "tungstenite", ] @@ -6008,6 +6009,21 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "tauri-plugin-window-state" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27a3fe49de72adbe0d84aee33c89a0b059722cd0b42aaeab29eaaee7f7535cd" +dependencies = [ + "bitflags 2.9.1", + "log", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.12", +] + [[package]] name = "tauri-runtime" version = "2.6.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6841616e..902184ab 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -72,6 +72,9 @@ rand = "0.8.5" cocoa = "0.26.0" objc = "0.2.7" +[target."cfg(any(target_os = \"macos\", target_os = \"windows\", target_os = \"linux\"))".dependencies] +tauri-plugin-window-state = "2.2.2" + [features] # by default Tauri runs in production mode # when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is a URL diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 72abb5f8..c5be70f9 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -91,6 +91,9 @@ "notification:allow-delete-channel", "notification:allow-create-channel", "notification:allow-permission-state", + "window-state:allow-filename", + "window-state:allow-restore-state", + "window-state:allow-save-window-state", { "identifier": "shell:allow-execute", "allow": [ diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 08398925..0aee80e7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -47,6 +47,8 @@ fn setup_desktop() { .init_window_event() .setup(move |app| { tray::create_tray(app.handle())?; + #[cfg(desktop)] + let _ = app.handle().plugin(tauri_plugin_window_state::Builder::default().build()); Ok(()) }) .invoke_handler(tauri::generate_handler![ diff --git a/src/layout/index.vue b/src/layout/index.vue index 8150944a..e7cf0adf 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -358,6 +358,7 @@ onMounted(async () => { // 监听home窗口被聚焦的事件,当窗口被聚焦时自动关闭状态栏通知 const homeWindow = await WebviewWindow.getByLabel('home') if (homeWindow) { + homeWindow.show() homeWindow.onFocusChanged(({ payload: focused }) => { // 当窗口获得焦点时,关闭通知提示 if (focused) { diff --git a/src/views/loginWindow/Login.vue b/src/views/loginWindow/Login.vue index ff37572a..c8f454fc 100644 --- a/src/views/loginWindow/Login.vue +++ b/src/views/loginWindow/Login.vue @@ -406,7 +406,7 @@ const normalLogin = async (auto = false) => { } const openHomeWindow = async () => { - await createWebviewWindow('HuLa', 'home', 960, 720, 'login', true, undefined, 480) + await createWebviewWindow('HuLa', 'home', 960, 720, 'login', true, undefined, 480, undefined, false) } /** 移除已登录账号 */