feat: improve core functionality to prevent main process blocking, enhance MihomoManager, and optimize window creation process

This commit is contained in:
wonfen
2025-04-25 18:24:16 +08:00
parent d6a79316a6
commit 55cde38562
4 changed files with 256 additions and 155 deletions

View File

@@ -19,6 +19,7 @@ use tauri::AppHandle;
use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_deep_link::DeepLinkExt;
use tokio::time::{timeout, Duration};
use utils::logging::Type;
/// A global singleton handle to the application.
@@ -85,13 +86,22 @@ impl AppHandleManager {
#[allow(clippy::panic)]
pub fn run() {
// 单例检测
// 单例检测 - 使用超时机制防止阻塞
let app_exists: bool = AsyncHandler::block_on(move || async move {
if server::check_singleton().await.is_err() {
println!("app exists");
true
} else {
false
match timeout(Duration::from_secs(3), server::check_singleton()).await {
Ok(result) => {
if result.is_err() {
println!("app exists");
true
} else {
false
}
}
Err(_) => {
// 超时处理
println!("singleton check timeout, assuming app doesn't exist");
false
}
}
});
if app_exists {
@@ -139,8 +149,21 @@ pub fn run() {
});
});
AsyncHandler::block_on(move || async move {
resolve::resolve_setup(app).await;
// 使用 block_on 但增加超时保护
AsyncHandler::block_on(|| async {
match timeout(Duration::from_secs(30), resolve::resolve_setup(app)).await {
Ok(_) => {
logging!(info, Type::Setup, true, "App setup completed successfully");
}
Err(_) => {
logging!(
error,
Type::Setup,
true,
"App setup timed out, proceeding anyway"
);
}
}
});
Ok(())