refactor(ipc): remove unused proxy liveness payloads

This commit is contained in:
Tunglies
2026-10-12 02:34:06 +08:00
parent bb55742d18
commit ad52f5e79b
6 changed files with 36 additions and 35 deletions
+27 -9
View File
@@ -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<crate::ipc::DelayHistory>)]
history: &'a [DelayHistory],
}
fn serialize_proxy_latency_history<S: Serializer>(
extra: &HashMap<String, Extra>,
serializer: S,
) -> Result<S::Ok, S::Error> {
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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -77,7 +98,8 @@ pub struct ProxyGroupView {
pub test_url: Option<String>,
#[specta(type = Vec<crate::ipc::DelayHistory>)]
pub history: Vec<DelayHistory>,
#[specta(type = HashMap<String, crate::ipc::ProxyExtra>)]
#[serde(serialize_with = "serialize_proxy_latency_history")]
#[specta(type = HashMap<String, ProxyLatencyHistory<'static>>)]
pub extra: HashMap<String, Extra>,
#[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<crate::ipc::DelayHistory>)]
pub history: Vec<DelayHistory>,
#[specta(type = HashMap<String, crate::ipc::ProxyExtra>)]
#[serde(serialize_with = "serialize_proxy_latency_history")]
#[specta(type = HashMap<String, ProxyLatencyHistory<'static>>)]
pub extra: HashMap<String, Extra>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
@@ -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,
-6
View File
@@ -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<DelayHistory>,
}
fn platform_types() -> specta::Types {
use specta::datatype::{DataType, Fields};
let mut types = specta::Types::default().register::<crate::config::IVerge>();
@@ -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 }],
},
},
-1
View File
@@ -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,
+8 -13
View File
@@ -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
+1 -5
View File
@@ -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)