Skip to content

Commit a24ef73

Browse files
author
richardson
committed
重构WebSocket通信和舵机控制
- 删除了socket_communication.rs和phoneCommunication.ts - 新增webSocketService.ts以统一管理WebSocket通信 - 更新了servoControl.ts以适应新的通信方式 - 修改了DebugPanel、InteractionInterface和SettingsPanel组件以使用新的WebSocket服务 - 在main.rs和commands.rs中更新了相关功能 - 新增了websocket.ts类型定义文件 - 添加了GitHub Actions工作流用于自动构建和发布
1 parent 147c7b2 commit a24ef73

11 files changed

+335
-319
lines changed

src-tauri/src/commands.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::sync::Arc;
22
use serde::Serialize;
3-
use crate::socket_communication::SocketCommunication;
43
use crate::device_manager::DeviceManager;
54

65

@@ -13,7 +12,6 @@ pub struct CameraInfoDto {
1312

1413
// 定义允许跨线程访问的状态结构
1514
pub struct AppState {
16-
pub socket_communication: Arc<SocketCommunication>,
1715
pub device_manager: Arc<DeviceManager>,
1816
}
1917

@@ -39,17 +37,6 @@ pub async fn check_device_status(
3937
state.device_manager.check_device_status(device_name)
4038
}
4139

42-
#[tauri::command]
43-
pub async fn send_to_mobile_phone(
44-
state: tauri::State<'_, AppState>,
45-
ip_address: String,
46-
port: u16,
47-
kaomoji: String,
48-
audio_buffer: Vec<u8>,
49-
) -> Result<(), String> {
50-
state.socket_communication.send_to_mobile_phone(ip_address, port, kaomoji, audio_buffer)
51-
}
52-
5340
// 原有的其他命令保持不变
5441
#[tauri::command]
5542
pub fn greet(name: &str) -> String {

src-tauri/src/main.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@
44
)]
55

66
mod commands;
7-
mod socket_communication;
87
mod device_manager;
98
mod servo_controller;
109
mod logger;
1110

1211
use crate::logger::setup_logging;
13-
use crate::socket_communication::SocketCommunication;
1412
use crate::device_manager::DeviceManager;
15-
use std::sync::{Arc, Mutex};
13+
use std::sync::Arc;
1614
use tauri::Manager;
1715

1816
#[tokio::main]
1917
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2018
// 创建线程安全的组件实例
21-
let socket_communication = Arc::new(SocketCommunication::new());
2219
let device_manager = Arc::new(DeviceManager::new());
2320
// 创建应用状态
2421
let app_state = commands::AppState {
25-
socket_communication: socket_communication.clone(),
2622
device_manager: device_manager.clone(),
2723
};
2824

@@ -40,7 +36,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4036
.invoke_handler(tauri::generate_handler![
4137
commands::set_servo_position,
4238
commands::check_device_status,
43-
commands::send_to_mobile_phone,
4439
commands::greet,
4540
commands::log_message,
4641
commands::get_logs,

src-tauri/src/socket_communication.rs

-113
This file was deleted.

src/components/DebugPanel.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export const DebugPanel: React.FC<DebugPanelProps> = ({ onServoControl, servoCon
129129
<TabsContent value="servo" className="space-y-4">
130130
<div>
131131
<p>Device Name: {servoConfig.deviceName}</p>
132-
<p>IP Address: {servoConfig.ipAddress}</p>
133132
</div>
134133
<div className="grid grid-cols-4 items-center gap-4">
135134
<Button onClick={() => handleServoControl('X', 0)}>Left</Button>

0 commit comments

Comments
 (0)