From 9d76d8bba4018136586e0efc52c6fd777060ea5a Mon Sep 17 00:00:00 2001 From: zqm Date: Tue, 7 Apr 2026 16:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E8=BF=9E=E6=8E=A5=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E9=83=BD=E8=8E=B7=E5=8F=96BootLoader.exe=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Windows/CS/Framework4.0/Updater/src/main.rs | 49 ++++++++++++++++----- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/Windows/CS/Framework4.0/Updater/src/main.rs b/Windows/CS/Framework4.0/Updater/src/main.rs index 69d7a45..f728d08 100644 --- a/Windows/CS/Framework4.0/Updater/src/main.rs +++ b/Windows/CS/Framework4.0/Updater/src/main.rs @@ -188,16 +188,45 @@ async fn run_updater(debug_mode: bool) { // 设置重连回调 - 在每次重连前重新加载配置 let debug_for_reconnect = debug_mode; client.on_reconnecting(move |attempt, url_arc| { - if debug_for_reconnect { - println!("[重连] 第 {} 次重连中...", attempt); - } - // 重新读取配置文件并更新 URL - let new_url = resolve_ws_url(); - // 更新 CubeLib 内部的 URL - *url_arc.blocking_lock() = new_url.clone(); - if debug_for_reconnect { - println!("[配置] 已重新加载,服务器地址: {}", new_url); - } + Box::pin(async move { + if debug_for_reconnect { + println!("[重连] 第 {} 次重连中...", attempt); + } + // 重新读取配置文件并更新 URL + let new_url = resolve_ws_url(); + // 更新 CubeLib 内部的 URL (使用 .lock().await) + *url_arc.lock().await = new_url.clone(); + if debug_for_reconnect { + println!("[配置] 已重新加载,服务器地址: {}", new_url); + } + }) as Pin + Send + Sync>> + }); + + // 设置重连成功回调 - 每次重连成功后也发送 GetFileVer + let debug_for_reconnected = debug_mode; + client.on_reconnected(move |_url, sender| { + Box::pin(async move { + if debug_for_reconnected { + println!("[重连成功] 发送 GetFileVer 命令..."); + } + // 构造 GetFileVer 消息 + let msg = serde_json::json!({ + "Type": "GetFileVer", + "Data": { + "file": "BootLoader.exe" + } + }); + let msg_str = msg.to_string(); + + // 通过 sender 发送消息 + let sender_guard = sender.lock().await; + if let Some(ref tx) = *sender_guard { + let _ = tx.try_send(cube_lib::websocket::OutgoingMessage::Text(msg_str)); + } + if debug_for_reconnected { + println!("[重连成功] GetFileVer 已发送"); + } + }) as Pin + Send + Sync>> }); // 连接(CubeLib 会自动处理重连)