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.
This commit is contained in:
Tunglies
2026-11-30 18:44:12 +08:00
parent b1281d78fe
commit e31c01894a
19 changed files with 1017 additions and 856 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
use crate::{
config::{Config, IClashTemp, IProfiles, IVerge},
config::{Config, IClashTemp, IVerge, profiles::load_profiles},
core::{CoreManager, auto_backup, backup, proxy_control, proxy_control::SystemProxyStateUnknown},
process::AsyncHandler,
utils::{
@@ -46,7 +46,7 @@ async fn finalize_restored_verge_config(
});
clash_draft.apply();
let restored_profiles = IProfiles::new().await;
let restored_profiles = load_profiles().await;
let profiles_draft = Config::profiles().await;
profiles_draft.edit_draft(|d| {
*d = restored_profiles;
+2 -2
View File
@@ -8,7 +8,7 @@ use crate::{
config::{
Config,
dns::{ProfileDnsSettings, dns_override_source},
profiles::PROFILE_WRITE_LOCK,
profiles::{PROFILE_WRITE_LOCK, current_mapping},
},
constants::files::DNS_CONFIG,
core::CoreManager,
@@ -36,7 +36,7 @@ pub async fn set_dns_override(
);
let source = dns_override_source(
profiles.current.as_deref().unwrap_or_default(),
&profiles.current_mapping().await?,
&current_mapping(&profiles).await?,
)?;
if enabled && let Some(source) = source.as_ref().filter(|source| Some(*source) != confirmation.as_ref()) {
return Ok(DnsOverrideOutcome::ConfirmationRequired { source: source.clone() });
+2 -2
View File
@@ -2,7 +2,7 @@ use crate::core::notify::NoticeStatus;
use crate::core::notify::{Refresh, announce};
use crate::{
cmd,
config::{Config, PrfItem, PrfOption, profiles::profiles_update_item_safe},
config::{Config, PrfOption, fetch_remote_profile, profiles::profiles_update_item_safe},
core::{CoreManager, handle, tray, validate::ValidationOutcome},
process::AsyncHandler,
utils::help::{mask_err, mask_url},
@@ -289,7 +289,7 @@ async fn perform_profile_update(
}
tracing::Span::current().record("strategy", name);
let started = std::time::Instant::now();
let result = PrfItem::from_url(url, None, None, options.as_ref()).await;
let result = fetch_remote_profile(url, None, None, options.as_ref()).await;
let elapsed_field = match strategy {
Strategy::Configured => "configured_elapsed",
Strategy::Clash => "clash_elapsed",