mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
refactor(profile): borrow profile identifiers from the render snapshot
This commit is contained in:
@@ -80,7 +80,7 @@ pub(crate) async fn load_profiles() -> IProfiles {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn load_profiles_checked() -> Result<IProfiles> {
|
||||
async fn load_profiles_checked() -> Result<IProfiles> {
|
||||
profile_storage::check()?;
|
||||
load_profiles_unlocked().await
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ async fn get_config_values(profile_uid: &str) -> ConfigValues {
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
async fn collect_profile_items(profiles: &IProfiles) -> Result<RenderProfile> {
|
||||
let current_profile_uid = match profiles.current.clone() {
|
||||
let current_profile_uid = match profiles.current.as_deref() {
|
||||
Some(uid) => uid,
|
||||
None => return Ok(default_profile()),
|
||||
};
|
||||
@@ -141,27 +141,18 @@ async fn collect_profile_items(profiles: &IProfiles) -> Result<RenderProfile> {
|
||||
.await
|
||||
.with_context(|| format!("failed to read current profile \"{current_profile_uid}\""))?;
|
||||
|
||||
let current_item = match profiles.get_item(¤t_profile_uid) {
|
||||
let current_item = match profiles.get_item(current_profile_uid) {
|
||||
Ok(item) => item,
|
||||
Err(err) => {
|
||||
return Err(err).with_context(|| format!("failed to get current profile \"{current_profile_uid}\""));
|
||||
}
|
||||
};
|
||||
|
||||
let merge_uid = current_item.current_merge().cloned().unwrap_or_else(|| "Merge".into());
|
||||
let script_uid = current_item
|
||||
.current_script()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "Script".into());
|
||||
let rules_uid = current_item.current_rules().cloned().unwrap_or_else(|| "Rules".into());
|
||||
let proxies_uid = current_item
|
||||
.current_proxies()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "Proxies".into());
|
||||
let groups_uid = current_item
|
||||
.current_groups()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "Groups".into());
|
||||
let merge_uid = current_item.current_merge().map_or("Merge", String::as_str);
|
||||
let script_uid = current_item.current_script().map_or("Script", String::as_str);
|
||||
let rules_uid = current_item.current_rules().map_or("Rules", String::as_str);
|
||||
let proxies_uid = current_item.current_proxies().map_or("Proxies", String::as_str);
|
||||
let groups_uid = current_item.current_groups().map_or("Groups", String::as_str);
|
||||
|
||||
let name = current_item.name.clone().unwrap_or_default();
|
||||
|
||||
@@ -177,11 +168,11 @@ async fn collect_profile_items(profiles: &IProfiles) -> Result<RenderProfile> {
|
||||
} = default_profile();
|
||||
|
||||
let (merge_item, script_item, rules_item, proxies_item, groups_item, global_merge, global_script) = tokio::join!(
|
||||
chain_item_or_default(profiles.get_item(&merge_uid).ok(), || default_merge,),
|
||||
chain_item_or_default(profiles.get_item(&script_uid).ok(), || default_script,),
|
||||
chain_item_or_default(profiles.get_item(&rules_uid).ok(), || default_rules,),
|
||||
chain_item_or_default(profiles.get_item(&proxies_uid).ok(), || default_proxies,),
|
||||
chain_item_or_default(profiles.get_item(&groups_uid).ok(), || default_groups,),
|
||||
chain_item_or_default(profiles.get_item(merge_uid).ok(), || default_merge,),
|
||||
chain_item_or_default(profiles.get_item(script_uid).ok(), || default_script,),
|
||||
chain_item_or_default(profiles.get_item(rules_uid).ok(), || default_rules,),
|
||||
chain_item_or_default(profiles.get_item(proxies_uid).ok(), || default_proxies,),
|
||||
chain_item_or_default(profiles.get_item(groups_uid).ok(), || default_groups,),
|
||||
chain_item_or_default(profiles.get_item("Merge").ok(), || default_global_merge,),
|
||||
chain_item_or_default(profiles.get_item("Script").ok(), || default_global_script,),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user