mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: simplify proxy type handling and improve error handling in network commands
This commit is contained in:
@@ -128,9 +128,10 @@ impl WebDavClient {
|
||||
.build()?;
|
||||
|
||||
// 尝试检查目录是否存在,如果不存在尝试创建,但创建失败不报错
|
||||
if let Err(_) = client
|
||||
if client
|
||||
.list(dirs::BACKUP_DIR, reqwest_dav::Depth::Number(0))
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
let _ = client.mkcol(dirs::BACKUP_DIR).await;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ impl NotificationSystem {
|
||||
let system_guard = handle.notification_system.read();
|
||||
let is_emergency = system_guard
|
||||
.as_ref()
|
||||
.and_then(|sys| Some(*sys.emergency_mode.read()))
|
||||
.map(|sys| *sys.emergency_mode.read())
|
||||
.unwrap_or(false);
|
||||
|
||||
if is_emergency {
|
||||
@@ -110,7 +110,7 @@ impl NotificationSystem {
|
||||
&window,
|
||||
"verge://refresh-clash-config",
|
||||
"yes",
|
||||
&handle,
|
||||
handle,
|
||||
);
|
||||
}
|
||||
FrontendEvent::RefreshVerge => {
|
||||
@@ -118,7 +118,7 @@ impl NotificationSystem {
|
||||
&window,
|
||||
"verge://refresh-verge-config",
|
||||
"yes",
|
||||
&handle,
|
||||
handle,
|
||||
);
|
||||
}
|
||||
FrontendEvent::NoticeMessage {
|
||||
@@ -129,7 +129,7 @@ impl NotificationSystem {
|
||||
&window,
|
||||
"verge://notice-message",
|
||||
(status.clone(), message.clone()),
|
||||
&handle,
|
||||
handle,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ impl Default for Handle {
|
||||
impl Handle {
|
||||
pub fn global() -> &'static Handle {
|
||||
static HANDLE: OnceCell<Handle> = OnceCell::new();
|
||||
HANDLE.get_or_init(|| Handle::default())
|
||||
HANDLE.get_or_init(Handle::default)
|
||||
}
|
||||
|
||||
pub fn init(&self, app_handle: &AppHandle) {
|
||||
|
||||
@@ -538,7 +538,7 @@ pub async fn check_ipc_service_status() -> Result<JsonResponse> {
|
||||
json_response.msg,
|
||||
json_response.data.is_some()
|
||||
);
|
||||
return Ok(json_response);
|
||||
Ok(json_response)
|
||||
} else {
|
||||
// 尝试直接解析
|
||||
match serde_json::from_value::<JsonResponse>(data.clone()) {
|
||||
@@ -551,7 +551,7 @@ pub async fn check_ipc_service_status() -> Result<JsonResponse> {
|
||||
json_response.code,
|
||||
json_response.msg
|
||||
);
|
||||
return Ok(json_response);
|
||||
Ok(json_response)
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(
|
||||
|
||||
@@ -385,10 +385,7 @@ impl Timer {
|
||||
}
|
||||
};
|
||||
|
||||
let profile = match items
|
||||
.iter()
|
||||
.find(|item| item.uid.as_ref().map(|u| u.as_str()) == Some(uid))
|
||||
{
|
||||
let profile = match items.iter().find(|item| item.uid.as_deref() == Some(uid)) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
logging!(warn, Type::Timer, "找不到对应的配置,uid={}", uid);
|
||||
@@ -441,7 +438,6 @@ impl Timer {
|
||||
}
|
||||
|
||||
/// Async task with better error handling and logging
|
||||
|
||||
async fn async_task(uid: String) {
|
||||
let task_start = std::time::Instant::now();
|
||||
logging!(info, Type::Timer, "Running timer task for profile: {}", uid);
|
||||
|
||||
@@ -442,7 +442,7 @@ impl Tray {
|
||||
traffic_result = stream.next() => {
|
||||
match traffic_result {
|
||||
Some(Ok(traffic)) => {
|
||||
if let Ok(speedrate_result) = tokio::time::timeout(
|
||||
if let Ok(Some(rate)) = tokio::time::timeout(
|
||||
std::time::Duration::from_millis(50),
|
||||
async {
|
||||
let guard = speed_rate.try_lock();
|
||||
@@ -457,12 +457,10 @@ impl Tray {
|
||||
}
|
||||
}
|
||||
).await {
|
||||
if let Some(rate) = speedrate_result {
|
||||
let _ = tokio::time::timeout(
|
||||
std::time::Duration::from_millis(100),
|
||||
async { let _ = Tray::global().update_icon(Some(rate)); }
|
||||
).await;
|
||||
}
|
||||
let _ = tokio::time::timeout(
|
||||
std::time::Duration::from_millis(100),
|
||||
async { let _ = Tray::global().update_icon(Some(rate)); }
|
||||
).await;
|
||||
}
|
||||
},
|
||||
Some(Err(e)) => {
|
||||
|
||||
@@ -271,7 +271,7 @@ impl Traffic {
|
||||
// 设置流超时控制
|
||||
let traffic_stream = ws_stream
|
||||
.take_while(|msg| {
|
||||
let continue_stream = matches!(msg, Ok(_));
|
||||
let continue_stream = msg.is_ok();
|
||||
async move { continue_stream }.boxed()
|
||||
})
|
||||
.filter_map(|msg| async move {
|
||||
|
||||
Reference in New Issue
Block a user