- tauri 设计完成

This commit is contained in:
Pine
2026-05-12 23:19:37 +08:00
parent c8e8dd12d2
commit 4ad266f6c4
25 changed files with 3495 additions and 3039 deletions
+29
View File
@@ -0,0 +1,29 @@
use crate::models::ServerEvent;
use once_cell::sync::Lazy;
use tokio::sync::broadcast;
/// SSE 事件管理器
pub struct EventManager {
tx: broadcast::Sender<String>,
}
impl EventManager {
pub fn new() -> Self {
let (tx, _) = broadcast::channel(64);
Self { tx }
}
/// 广播事件给所有 SSE 客户端
pub fn broadcast(&self, event: &ServerEvent) {
if let Ok(json) = serde_json::to_string(event) {
let _ = self.tx.send(json);
}
}
/// 获取广播接收器
pub fn subscribe(&self) -> broadcast::Receiver<String> {
self.tx.subscribe()
}
}
pub static EVENTS: Lazy<EventManager> = Lazy::new(EventManager::new);