From ad52f5e79b43f790852cf6d3766af58f8f98a818 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Mon, 12 Oct 2026 02:34:06 +0800 Subject: [PATCH] refactor(ipc): remove unused proxy liveness payloads --- src-tauri/src/core/proxy_view.rs | 36 +++++++++++++++----- src-tauri/src/ipc.rs | 6 ---- src/components/proxy/use-filter-sort.test.ts | 1 - src/components/proxy/use-render-list.ts | 1 - src/services/bindings.ts | 21 +++++------- src/services/delay.test.ts | 6 +--- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src-tauri/src/core/proxy_view.rs b/src-tauri/src/core/proxy_view.rs index a78729187..54d488fc0 100644 --- a/src-tauri/src/core/proxy_view.rs +++ b/src-tauri/src/core/proxy_view.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; -use serde::Serialize; +use serde::{Serialize, Serializer, ser::SerializeMap as _}; use tauri_plugin_mihomo::models::{ DelayHistory, Extra, Proxies, Proxy, ProxyProvider, ProxyProviders, ProxyType, VehicleType, }; @@ -57,6 +57,28 @@ pub struct ProxyCapabilities { pub smux: bool, } +#[derive(Serialize, specta::Type)] +struct ProxyLatencyHistory<'a> { + #[specta(type = Vec)] + history: &'a [DelayHistory], +} + +fn serialize_proxy_latency_history( + extra: &HashMap, + serializer: S, +) -> Result { + let mut map = serializer.serialize_map(Some(extra.len()))?; + for (url, extra) in extra { + map.serialize_entry( + url, + &ProxyLatencyHistory { + history: &extra.history, + }, + )?; + } + map.end() +} + #[derive(Debug, PartialEq, Eq, Serialize, specta::Type)] #[serde(rename_all = "camelCase")] pub struct ProxyGroupView { @@ -64,7 +86,6 @@ pub struct ProxyGroupView { #[serde(rename = "type")] #[specta(type = String)] pub proxy_type: ProxyType, - pub alive: bool, #[serde(skip_serializing_if = "Option::is_none")] pub now: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -77,7 +98,8 @@ pub struct ProxyGroupView { pub test_url: Option, #[specta(type = Vec)] pub history: Vec, - #[specta(type = HashMap)] + #[serde(serialize_with = "serialize_proxy_latency_history")] + #[specta(type = HashMap>)] pub extra: HashMap, #[serde(flatten)] pub capabilities: ProxyCapabilities, @@ -92,10 +114,10 @@ pub struct ProxyNodeView { #[serde(rename = "type")] #[specta(type = String)] pub proxy_type: ProxyType, - pub alive: bool, #[specta(type = Vec)] pub history: Vec, - #[specta(type = HashMap)] + #[serde(serialize_with = "serialize_proxy_latency_history")] + #[specta(type = HashMap>)] pub extra: HashMap, #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, @@ -408,7 +430,6 @@ fn build_group(name: String, proxy: Proxy, resolver: &MemberResolver<'_>) -> Pro icon, now, test_url, - alive, history, extra, udp, @@ -437,7 +458,6 @@ fn build_group(name: String, proxy: Proxy, resolver: &MemberResolver<'_>) -> Pro ProxyGroupView { name, proxy_type, - alive, now, fixed, hidden, @@ -462,7 +482,6 @@ fn build_node(record_id: String, name: String, proxy: Proxy, source: ProxyNodeSo hidden, icon, test_url, - alive, history, extra, udp, @@ -478,7 +497,6 @@ fn build_node(record_id: String, name: String, proxy: Proxy, source: ProxyNodeSo record_id, name, proxy_type, - alive, history, extra, id, diff --git a/src-tauri/src/ipc.rs b/src-tauri/src/ipc.rs index 6b2a82e90..334ef1ccb 100644 --- a/src-tauri/src/ipc.rs +++ b/src-tauri/src/ipc.rs @@ -172,12 +172,6 @@ pub struct DelayHistory { pub delay: u16, } -#[derive(serde::Serialize, serde::Deserialize, specta::Type)] -pub struct ProxyExtra { - pub alive: bool, - pub history: Vec, -} - fn platform_types() -> specta::Types { use specta::datatype::{DataType, Fields}; let mut types = specta::Types::default().register::(); diff --git a/src/components/proxy/use-filter-sort.test.ts b/src/components/proxy/use-filter-sort.test.ts index 08730cd5e..dd5effc33 100644 --- a/src/components/proxy/use-filter-sort.test.ts +++ b/src/components/proxy/use-filter-sort.test.ts @@ -17,7 +17,6 @@ const node = (memberIndex: number, delay: number, name = `${memberIndex}`) => history: [{ delay }], extra: { 'http://cp.cloudflare.com/generate_204': { - alive: true, history: [{ time: new Date(0).toISOString(), delay }], }, }, diff --git a/src/components/proxy/use-render-list.ts b/src/components/proxy/use-render-list.ts index faa3e230e..826331bde 100644 --- a/src/components/proxy/use-render-list.ts +++ b/src/components/proxy/use-render-list.ts @@ -110,7 +110,6 @@ const CHAIN_DELAY_GROUP = 'chain-mode' const virtualGroup = (members: ProxyGroupView['members']): ProxyGroupView => ({ name: CHAIN_DELAY_GROUP, type: 'Selector', - alive: true, udp: false, xudp: false, tfo: false, diff --git a/src/services/bindings.ts b/src/services/bindings.ts index 970875fe4..73e886a69 100644 --- a/src/services/bindings.ts +++ b/src/services/bindings.ts @@ -805,11 +805,6 @@ export type ProxyCapabilities = { smux: boolean } -export type ProxyExtra = { - alive: boolean - history: DelayHistory[] -} - export type ProxyGroupView = | ProxyGroupView_Serialize | ProxyGroupView_Deserialize @@ -817,31 +812,33 @@ export type ProxyGroupView = export type ProxyGroupView_Deserialize = { name: string type: string - alive: boolean now: string | null fixed: string | null hidden: boolean | null icon: string | null testUrl: string | null history: DelayHistory[] - extra: { [key in string]: ProxyExtra } + extra: { [key in string]: ProxyLatencyHistory } members: ProxyMemberRef[] } & ProxyCapabilities export type ProxyGroupView_Serialize = { name: string type: string - alive: boolean now?: string | null fixed?: string | null hidden?: boolean | null icon?: string | null testUrl?: string | null history: DelayHistory[] - extra: { [key in string]: ProxyExtra } + extra: { [key in string]: ProxyLatencyHistory } members: ProxyMemberRef[] } & ProxyCapabilities +export type ProxyLatencyHistory = { + history: DelayHistory[] +} + export type ProxyMemberRef = | { kind: 'group'; name: string } | { kind: 'node'; name: string; recordId: string } @@ -862,9 +859,8 @@ export type ProxyNodeView_Deserialize = { recordId: string name: string type: string - alive: boolean history: DelayHistory[] - extra: { [key in string]: ProxyExtra } + extra: { [key in string]: ProxyLatencyHistory } id: string | null hidden: boolean | null icon: string | null @@ -876,9 +872,8 @@ export type ProxyNodeView_Serialize = { recordId: string name: string type: string - alive: boolean history: DelayHistory[] - extra: { [key in string]: ProxyExtra } + extra: { [key in string]: ProxyLatencyHistory } id?: string | null hidden?: boolean | null icon?: string | null diff --git a/src/services/delay.test.ts b/src/services/delay.test.ts index 5f6a51afe..a26d25dde 100644 --- a/src/services/delay.test.ts +++ b/src/services/delay.test.ts @@ -66,7 +66,6 @@ test('uses newer core history after a tray test without hiding an active page te const cached = delayManager.setDelay(member, 'tray-group', 50) member.node.extra = { [delayManager.getUrl('tray-group')]: { - alive: true, history: [ { time: new Date(cached.updatedAt + 1000).toISOString(), delay: 300 }, ], @@ -107,13 +106,11 @@ test('another URL cannot replace a group measurement, but a newer matching URL c history: [{ time: newer, delay: 126 }], extra: { 'http://localhost/a': { - alive: true, history: [ { time: new Date(cached.updatedAt - 1000).toISOString(), delay: 49 }, ], }, 'http://localhost/b': { - alive: true, history: [{ time: newer, delay: 126 }], }, }, @@ -122,7 +119,6 @@ test('another URL cannot replace a group measurement, but a newer matching URL c Object.assign(member.node, { extra: { 'http://localhost/a': { - alive: true, history: [{ time: newer, delay: 75 }], }, }, @@ -190,7 +186,7 @@ test('unmeasured selectors show automatic history without replacing a manual URL { time: new Date(Date.now() + 1000).toISOString(), delay: 126 }, ] member.node.extra = { - 'http://localhost/automatic': { alive: true, history: member.node.history }, + 'http://localhost/automatic': { history: member.node.history }, } expect(delayManager.getDelayFix(member, 'selector')).toBe(126) delayManager.setDelay(member, 'selector', 50)