每次连接成功都获取BootLoader.exe的版本号
This commit is contained in:
@@ -188,16 +188,45 @@ async fn run_updater(debug_mode: bool) {
|
||||
// 设置重连回调 - 在每次重连前重新加载配置
|
||||
let debug_for_reconnect = debug_mode;
|
||||
client.on_reconnecting(move |attempt, url_arc| {
|
||||
Box::pin(async move {
|
||||
if debug_for_reconnect {
|
||||
println!("[重连] 第 {} 次重连中...", attempt);
|
||||
}
|
||||
// 重新读取配置文件并更新 URL
|
||||
let new_url = resolve_ws_url();
|
||||
// 更新 CubeLib 内部的 URL
|
||||
*url_arc.blocking_lock() = new_url.clone();
|
||||
// 更新 CubeLib 内部的 URL (使用 .lock().await)
|
||||
*url_arc.lock().await = new_url.clone();
|
||||
if debug_for_reconnect {
|
||||
println!("[配置] 已重新加载,服务器地址: {}", new_url);
|
||||
}
|
||||
}) as Pin<Box<dyn std::future::Future<Output = ()> + 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<Box<dyn std::future::Future<Output = ()> + Send + Sync>>
|
||||
});
|
||||
|
||||
// 连接(CubeLib 会自动处理重连)
|
||||
|
||||
Reference in New Issue
Block a user