mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 03:23:57 +08:00
fix: #3227, use async operations to avoid blocking on
This commit is contained in:
parent
30ea408019
commit
7b5fd104de
@ -23,7 +23,7 @@ static APP_START_TIME: Lazy<AtomicI64> = Lazy::new(|| {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn export_diagnostic_info() -> CmdResult<()> {
|
pub async fn export_diagnostic_info() -> CmdResult<()> {
|
||||||
let sysinfo = PlatformSpecification::new();
|
let sysinfo = PlatformSpecification::new_async().await;
|
||||||
let info = format!("{:?}", sysinfo);
|
let info = format!("{:?}", sysinfo);
|
||||||
|
|
||||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||||
@ -36,7 +36,7 @@ pub async fn export_diagnostic_info() -> CmdResult<()> {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_system_info() -> CmdResult<String> {
|
pub async fn get_system_info() -> CmdResult<String> {
|
||||||
let sysinfo = PlatformSpecification::new();
|
let sysinfo = PlatformSpecification::new_async().await;
|
||||||
let info = format!("{:?}", sysinfo);
|
let info = format!("{:?}", sysinfo);
|
||||||
Ok(info)
|
Ok(info)
|
||||||
}
|
}
|
||||||
|
@ -29,25 +29,31 @@ pub fn restart_app() {
|
|||||||
tauri::async_runtime::spawn_blocking(|| {
|
tauri::async_runtime::spawn_blocking(|| {
|
||||||
tauri::async_runtime::block_on(async {
|
tauri::async_runtime::block_on(async {
|
||||||
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
||||||
|
resolve::resolve_reset_async().await;
|
||||||
|
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
tauri::process::restart(&app_handle.env());
|
||||||
});
|
});
|
||||||
resolve::resolve_reset();
|
|
||||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
||||||
tauri::process::restart(&app_handle.env());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_change_clash_mode() {
|
fn after_change_clash_mode() {
|
||||||
let _ = tauri::async_runtime::block_on(tauri::async_runtime::spawn_blocking(|| {
|
tauri::async_runtime::spawn(async {
|
||||||
tauri::async_runtime::block_on(async {
|
match MihomoManager::global().get_connections().await {
|
||||||
let connections = MihomoManager::global().get_connections().await.unwrap();
|
Ok(connections) => {
|
||||||
let connections = connections["connections"].as_array().unwrap();
|
if let Some(connections_array) = connections["connections"].as_array() {
|
||||||
for connection in connections {
|
for connection in connections_array {
|
||||||
let id = connection["id"].as_str().unwrap();
|
if let Some(id) = connection["id"].as_str() {
|
||||||
let _ = MihomoManager::global().delete_connection(id).await;
|
let _ = MihomoManager::global().delete_connection(id).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
Err(err) => {
|
||||||
}));
|
log::error!(target: "app", "Failed to get connections: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change Clash mode (rule/global/direct/script)
|
/// Change Clash mode (rule/global/direct/script)
|
||||||
|
@ -36,13 +36,8 @@ impl PlatformSpecification {
|
|||||||
let config = handler.config();
|
let config = handler.config();
|
||||||
let verge_version = config.version.clone().unwrap_or("Null".into());
|
let verge_version = config.version.clone().unwrap_or("Null".into());
|
||||||
|
|
||||||
// Get running mode asynchronously
|
// 使用默认值避免在同步上下文中执行异步操作
|
||||||
let running_mode = tokio::task::block_in_place(|| {
|
let running_mode = "NotRunning".to_string();
|
||||||
tokio::runtime::Handle::current().block_on(async {
|
|
||||||
let running_mode = CoreManager::global().get_running_mode().await;
|
|
||||||
running_mode.to_string()
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
let is_admin = match system::is_admin() {
|
let is_admin = match system::is_admin() {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
@ -59,4 +54,14 @@ impl PlatformSpecification {
|
|||||||
is_admin,
|
is_admin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 异步方法来获取完整的系统信息
|
||||||
|
pub async fn new_async() -> Self {
|
||||||
|
let mut info = Self::new();
|
||||||
|
|
||||||
|
let running_mode = CoreManager::global().get_running_mode().await;
|
||||||
|
info.running_mode = running_mode.to_string();
|
||||||
|
|
||||||
|
info
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,26 +130,24 @@ pub async fn resolve_setup(app: &mut App) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// reset system proxy
|
/// reset system proxy (异步版)
|
||||||
pub fn resolve_reset() {
|
pub async fn resolve_reset_async() {
|
||||||
tauri::async_runtime::block_on(async move {
|
#[cfg(target_os = "macos")]
|
||||||
#[cfg(target_os = "macos")]
|
logging!(info, Type::Tray, true, "Unsubscribing from traffic updates");
|
||||||
logging!(info, Type::Tray, true, "Unsubscribing from traffic updates");
|
#[cfg(target_os = "macos")]
|
||||||
#[cfg(target_os = "macos")]
|
tray::Tray::global().unsubscribe_traffic();
|
||||||
tray::Tray::global().unsubscribe_traffic();
|
|
||||||
|
|
||||||
logging_error!(
|
logging_error!(
|
||||||
Type::System,
|
Type::System,
|
||||||
true,
|
true,
|
||||||
sysopt::Sysopt::global().reset_sysproxy().await
|
sysopt::Sysopt::global().reset_sysproxy().await
|
||||||
);
|
);
|
||||||
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
logging!(info, Type::System, true, "Restoring system DNS settings");
|
logging!(info, Type::System, true, "Restoring system DNS settings");
|
||||||
restore_public_dns().await;
|
restore_public_dns().await;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// create main window
|
/// create main window
|
||||||
|
Loading…
x
Reference in New Issue
Block a user