From b96120ec7e544d95cff2f6944c846f4d473ec403 Mon Sep 17 00:00:00 2001 From: LemonNeko Date: Thu, 1 May 2025 18:49:33 +0800 Subject: [PATCH] fix(tamagotchi): process stuck when create settings window on Windows (#154) --- Cargo.lock | 53 +++++++++++++++++++ apps/stage-tamagotchi/src-tauri/Cargo.toml | 1 + .../src-tauri/src/commands.rs | 2 +- apps/stage-tamagotchi/src-tauri/src/lib.rs | 6 +++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1291a4d50..2b67d129e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,6 +102,7 @@ dependencies = [ "tauri-plugin-log", "tauri-plugin-mcp", "tauri-plugin-os", + "tauri-plugin-prevent-default", ] [[package]] @@ -781,6 +782,12 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005" +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "embed-resource" version = "3.0.2" @@ -1692,6 +1699,15 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.8" @@ -3375,6 +3391,28 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.101", +] + [[package]] name = "swift-rs" version = "1.0.7" @@ -3698,6 +3736,21 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "tauri-plugin-prevent-default" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20327367bca73bc4a08973592b0e6fe716321566207c52c79234876a5467c4ac" +dependencies = [ + "bitflags 2.9.0", + "itertools", + "serde", + "strum", + "tauri", + "tauri-plugin", + "thiserror 2.0.12", +] + [[package]] name = "tauri-runtime" version = "2.6.0" diff --git a/apps/stage-tamagotchi/src-tauri/Cargo.toml b/apps/stage-tamagotchi/src-tauri/Cargo.toml index 9eafa2e06..09d3b78fd 100644 --- a/apps/stage-tamagotchi/src-tauri/Cargo.toml +++ b/apps/stage-tamagotchi/src-tauri/Cargo.toml @@ -32,3 +32,4 @@ tauri = { version = "2.3.1", features = [ tauri-plugin-log = "2.0.0-rc" tauri-plugin-os = "2" tauri-plugin-mcp = { workspace = true } +tauri-plugin-prevent-default = "1.3" diff --git a/apps/stage-tamagotchi/src-tauri/src/commands.rs b/apps/stage-tamagotchi/src-tauri/src/commands.rs index 874cecc81..6468d3c36 100644 --- a/apps/stage-tamagotchi/src-tauri/src/commands.rs +++ b/apps/stage-tamagotchi/src-tauri/src/commands.rs @@ -2,7 +2,7 @@ use std::path::Path; use tauri::{Manager, WebviewUrl, WebviewWindowBuilder}; #[tauri::command] -pub fn open_settings_window(app: tauri::AppHandle) { +pub async fn open_settings_window(app: tauri::AppHandle) { if let Some(window) = app.get_webview_window("settings") { let _ = window.show(); return; diff --git a/apps/stage-tamagotchi/src-tauri/src/lib.rs b/apps/stage-tamagotchi/src-tauri/src/lib.rs index 9f4dc10d9..8e0806d93 100644 --- a/apps/stage-tamagotchi/src-tauri/src/lib.rs +++ b/apps/stage-tamagotchi/src-tauri/src/lib.rs @@ -4,12 +4,18 @@ use tauri::tray::TrayIconBuilder; #[cfg(target_os = "macos")] use tauri::{ActivationPolicy, TitleBarStyle}; use tauri::{Manager, WebviewUrl, WebviewWindowBuilder}; +use tauri_plugin_prevent_default::Flags; mod commands; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { + let prevent_default_plugin = tauri_plugin_prevent_default::Builder::new() + .with_flags(Flags::RELOAD) + .build(); + tauri::Builder::default() + .plugin(prevent_default_plugin) .plugin(tauri_plugin_mcp::Builder.build()) .plugin(tauri_plugin_os::init()) .setup(|app| {