refactor: clean up imports and remove unused initialization in NetworkManager
This commit is contained in:
@@ -6,6 +6,11 @@ use kode_bridge::{
|
||||
};
|
||||
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
|
||||
|
||||
use crate::{
|
||||
logging, singleton_with_logging,
|
||||
utils::{dirs::ipc_path, logging::Type},
|
||||
};
|
||||
|
||||
// 定义用于URL路径的编码集合,只编码真正必要的字符
|
||||
const URL_PATH_ENCODE_SET: &AsciiSet = &CONTROLS
|
||||
.add(b' ') // 空格
|
||||
@@ -15,8 +20,6 @@ const URL_PATH_ENCODE_SET: &AsciiSet = &CONTROLS
|
||||
.add(b'&') // 和号
|
||||
.add(b'%'); // 百分号
|
||||
|
||||
use crate::{logging, singleton_with_logging, utils::dirs::ipc_path};
|
||||
|
||||
// Helper function to create AnyError from string
|
||||
fn create_error(msg: impl Into<String>) -> AnyError {
|
||||
Box::new(std::io::Error::other(msg.into()))
|
||||
@@ -29,13 +32,7 @@ pub struct IpcManager {
|
||||
impl IpcManager {
|
||||
fn new() -> Self {
|
||||
let ipc_path_buf = ipc_path().unwrap_or_else(|e| {
|
||||
logging!(
|
||||
error,
|
||||
crate::utils::logging::Type::Ipc,
|
||||
true,
|
||||
"Failed to get IPC path: {}",
|
||||
e
|
||||
);
|
||||
logging!(error, Type::Ipc, true, "Failed to get IPC path: {}", e);
|
||||
std::path::PathBuf::from("/tmp/clash-verge-ipc") // fallback path
|
||||
});
|
||||
let ipc_path = ipc_path_buf.to_str().unwrap_or_default();
|
||||
@@ -48,9 +45,9 @@ impl IpcManager {
|
||||
max_requests_per_second: Some(64.0),
|
||||
..Default::default()
|
||||
};
|
||||
Self {
|
||||
client: IpcHttpClient::with_config(ipc_path, config).unwrap(),
|
||||
}
|
||||
#[allow(clippy::unwrap_used)]
|
||||
let client = IpcHttpClient::with_config(ipc_path, config).unwrap();
|
||||
Self { client }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ use isahc::{
|
||||
},
|
||||
};
|
||||
use isahc::{config::SslOption, HttpClient};
|
||||
use std::sync::Once;
|
||||
use std::time::{Duration, Instant};
|
||||
use sysproxy::Sysproxy;
|
||||
use tokio::sync::Mutex;
|
||||
@@ -56,7 +55,6 @@ pub struct NetworkManager {
|
||||
self_proxy_client: Mutex<Option<HttpClient>>,
|
||||
system_proxy_client: Mutex<Option<HttpClient>>,
|
||||
no_proxy_client: Mutex<Option<HttpClient>>,
|
||||
init: Once,
|
||||
last_connection_error: Mutex<Option<(Instant, String)>>,
|
||||
connection_error_count: Mutex<usize>,
|
||||
}
|
||||
@@ -67,16 +65,11 @@ impl NetworkManager {
|
||||
self_proxy_client: Mutex::new(None),
|
||||
system_proxy_client: Mutex::new(None),
|
||||
no_proxy_client: Mutex::new(None),
|
||||
init: Once::new(),
|
||||
last_connection_error: Mutex::new(None),
|
||||
connection_error_count: Mutex::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(&self) {
|
||||
self.init.call_once(|| {});
|
||||
}
|
||||
|
||||
async fn record_connection_error(&self, error: &str) {
|
||||
let mut last_error = self.last_connection_error.lock().await;
|
||||
*last_error = Some((Instant::now(), error.to_string()));
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
logging, logging_error,
|
||||
module::lightweight::auto_lightweight_mode_init,
|
||||
process::AsyncHandler,
|
||||
utils::{init, logging::Type, network::NetworkManager, resolve::window::create_window, server},
|
||||
utils::{init, logging::Type, resolve::window::create_window, server},
|
||||
};
|
||||
|
||||
pub mod dns;
|
||||
@@ -22,9 +22,8 @@ pub fn resolve_setup_handle(app_handle: AppHandle) {
|
||||
|
||||
pub fn resolve_setup_sync() {
|
||||
AsyncHandler::spawn(|| async {
|
||||
AsyncHandler::spawn_blocking(|| init_scheme());
|
||||
AsyncHandler::spawn_blocking(|| init_embed_server());
|
||||
AsyncHandler::spawn_blocking(|| NetworkManager::new().init());
|
||||
AsyncHandler::spawn_blocking(init_scheme);
|
||||
AsyncHandler::spawn_blocking(init_embed_server);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user