mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-04 21:30:06 +08:00
* chore(clippy): scope crate lint policy Keep panic-on-error lints at application target roots and scope signal dependencies to Linux. * docs(agents): define Rust backend architecture boundaries Document which layer owns Rust capabilities, fallible inputs, background work, and crate validation. * refactor(draft): type async publication conflicts Return typed conflicts for async Draft edits. Release the lock and edit permit before converting the error, and exercise overlapping updates. * refactor(logging): use typed logger errors Expose crate-owned logger errors and preserve the underlying error sources. * refactor(subscription): extract response decoding Keep HTTP and persistence in the app. Decode response metadata and framing in the crate, and fall back when the server filename is invalid. * refactor(profile): extract profile models and index rules Move profile models and index rules into the crate, preserving serialization and returning a typed missing-profile error. * refactor(profile): separate subscription refresh and scheduling policy Separate download and scheduling policy from the subscription use case while retaining the existing write path. * refactor(subscription): decode deep links in the subscription crate * refactor(profile): extract selected node recovery rules * docs(agents): define dependencies between capability crates * refactor(task): move retry primitives into the task crate * refactor(backup): extract backup ZIP writing * refactor(subscription): keep profile writes outside proxy fallback * refactor(runtime-bundle): extract runtime bundle planning Plan provider destinations and assets in the crate. Adapt the plan to the Service wire format at the call site. * perf(runtime-bundle): share destination strings with tristr Share destination storage within bundle planning and preserve the Service wire strings and provider readback. * refactor(profile): extract script validation and execution Share the Boa validation and execution API while preserving the save-side timeout and diagnostics. * refactor(config): extract configuration renderer Render from inputs supplied by the app, reuse the script crate, and preserve the default template fast path. * refactor(proxy): extract proxy view and its use case Project the Mihomo snapshot into the existing IPC DTO and move use-case orchestration out of the command. * refactor(config): inject the profile script executor * refactor(config): centralize Mihomo YAML output * perf(runtime-bundle): read remote providers from borrowed configuration * chore(clippy): scope crate lint policy Keep panic-on-error lints at application target roots and scope signal dependencies to Linux. * docs(agents): define Rust backend architecture boundaries Document which layer owns Rust capabilities, fallible inputs, background work, and crate validation. * refactor(draft): type async publication conflicts Return typed conflicts for async Draft edits. Release the lock and edit permit before converting the error, and exercise overlapping updates. * refactor(logging): use typed logger errors Expose crate-owned logger errors and preserve the underlying error sources. * refactor(subscription): extract response decoding Keep HTTP and persistence in the app. Decode response metadata and framing in the crate, and fall back when the server filename is invalid. * refactor(profile): extract profile models and index rules Move profile models and index rules into the crate, preserving serialization and returning a typed missing-profile error. * refactor(profile): separate subscription refresh and scheduling policy Separate download and scheduling policy from the subscription use case while retaining the existing write path. * refactor(subscription): decode deep links in the subscription crate * refactor(profile): extract selected node recovery rules * docs(agents): define dependencies between capability crates * refactor(task): move retry primitives into the task crate * refactor(backup): extract backup ZIP writing * refactor(subscription): keep profile writes outside proxy fallback * fix(profile): preserve delays for future update timestamps * fix(subscription): preserve filenames from response headers and URL paths * fix(subscription): separate deep link parameters from nested URLs * refactor(profile): look up the refresh target once * refactor(subscription): pass the proxy directly to each download * refactor(profile): build companion options in one place * refactor(profile): remove companions from the deleted profile * style(profile): keep profile fields together * refactor(profile): name index operations after what they change * refactor(profile): call the core reload directly * refactor(backup): move archive validation to the restore change * refactor(config): name the runtime rendering step * refactor(config): remove the unused runtime patch API * refactor(config): accumulate profile keys and logs during rendering * refactor(config): load cached chain items directly * refactor(script): keep console state local to evaluation * refactor(proxy): read group order and scope in one pass * refactor(config): reuse sequence storage when applying profile edits * refactor(proxy): collect provider snapshots in display order * refactor(proxy): build the view from its input * refactor(runtime-bundle): share provider section order * fix(config): fill blank IPv6 fake IP ranges in TUN mode * fix(config): keep runtime field sorting stable * perf(config): reuse profile sequence storage during rendering * fix(script): check the evaluated profile entry point * fix(script): support runtime console methods during validation * perf(script): count integer digits without formatting JSON * perf(proxy): resolve unique members without building scope caches * fix(runtime-bundle): reject mixed owners of a provider path * perf(runtime-bundle): reuse the normalized destination buffer * fix(script): reject oversized names before escaping
171 lines
5.9 KiB
Rust
171 lines
5.9 KiB
Rust
mod groups;
|
|
|
|
use clash_verge_proxy_view::{
|
|
DelayHistory, ProviderSnapshot, ProxyCapabilities, ProxyProviderVehicleType, ProxySnapshot, ProxySubscriptionInfo,
|
|
ProxyViewInput, ProxyViewV1,
|
|
};
|
|
use serde_yaml_ng::Mapping;
|
|
use std::future::Future;
|
|
use tauri_plugin_mihomo::{
|
|
Result,
|
|
models::{Proxies, Proxy, ProxyProvider, ProxyProviders, ProxyType, VehicleType},
|
|
};
|
|
|
|
pub(crate) async fn load_proxy_view(
|
|
config: Option<&Mapping>,
|
|
proxies: impl Future<Output = Result<Proxies>>,
|
|
providers: impl Future<Output = Result<ProxyProviders>>,
|
|
) -> Result<ProxyViewV1> {
|
|
let (runtime_group_order, group_scopes) = groups::runtime_groups(config);
|
|
let (proxies, providers) = tokio::join!(proxies, providers);
|
|
let proxies = proxies?;
|
|
|
|
Ok(ProxyViewInput {
|
|
runtime_group_order,
|
|
group_scopes,
|
|
proxies: proxies
|
|
.proxies
|
|
.into_iter()
|
|
.map(|(name, proxy)| (name.into(), proxy_snapshot(proxy)))
|
|
.collect(),
|
|
providers: providers.ok().map(|providers| {
|
|
providers
|
|
.providers
|
|
.into_iter()
|
|
.filter_map(|(name, provider)| provider_snapshot(provider).map(|snapshot| (name.into(), snapshot)))
|
|
.collect()
|
|
}),
|
|
}
|
|
.into_view())
|
|
}
|
|
|
|
fn proxy_snapshot(proxy: Proxy) -> ProxySnapshot {
|
|
ProxySnapshot {
|
|
name: proxy.name.into(),
|
|
proxy_type: match proxy.proxy_type {
|
|
ProxyType::Unknown(value) => value.into(),
|
|
proxy_type => proxy_type.as_str().into(),
|
|
},
|
|
all: proxy.all.map(|all| all.into_iter().map(Into::into).collect()),
|
|
fixed: proxy.fixed.map(Into::into),
|
|
hidden: proxy.hidden,
|
|
icon: proxy.icon.map(Into::into),
|
|
now: proxy.now.map(Into::into),
|
|
test_url: proxy.test_url.map(Into::into),
|
|
id: proxy.id.map(Into::into),
|
|
history: proxy
|
|
.history
|
|
.into_iter()
|
|
.map(|entry| DelayHistory {
|
|
time: entry.time.into(),
|
|
delay: entry.delay,
|
|
})
|
|
.collect(),
|
|
capabilities: ProxyCapabilities {
|
|
udp: proxy.udp,
|
|
xudp: proxy.xudp,
|
|
tfo: proxy.tfo,
|
|
mptcp: proxy.mptcp,
|
|
smux: proxy.smux,
|
|
},
|
|
}
|
|
}
|
|
|
|
fn provider_snapshot(provider: ProxyProvider) -> Option<ProviderSnapshot> {
|
|
let vehicle_type = match provider.vehicle_type {
|
|
VehicleType::HTTP => ProxyProviderVehicleType::Http,
|
|
VehicleType::File => ProxyProviderVehicleType::File,
|
|
VehicleType::Inline => ProxyProviderVehicleType::Inline,
|
|
_ => return None,
|
|
};
|
|
|
|
Some(ProviderSnapshot {
|
|
vehicle_type,
|
|
proxies: provider.proxies.into_iter().map(proxy_snapshot).collect(),
|
|
updated_at: provider.updated_at.map(Into::into),
|
|
subscription_info: provider.subscription_info.map(|info| ProxySubscriptionInfo {
|
|
upload: info.upload,
|
|
download: info.download,
|
|
total: info.total,
|
|
expire: info.expire,
|
|
}),
|
|
})
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use clash_verge_proxy_view::{
|
|
ProxyMemberRef, ProxyMemberUnresolvedReason, ProxyNodeSource, ProxyViewProviderState,
|
|
};
|
|
use std::future::ready;
|
|
use tauri_plugin_mihomo::Error;
|
|
|
|
#[tokio::test]
|
|
async fn preserves_scoped_members_and_global_when_providers_are_unavailable() -> anyhow::Result<()> {
|
|
let config = serde_yaml_ng::from_str(
|
|
"proxy-providers: {z: {}, a: {}}\n\
|
|
proxy-groups:\n\
|
|
- {name: GLOBAL}\n\
|
|
- {name: Select, use: [a]}\n\
|
|
- {name: Another}\n\
|
|
- {name: Select, use: [a], include-all-providers: true, exclude-type: Direct}",
|
|
)?;
|
|
let proxies = r#"{"proxies":{
|
|
"GLOBAL":{"type":"Selector","all":["Select"]},
|
|
"Select":{"type":"Selector","all":["shared"]},
|
|
"Another":{"type":"Selector","all":[]}
|
|
}}"#;
|
|
let providers = serde_json::from_str(
|
|
r#"{"providers":{
|
|
"a":{"vehicleType":"HTTP","proxies":[{"name":"shared","type":"Direct"}]},
|
|
"z":{"vehicleType":"File","proxies":[{"name":"shared","type":"Shadowsocks"}]}
|
|
}}"#,
|
|
)?;
|
|
|
|
let available = load_proxy_view(
|
|
Some(&config),
|
|
ready(Ok(serde_json::from_str(proxies)?)),
|
|
ready(Ok(providers)),
|
|
)
|
|
.await?;
|
|
let unavailable = load_proxy_view(
|
|
Some(&config),
|
|
ready(Ok(serde_json::from_str(proxies)?)),
|
|
ready(Err(Error::FailedResponse("providers unavailable".into()))),
|
|
)
|
|
.await?;
|
|
|
|
for view in [&available, &unavailable] {
|
|
assert_eq!(
|
|
view.global.as_ref().map(|global| global.members.as_slice()),
|
|
Some([ProxyMemberRef::Group { name: "Select".into() }].as_slice())
|
|
);
|
|
assert_eq!(view.groups.len(), 2);
|
|
assert_eq!(view.groups[1].name.as_str(), "Another");
|
|
assert_eq!(view.groups[0].name.as_str(), "Select");
|
|
}
|
|
|
|
assert_eq!(available.provider_state, ProxyViewProviderState::Ready);
|
|
let [ProxyMemberRef::Node { record_id, .. }] = available.groups[0].members.as_slice() else {
|
|
anyhow::bail!("expected the scoped provider member");
|
|
};
|
|
assert_eq!(
|
|
available.records.get(record_id).map(|record| &record.source),
|
|
Some(&ProxyNodeSource::Provider {
|
|
provider_name: "z".into(),
|
|
proxy_name: "shared".into(),
|
|
})
|
|
);
|
|
assert_eq!(unavailable.provider_state, ProxyViewProviderState::Unavailable);
|
|
assert_eq!(
|
|
unavailable.groups[0].members,
|
|
[ProxyMemberRef::Unresolved {
|
|
name: "shared".into(),
|
|
reason: ProxyMemberUnresolvedReason::ProviderUnavailable,
|
|
}]
|
|
);
|
|
Ok(())
|
|
}
|
|
}
|