发送 GetFileVer 命令..
This commit is contained in:
@@ -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<Box<dyn std::future::Future<Output = ()> + Send + Sync>>
|
||||
});
|
||||
|
||||
// 设置重连回调 - 在每次重连前重新加载配置
|
||||
let debug_for_reconnect = debug_mode;
|
||||
client.on_reconnecting(move |attempt, url_arc| {
|
||||
|
||||
Reference in New Issue
Block a user