mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-02 21:12:13 +08:00
chore: bump dependencies
Bump tauri-plugin-mihomo to 0.5.0 and update frontend dependency locks. Adapt the traffic websocket stream parser to the new raw text byte callback API.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
use crate::{Type, core::handle, logging};
|
||||
use anyhow::Result;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use std::time::Duration;
|
||||
use tauri_plugin_mihomo::models::{ConnectionId, WebSocketMessage};
|
||||
use tauri_plugin_mihomo::models::ConnectionId;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::time::Instant;
|
||||
|
||||
@@ -33,7 +32,6 @@ pub enum StreamConsumeState<T> {
|
||||
|
||||
enum InternalWsEvent<T> {
|
||||
Data(T),
|
||||
Closed,
|
||||
}
|
||||
|
||||
/// Mihomo WebSocket 订阅句柄(通用事件流)。
|
||||
@@ -52,29 +50,12 @@ struct TrafficPayload {
|
||||
down: u64,
|
||||
}
|
||||
|
||||
fn parse_traffic_event(data: Value) -> Option<InternalWsEvent<TrafficSpeedEvent>> {
|
||||
if let Ok(payload) = serde_json::from_value::<TrafficPayload>(data.clone()) {
|
||||
return Some(InternalWsEvent::Data(TrafficSpeedEvent {
|
||||
up: payload.up,
|
||||
down: payload.down,
|
||||
}));
|
||||
}
|
||||
|
||||
if let Ok(ws_message) = WebSocketMessage::deserialize(&data) {
|
||||
match ws_message {
|
||||
WebSocketMessage::Text(text) => {
|
||||
let payload = serde_json::from_str::<TrafficPayload>(&text).ok()?;
|
||||
Some(InternalWsEvent::Data(TrafficSpeedEvent {
|
||||
up: payload.up,
|
||||
down: payload.down,
|
||||
}))
|
||||
}
|
||||
WebSocketMessage::Close(_) => Some(InternalWsEvent::Closed),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
fn parse_traffic_event(data: &[u8]) -> Option<InternalWsEvent<TrafficSpeedEvent>> {
|
||||
let payload = serde_json::from_slice::<TrafficPayload>(data).ok()?;
|
||||
Some(InternalWsEvent::Data(TrafficSpeedEvent {
|
||||
up: payload.up,
|
||||
down: payload.down,
|
||||
}))
|
||||
}
|
||||
|
||||
fn try_send_internal_event<T>(message_tx: &mpsc::Sender<InternalWsEvent<T>>, event: InternalWsEvent<T>) {
|
||||
@@ -98,7 +79,7 @@ pub async fn connect_traffic_stream() -> Result<MihomoWsEventStream<TrafficSpeed
|
||||
.ws_traffic({
|
||||
let message_tx = message_tx.clone();
|
||||
move |message| {
|
||||
if let Some(event) = parse_traffic_event(message) {
|
||||
if let Some(event) = parse_traffic_event(&message) {
|
||||
try_send_internal_event(&message_tx, event);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +125,7 @@ impl<T> MihomoWsEventStream<T> {
|
||||
sleep.as_mut().reset(self.last_valid_event_at + stale_timeout);
|
||||
return StreamConsumeState::Event(event);
|
||||
}
|
||||
Some(InternalWsEvent::Closed) | None => return StreamConsumeState::Closed,
|
||||
None => return StreamConsumeState::Closed,
|
||||
}
|
||||
}
|
||||
_ = &mut sleep => {
|
||||
|
||||
Reference in New Issue
Block a user