refactor: Replace tokio::spawn with AsyncHandler::spawn for better task management
- Replace direct tokio::spawn calls with AsyncHandler::spawn across multiple modules - Improves task lifecycle management and error handling consistency - Affected files: - src-tauri/src/cmd/network.rs - src-tauri/src/core/core.rs - src-tauri/src/core/event_driven_proxy.rs - src-tauri/src/enhance/tun.rs - src-tauri/src/ipc/logs.rs - src-tauri/src/ipc/memory.rs - src-tauri/src/ipc/monitor.rs - src-tauri/src/ipc/traffic.rs - src-tauri/src/utils/network.rs - src-tauri/src/utils/resolve.rs This change provides better control over async task spawning and helps prevent potential issues with unmanaged background tasks.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use serde_yaml::{Mapping, Value};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use crate::process::AsyncHandler;
|
||||
|
||||
macro_rules! revise {
|
||||
($map: expr, $key: expr, $val: expr) => {
|
||||
let ret_key = Value::String($key.into());
|
||||
@@ -59,7 +62,7 @@ pub fn use_tun(mut config: Mapping, enable: bool) -> Mapping {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
tokio::spawn(async {
|
||||
AsyncHandler::spawn(move || async move {
|
||||
crate::utils::resolve::restore_public_dns().await;
|
||||
crate::utils::resolve::set_public_dns("223.6.6.6".to_string()).await;
|
||||
});
|
||||
@@ -71,7 +74,7 @@ pub fn use_tun(mut config: Mapping, enable: bool) -> Mapping {
|
||||
} else {
|
||||
// TUN未启用时,仅恢复系统DNS,不修改配置文件中的DNS设置
|
||||
#[cfg(target_os = "macos")]
|
||||
tokio::spawn(async {
|
||||
AsyncHandler::spawn(move || async move {
|
||||
crate::utils::resolve::restore_public_dns().await;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user