From 5bf14aed888cd0e258e325c65f14022dad02985b Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期四, 17 七月 2025 15:32:01 +0800
Subject: [PATCH] 更改为通过websocket获取数据

---
 src-tauri/src/lib.rs |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 193a629..8e0934c 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1,5 +1,9 @@
 mod tokio_utils;
 mod pipe_server;
+mod ws_client;
+use crate::ws_client::LATEST_WS_DATA;
+
+
 
 use std::sync::Mutex;
 use tauri::async_runtime::spawn;
@@ -9,6 +13,10 @@
 // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
 use crate::pipe_server::start_pipe_server;
 
+#[tauri::command]
+fn get_latest_ws_data() -> Option<String> {
+    LATEST_WS_DATA.lock().unwrap().clone()
+}
 #[tauri::command]
 fn greet(name: &str) -> String {
     format!("Hello, {}! You've been greeted from Rust!", name)
@@ -38,6 +46,8 @@
         .map_err(|e| e.to_string())
 }
 
+
+
 // #[cfg_attr(mobile, tauri::mobile_entry_point)]
 // pub fn run() {
 //     tauri::Builder::default()
@@ -60,10 +70,12 @@
             backend_task: false,
         }))
         // Add a command we can use to check
-        .invoke_handler(tauri::generate_handler![greet, set_complete, start_pipe_server_command, send_pipe_message])
+        .invoke_handler(tauri::generate_handler![greet, set_complete, start_pipe_server_command, send_pipe_message, get_latest_ws_data])
         // Use the setup hook to execute setup related tasks
         // Runs before the main loop, so no windows are yet created
         .setup(|app| {
+            // 鍚姩 WebSocket 瀹㈡埛绔紙寮傛浠诲姟锛�
+            ws_client::start_ws_client();
             // Spawn setup as a non-blocking task so the windows can be
             // created and ran while it executes
             spawn(setup(app.handle().clone()));

--
Gitblit v1.9.3