refactor(ipc): avoid redundant response copies

This commit is contained in:
Tunglies
2026-10-08 02:21:11 +08:00
parent 4065e19dbf
commit 17ee7f348c
3 changed files with 16 additions and 22 deletions
+8 -11
View File
@@ -16,16 +16,16 @@ pub async fn get_sys_proxy() -> CmdResult<SystemProxy> {
other => other.stringify_err()?,
};
let Sysproxy {
ref host,
ref bypass,
ref port,
ref enable,
host,
bypass,
port,
enable,
} = sys_proxy;
Ok(SystemProxy {
enable: *enable,
enable,
server: format!("{host}:{port}"),
bypass: bypass.to_string(),
bypass,
})
}
@@ -37,12 +37,9 @@ pub async fn get_auto_proxy() -> CmdResult<AutoProxy> {
Err(error) if proxy_control::is_missing_network_service(&error) => Autoproxy::default(),
other => other.stringify_err()?,
};
let Autoproxy { ref enable, ref url } = auto_proxy;
let Autoproxy { enable, url } = auto_proxy;
Ok(AutoProxy {
enable: *enable,
url: url.to_string(),
})
Ok(AutoProxy { enable, url })
}
#[tauri::command]
+5 -7
View File
@@ -408,15 +408,16 @@ pub async fn patch_profiles_config(profiles: ProfileSelection) -> CmdResult<Vali
}
let _profile_write_guard = PROFILE_WRITE_LOCK.lock().await;
let profiles = IProfiles {
current: profiles.current,
items: None,
};
let target_profile = profiles.current.as_ref();
let previous_profile = Config::profiles().await.data_arc().current.clone();
Config::profiles().await.edit_draft(|d| {
d.patch_config(&IProfiles {
current: profiles.current.clone(),
items: None,
});
d.patch_config(&profiles);
});
perform_config_update(target_profile, previous_profile.as_ref())
@@ -477,7 +478,6 @@ pub async fn patch_profile(index: std::string::String, profile: ProfilePatch) ->
#[tauri::command]
#[specta::specta]
pub async fn view_profile(index: std::string::String) -> CmdResult {
let index: String = index.into();
let profiles = Config::profiles().await;
let profiles_ref = profiles.latest_arc();
let file = profiles_ref
@@ -503,7 +503,6 @@ pub async fn view_profile(index: std::string::String) -> CmdResult {
#[tauri::command]
#[specta::specta]
pub async fn read_profile_file(index: std::string::String) -> CmdResult<std::string::String> {
let index: String = index.into();
let item = {
let profiles = Config::profiles().await;
let profiles_ref = profiles.latest_arc();
@@ -540,7 +539,6 @@ pub async fn read_profile_file(index: std::string::String) -> CmdResult<std::str
#[tauri::command]
#[specta::specta]
pub async fn get_next_update_time(uid: std::string::String) -> CmdResult<Option<i64>> {
let uid: String = uid.into();
let timer = Timer::global();
let next_time = timer.get_next_update_time(&uid).await;
Ok(next_time)
+3 -4
View File
@@ -52,7 +52,6 @@ pub fn take_discarded_keys_notice() -> Option<std::string::String> {
pub async fn get_runtime_proxy_chain_config(
proxy_chain_exit_node: std::string::String,
) -> CmdResult<std::string::String> {
let proxy_chain_exit_node: String = proxy_chain_exit_node.into();
let runtime = Config::runtime().await;
let runtime = runtime.latest_arc();
@@ -73,7 +72,7 @@ pub async fn get_runtime_proxy_chain_config(
false
}
}) {
proxies_chain.push(proxy.to_owned());
proxies_chain.push(proxy);
proxy_name = proxy.get("dialer-proxy").map(|x| x.as_str());
}
@@ -82,12 +81,12 @@ pub async fn get_runtime_proxy_chain_config(
.find(|proxy| proxy.get("name").map(|x| x.as_str()) == proxy_name)
&& !proxies_chain.is_empty()
{
proxies_chain.push(entry_proxy.to_owned());
proxies_chain.push(entry_proxy);
}
proxies_chain.reverse();
let mut config: HashMap<String, Vec<serde_yaml_ng::Value>> = HashMap::new();
let mut config: HashMap<String, Vec<&serde_yaml_ng::Value>> = HashMap::new();
config.insert("proxies".into(), proxies_chain);