diff --git a/Windows/CS/Framework4.0/Updater/src/main.rs b/Windows/CS/Framework4.0/Updater/src/main.rs index 1a2e687..69d7a45 100644 --- a/Windows/CS/Framework4.0/Updater/src/main.rs +++ b/Windows/CS/Framework4.0/Updater/src/main.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; use std::fs; use std::path::PathBuf; +use std::pin::Pin; use std::process::Command; use cube_lib::websocket::{WebSocketClient, WebSocketConfig}; @@ -157,6 +158,33 @@ async fn run_updater(debug_mode: bool) { eprintln!("[错误] WebSocket: {}", error); }); + // 设置首次连接回调 - 发送 GetFileVer 命令 + let debug_for_first = debug_mode; + client.on_first_connect(move |_url, sender| { + Box::pin(async move { + if debug_for_first { + println!("[首次连接] 发送 GetFileVer 命令..."); + } + // 构造 GetFileVer 消息 + let msg = serde_json::json!({ + "Type": "GetFileVer", + "Data": { + "file": "BootLoader.exe" + } + }); + let msg_str = msg.to_string(); + + // 通过 sender 发送消息 (使用 .lock().await) + 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_first { + println!("[首次连接] GetFileVer 已发送"); + } + }) as Pin + Send + Sync>> + }); + // 设置重连回调 - 在每次重连前重新加载配置 let debug_for_reconnect = debug_mode; client.on_reconnecting(move |attempt, url_arc| {