feat: add retry mechanism to optimize network requests, improve async message handling and timeout for scheduled tasks

This commit is contained in:
wonfen
2025-05-03 09:38:25 +08:00
parent e7bf997f8c
commit 73b9a71c84
4 changed files with 102 additions and 39 deletions

View File

@@ -108,14 +108,29 @@ impl Handle {
return;
}
// 已经完成启动,直接发送消息
if let Some(window) = handle.get_window() {
logging_error!(
Type::Frontend,
true,
window.emit("verge://notice-message", (status_str, msg_str))
);
}
// 使用AsyncHandler发送消息防止阻塞
let status_clone = status_str.clone();
let msg_clone = msg_str.clone();
crate::process::AsyncHandler::spawn(move || async move {
let handle_clone = Self::global();
if let Some(window) = handle_clone.get_window() {
match tokio::time::timeout(tokio::time::Duration::from_millis(500), async {
window.emit("verge://notice-message", (status_clone, msg_clone))
})
.await
{
Ok(result) => {
if let Err(e) = result {
logging!(warn, Type::Frontend, true, "发送通知消息失败: {}", e);
}
}
Err(_) => {
logging!(warn, Type::Frontend, true, "发送通知消息超时");
}
}
}
});
}
/// 标记启动已完成,并发送所有启动阶段累积的错误消息
@@ -158,7 +173,6 @@ impl Handle {
for error in errors_clone {
let _ =
window_clone.emit("verge://notice-message", (error.status, error.message));
// 每条消息之间间隔500ms避免消息堆积
tokio::time::sleep(Duration::from_millis(500)).await;
}
});