mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: improve core functionality to prevent main process blocking, enhance MihomoManager, and optimize window creation process
This commit is contained in:
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user