refactor: mihomo ipc (#7601)

* refactor: mihomo ipc request

* refactor: remove redundant write locks and await on mihomo handle

* fix(rule): handle non-string types in ProviderButton labels

* refactor: handle non-string value types in RuleItem component

* refactor(tauri): remove unnecessary await in get_base_config call

* chore: update tauri-plugin-mihomo deps

* refactor: rename ConnectionId to WsConnectionId

* chore: update tauri-plugin-mihomo-api dependency reference

* chore(config): use Proxy::default in profile test initialization
This commit is contained in:
oomeow
2026-07-28 15:16:01 +00:00
committed by GitHub
parent 3515c79e2b
commit b71a1e4ec5
24 changed files with 68 additions and 134 deletions
+3 -5
View File
@@ -2,7 +2,7 @@ use crate::{Type, core::handle, logging};
use anyhow::Result;
use serde::Deserialize;
use std::time::Duration;
use tauri_plugin_mihomo::models::ConnectionId;
use tauri_plugin_mihomo::models::WsConnectionId;
use tokio::sync::mpsc;
use tokio::time::Instant;
@@ -37,7 +37,7 @@ enum InternalWsEvent<T> {
/// Mihomo WebSocket 订阅句柄(通用事件流)。
pub struct MihomoWsEventStream<T> {
/// 当前订阅连接 ID,用于主动断开。
pub connection_id: ConnectionId,
pub connection_id: WsConnectionId,
/// 当前订阅消息接收器。
receiver: mpsc::Receiver<InternalWsEvent<T>>,
/// 最近一次收到有效事件的时间戳。
@@ -75,7 +75,6 @@ pub async fn connect_traffic_stream() -> Result<MihomoWsEventStream<TrafficSpeed
let (message_tx, message_rx) = mpsc::channel::<InternalWsEvent<TrafficSpeedEvent>>(MIHOMO_WS_STREAM_BUFFER_SIZE);
// 建立 Mihomo `/traffic` WebSocket 订阅。
let connection_id = handle::Handle::mihomo()
.await
.ws_traffic({
let message_tx = message_tx.clone();
move |message| {
@@ -143,9 +142,8 @@ impl<T> MihomoWsEventStream<T> {
///
/// # Arguments
/// * `connection_id` - 目标连接 ID
pub async fn disconnect_connection(connection_id: ConnectionId) {
pub async fn disconnect_connection(connection_id: WsConnectionId) {
if let Err(err) = handle::Handle::mihomo()
.await
.disconnect(connection_id, Some(MIHOMO_WS_STREAM_CLOSE_CODE))
.await
{
+1 -1
View File
@@ -185,7 +185,7 @@ pub fn on_web_content_process_terminated(webview: &tauri::Webview) {
// reload 必须与清理同任务、排在其后,否则清理可能误清重载后新页面的订阅(竞态)。
let webview = webview.clone();
crate::process::AsyncHandler::spawn(move || async move {
if let Err(err) = handle::Handle::mihomo().await.clear_all_ws_connections().await {
if let Err(err) = handle::Handle::mihomo().clear_all_ws_connections().await {
logging!(warn, Type::Window, "清理 Mihomo WebSocket 连接失败: {err}");
} else {
logging!(info, Type::Window, "已清理全部 Mihomo WebSocket 连接");