refactor: api cleanup (#7812)

* refactor(config): unify YAML persistence

* refactor(config): remove redundant config APIs

* refactor(config): remove unused config APIs

* refactor(config): narrow profile APIs

* fix(config): preserve profiles on invalid reorder

* refactor(startup): narrow resolve helpers

* refactor(config): unify mixed port defaults

* refactor(network): simplify response APIs

* refactor(config): make profile builders infallible

* refactor(config): make profile activation infallible

* refactor(api): simplify internal runtime APIs

* refactor: consolidate internal config and window APIs
This commit is contained in:
Tunglies
2026-08-25 07:19:17 +00:00
committed by GitHub
parent 272c09568c
commit b7c4f7d39b
29 changed files with 277 additions and 413 deletions
+3 -3
View File
@@ -185,13 +185,13 @@ async fn resolve_latest_version(alpha: bool) -> Result<(ProxyType, std::string::
for proxy in [ProxyType::Localhost, ProxyType::System, ProxyType::None] {
let attempt = NetworkManager::new()
.get_with_interrupt(&url, proxy, Some(VERSION_TIMEOUT_SECS), None, false)
.get(&url, proxy, Some(VERSION_TIMEOUT_SECS), None, false)
.await;
match attempt {
Ok(response) if response.status().is_success() => {
// An error page answered with 200 must not become a version, nor reach the URL.
let version = response.text_with_charset()?.trim().to_owned();
let version = response.text().trim().to_owned();
if !is_usable_version(&version) {
last_error = Some(anyhow!("{url} returned an unusable version"));
continue;
@@ -220,7 +220,7 @@ async fn download_package(proxy: ProxyType, alpha: bool, version: &str) -> Resul
logging!(info, Type::Core, "core upgrade: downloading {url}");
NetworkManager::new()
.get_bytes_with_interrupt(&url, proxy, Some(PACKAGE_TIMEOUT_SECS), MAX_PACKAGE_BYTES)
.get_bytes(&url, proxy, Some(PACKAGE_TIMEOUT_SECS), MAX_PACKAGE_BYTES)
.await
.with_context(|| format!("failed to download {url}"))
}
+8 -7
View File
@@ -1,6 +1,6 @@
use crate::{
cmd,
config::{Config, PrfItem, PrfOption, profiles::profiles_draft_update_item_safe},
config::{Config, PrfItem, PrfOption, profiles::profiles_update_item_safe},
core::{CoreManager, handle, tray, validate::ValidationOutcome},
utils::help::{mask_err, mask_url},
};
@@ -124,13 +124,14 @@ async fn perform_profile_update(
let mut merged_opt = PrfOption::merge(opt, option);
let is_current = {
let profiles = Config::profiles().await;
profiles.latest_arc().is_current_profile_index(uid)
profiles.latest_arc().current.as_ref() == Some(uid)
};
let profiles = Config::profiles().await;
let profiles_arc = profiles.latest_arc();
let profile_name = profiles_arc
.get_name_by_uid(uid)
.cloned()
.get_item(uid)
.ok()
.and_then(|item| item.name.clone())
.unwrap_or_else(|| String::from("UnKnown Profile"));
let mut last_err;
@@ -138,7 +139,7 @@ async fn perform_profile_update(
match PrfItem::from_url(url, None, None, merged_opt.as_ref()).await {
Ok(mut item) => {
logging!(info, Type::Config, "[订阅更新] 更新订阅配置成功");
profiles_draft_update_item_safe(uid, &mut item).await?;
profiles_update_item_safe(uid, &mut item).await?;
return Ok(is_current);
}
Err(err) => {
@@ -158,7 +159,7 @@ async fn perform_profile_update(
match PrfItem::from_url(url, None, None, merged_opt.as_ref()).await {
Ok(mut item) => {
logging!(info, Type::Config, "[订阅更新] 使用 Clash代理 更新订阅配置成功");
profiles_draft_update_item_safe(uid, &mut item).await?;
profiles_update_item_safe(uid, &mut item).await?;
handle::Handle::notice_message("update_with_clash_proxy", profile_name);
drop(last_err);
return Ok(is_current);
@@ -180,7 +181,7 @@ async fn perform_profile_update(
match PrfItem::from_url(url, None, None, merged_opt.as_ref()).await {
Ok(mut item) => {
logging!(info, Type::Config, "[订阅更新] 使用 系统代理 更新订阅配置成功");
profiles_draft_update_item_safe(uid, &mut item).await?;
profiles_update_item_safe(uid, &mut item).await?;
handle::Handle::notice_message("update_with_clash_proxy", profile_name);
drop(last_err);
return Ok(is_current);