mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
Refactor string handling to use into() instead of to_string() for improved performance and consistency across the codebase. This change affects various modules including app.rs, clash.rs, config.rs, core.rs, service.rs, and others, ensuring that string conversions are streamlined and more idiomatic.
This commit is contained in:
@@ -27,7 +27,7 @@ impl Default for AsyncSysproxy {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enable: false,
|
||||
host: "127.0.0.1".to_string(),
|
||||
host: "127.0.0.1".into(),
|
||||
port: 7897,
|
||||
bypass: String::new(),
|
||||
}
|
||||
@@ -153,7 +153,7 @@ impl AsyncProxyQuery {
|
||||
log::debug!(target: "app", "PAC配置启用: URL={pac_url}, AutoDetect={auto_detect}");
|
||||
|
||||
if pac_url.is_empty() && auto_detect != 0 {
|
||||
pac_url = "auto-detect".to_string();
|
||||
pac_url = "auto-detect".into();
|
||||
}
|
||||
|
||||
Ok(AsyncAutoproxy {
|
||||
@@ -191,7 +191,7 @@ impl AsyncProxyQuery {
|
||||
// 正确解析包含冒号的URL
|
||||
// 格式: "ProxyAutoConfigURLString : http://127.0.0.1:11233/commands/pac"
|
||||
if let Some(colon_pos) = line.find(" : ") {
|
||||
pac_url = line[colon_pos + 3..].trim().to_string();
|
||||
pac_url = line[colon_pos + 3..].trim().into();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ impl AsyncProxyQuery {
|
||||
if let Ok(output) = output
|
||||
&& output.status.success()
|
||||
{
|
||||
let mode = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
let mode = String::from_utf8_lossy(&output.stdout).trim().into();
|
||||
if mode.contains("auto") {
|
||||
// 获取 PAC URL
|
||||
let pac_output = Command::new("gsettings")
|
||||
@@ -242,7 +242,7 @@ impl AsyncProxyQuery {
|
||||
.trim()
|
||||
.trim_matches('\'')
|
||||
.trim_matches('"')
|
||||
.to_string();
|
||||
.into();
|
||||
|
||||
if !pac_url.is_empty() {
|
||||
return Ok(AsyncAutoproxy {
|
||||
@@ -356,7 +356,7 @@ impl AsyncProxyQuery {
|
||||
if !proxy_server.is_empty() {
|
||||
// 解析服务器地址和端口
|
||||
let (host, port) = if let Some(colon_pos) = proxy_server.rfind(':') {
|
||||
let host = proxy_server[..colon_pos].to_string();
|
||||
let host = proxy_server[..colon_pos].into();
|
||||
let port = proxy_server[colon_pos + 1..].parse::<u16>().unwrap_or(8080);
|
||||
(host, port)
|
||||
} else {
|
||||
@@ -391,7 +391,7 @@ impl AsyncProxyQuery {
|
||||
let mut http_enabled = false;
|
||||
let mut http_host = String::new();
|
||||
let mut http_port = 8080u16;
|
||||
let mut exceptions = Vec::new();
|
||||
let mut exceptions: Vec<String> = Vec::new();
|
||||
|
||||
for line in stdout.lines() {
|
||||
let line = line.trim();
|
||||
@@ -399,7 +399,7 @@ impl AsyncProxyQuery {
|
||||
http_enabled = true;
|
||||
} else if line.contains("HTTPProxy") && !line.contains("Port") {
|
||||
if let Some(host_part) = line.split(':').nth(1) {
|
||||
http_host = host_part.trim().to_string();
|
||||
http_host = host_part.trim().into();
|
||||
}
|
||||
} else if line.contains("HTTPPort") {
|
||||
if let Some(port_part) = line.split(':').nth(1)
|
||||
@@ -412,7 +412,7 @@ impl AsyncProxyQuery {
|
||||
if let Some(list_part) = line.split(':').nth(1) {
|
||||
let list = list_part.trim();
|
||||
if !list.is_empty() {
|
||||
exceptions.push(list.to_string());
|
||||
exceptions.push(list.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,9 +452,7 @@ impl AsyncProxyQuery {
|
||||
if let Ok(mode_output) = mode_output
|
||||
&& mode_output.status.success()
|
||||
{
|
||||
let mode = String::from_utf8_lossy(&mode_output.stdout)
|
||||
.trim()
|
||||
.to_string();
|
||||
let mode = String::from_utf8_lossy(&mode_output.stdout).trim().into();
|
||||
if mode.contains("manual") {
|
||||
// 获取HTTP代理设置
|
||||
let host_result = Command::new("gsettings")
|
||||
@@ -475,7 +473,7 @@ impl AsyncProxyQuery {
|
||||
.trim()
|
||||
.trim_matches('\'')
|
||||
.trim_matches('"')
|
||||
.to_string();
|
||||
.into();
|
||||
|
||||
let port = String::from_utf8_lossy(&port_output.stdout)
|
||||
.trim()
|
||||
@@ -513,11 +511,11 @@ impl AsyncProxyQuery {
|
||||
|
||||
// 解析主机和端口
|
||||
let (host, port) = if let Some(colon_pos) = url.rfind(':') {
|
||||
let host = url[..colon_pos].to_string();
|
||||
let host = url[..colon_pos].into();
|
||||
let port = url[colon_pos + 1..].parse::<u16>().unwrap_or(8080);
|
||||
(host, port)
|
||||
} else {
|
||||
(url.to_string(), 8080)
|
||||
(url.into(), 8080)
|
||||
};
|
||||
|
||||
if host.is_empty() {
|
||||
|
||||
@@ -86,7 +86,7 @@ impl WebDavClient {
|
||||
|| verge.webdav_username.is_none()
|
||||
|| verge.webdav_password.is_none()
|
||||
{
|
||||
let msg = "Unable to create web dav client, please make sure the webdav config is correct".to_string();
|
||||
let msg: String = "Unable to create web dav client, please make sure the webdav config is correct".into();
|
||||
return Err(anyhow::Error::msg(msg));
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ impl WebDavClient {
|
||||
.webdav_url
|
||||
.unwrap_or_default()
|
||||
.trim_end_matches('/')
|
||||
.to_string(),
|
||||
.into(),
|
||||
username: verge.webdav_username.unwrap_or_default(),
|
||||
password: verge.webdav_password.unwrap_or_default(),
|
||||
};
|
||||
|
||||
@@ -272,13 +272,13 @@ impl CoreManager {
|
||||
if has_error {
|
||||
logging!(info, Type::Config, "发现错误,开始处理错误信息");
|
||||
let error_msg = if !stdout.is_empty() {
|
||||
stdout.to_string()
|
||||
stdout.into()
|
||||
} else if !stderr.is_empty() {
|
||||
stderr.to_string()
|
||||
stderr.into()
|
||||
} else if let Some(code) = output.status.code() {
|
||||
format!("验证进程异常退出,退出码: {code}")
|
||||
} else {
|
||||
"验证进程被终止".to_string()
|
||||
"验证进程被终止".into()
|
||||
};
|
||||
|
||||
logging!(info, Type::Config, "-------- 验证结束 --------");
|
||||
@@ -350,7 +350,7 @@ impl CoreManager {
|
||||
let error_msg = "Script must contain a main function";
|
||||
logging!(warn, Type::Config, "脚本缺少main函数: {}", path);
|
||||
//handle::Handle::notice_message("config_validate::script_missing_main", error_msg);
|
||||
return Ok((false, error_msg.to_string()));
|
||||
return Ok((false, error_msg.into()));
|
||||
}
|
||||
|
||||
Ok((true, String::new()))
|
||||
@@ -441,7 +441,7 @@ impl CoreManager {
|
||||
let process_name = if cfg!(windows) {
|
||||
format!("{target}.exe")
|
||||
} else {
|
||||
target.to_string()
|
||||
target.into()
|
||||
};
|
||||
process_futures.push(self.find_processes_by_name(process_name, target));
|
||||
}
|
||||
@@ -917,7 +917,7 @@ impl CoreManager {
|
||||
if clash_core.is_none() {
|
||||
let error_message = "Clash core should not be Null";
|
||||
logging!(error, Type::Core, "{}", error_message);
|
||||
return Err(error_message.to_string());
|
||||
return Err(error_message.into());
|
||||
}
|
||||
let core = clash_core.as_ref().ok_or_else(|| {
|
||||
let msg = "Clash core should not be None";
|
||||
|
||||
@@ -55,13 +55,13 @@ impl Default for ProxyState {
|
||||
pac_enabled: false,
|
||||
auto_proxy: Autoproxy {
|
||||
enable: false,
|
||||
url: "".to_string(),
|
||||
url: "".into(),
|
||||
},
|
||||
sys_proxy: Sysproxy {
|
||||
enable: false,
|
||||
host: "127.0.0.1".to_string(),
|
||||
host: "127.0.0.1".into(),
|
||||
port: 7897,
|
||||
bypass: "".to_string(),
|
||||
bypass: "".into(),
|
||||
},
|
||||
last_updated: std::time::Instant::now(),
|
||||
is_healthy: true,
|
||||
@@ -519,7 +519,7 @@ impl EventDrivenProxyManager {
|
||||
verge
|
||||
.proxy_host
|
||||
.clone()
|
||||
.unwrap_or_else(|| "127.0.0.1".to_string())
|
||||
.unwrap_or_else(|| "127.0.0.1".into())
|
||||
};
|
||||
let pac_port = IVerge::get_singleton_port();
|
||||
Autoproxy {
|
||||
@@ -534,7 +534,7 @@ impl EventDrivenProxyManager {
|
||||
let proxy_host = verge_config.latest_ref().proxy_host.clone();
|
||||
|
||||
let port = verge_mixed_port.unwrap_or(Config::clash().await.latest_ref().get_mixed_port());
|
||||
let proxy_host = proxy_host.unwrap_or_else(|| "127.0.0.1".to_string());
|
||||
let proxy_host = proxy_host.unwrap_or_else(|| "127.0.0.1".into());
|
||||
|
||||
Sysproxy {
|
||||
enable: true,
|
||||
|
||||
@@ -330,7 +330,7 @@ async fn check_service_version() -> Result<String> {
|
||||
return Err(anyhow::anyhow!(err_msg));
|
||||
}
|
||||
|
||||
let version = response.data.unwrap_or("unknown".to_string());
|
||||
let version = response.data.unwrap_or("unknown".into());
|
||||
Ok(version)
|
||||
};
|
||||
|
||||
@@ -361,9 +361,9 @@ pub(super) async fn start_with_existing_service(config_file: &PathBuf) -> Result
|
||||
|
||||
let payload = clash_verge_service_ipc::ClashConfig {
|
||||
core_config: CoreConfig {
|
||||
config_path: dirs::path_to_str(config_file)?.to_string(),
|
||||
core_path: dirs::path_to_str(&bin_path)?.to_string(),
|
||||
config_dir: dirs::path_to_str(&dirs::app_home_dir()?)?.to_string(),
|
||||
config_path: dirs::path_to_str(config_file)?.into(),
|
||||
core_path: dirs::path_to_str(&bin_path)?.into(),
|
||||
config_dir: dirs::path_to_str(&dirs::app_home_dir()?)?.into(),
|
||||
},
|
||||
log_config: service_writer_config().await?,
|
||||
};
|
||||
|
||||
@@ -39,11 +39,11 @@ async fn get_bypass() -> String {
|
||||
};
|
||||
let custom_bypass = match res {
|
||||
Some(bypass) => bypass,
|
||||
None => "".to_string(),
|
||||
None => "".into(),
|
||||
};
|
||||
|
||||
if custom_bypass.is_empty() {
|
||||
DEFAULT_BYPASS.to_string()
|
||||
DEFAULT_BYPASS.into()
|
||||
} else if use_default {
|
||||
format!("{DEFAULT_BYPASS},{custom_bypass}")
|
||||
} else {
|
||||
@@ -180,11 +180,11 @@ impl Sysopt {
|
||||
|
||||
let args = if pac_enable {
|
||||
let address = format!("http://{proxy_host}:{pac_port}/commands/pac");
|
||||
vec!["pac".to_string(), address]
|
||||
vec!["pac".into(), address]
|
||||
} else {
|
||||
let address = format!("{proxy_host}:{port}");
|
||||
let bypass = get_bypass().await;
|
||||
vec!["global".to_string(), address, bypass]
|
||||
vec!["global".into(), address, bypass]
|
||||
};
|
||||
|
||||
execute_sysproxy_command(args).await?;
|
||||
@@ -208,7 +208,7 @@ impl Sysopt {
|
||||
log::warn!(target: "app", "重置代理时获取自动代理配置失败: {e}, 使用默认配置");
|
||||
Autoproxy {
|
||||
enable: false,
|
||||
url: "".to_string(),
|
||||
url: "".into(),
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -220,7 +220,7 @@ impl Sysopt {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
execute_sysproxy_command(vec!["set".to_string(), "1".to_string()]).await?;
|
||||
execute_sysproxy_command(vec!["set".into(), "1".into()]).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -457,9 +457,9 @@ impl Timer {
|
||||
fn emit_update_event(_uid: &str, _is_start: bool) {
|
||||
{
|
||||
if _is_start {
|
||||
super::handle::Handle::notify_profile_update_started(_uid.to_string());
|
||||
super::handle::Handle::notify_profile_update_started(_uid.into());
|
||||
} else {
|
||||
super::handle::Handle::notify_profile_update_completed(_uid.to_string());
|
||||
super::handle::Handle::notify_profile_update_completed(_uid.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ impl TrayState {
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let tray_icon_colorful = verge.tray_icon.unwrap_or("monochrome".to_string());
|
||||
let tray_icon_colorful = verge.tray_icon.unwrap_or("monochrome".into());
|
||||
if tray_icon_colorful == "monochrome" {
|
||||
(
|
||||
false,
|
||||
@@ -117,7 +117,7 @@ impl TrayState {
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".into());
|
||||
if tray_icon_colorful == "monochrome" {
|
||||
(
|
||||
false,
|
||||
@@ -151,7 +151,7 @@ impl TrayState {
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".into());
|
||||
if tray_icon_colorful == "monochrome" {
|
||||
(
|
||||
false,
|
||||
@@ -349,7 +349,7 @@ impl Tray {
|
||||
(false, false) => TrayState::get_common_tray_icon().await,
|
||||
};
|
||||
|
||||
let colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
|
||||
let colorful = verge.tray_icon.clone().unwrap_or("monochrome".into());
|
||||
let is_colorful = colorful == "colorful";
|
||||
|
||||
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&icon_bytes)?));
|
||||
@@ -427,7 +427,7 @@ impl Tray {
|
||||
map
|
||||
};
|
||||
|
||||
let mut current_profile_name = "None".to_string();
|
||||
let mut current_profile_name = "None".into();
|
||||
{
|
||||
let profiles = Config::profiles().await;
|
||||
let profiles = profiles.latest_ref();
|
||||
@@ -447,7 +447,7 @@ impl Tray {
|
||||
let profile_text = t("Profile").await;
|
||||
|
||||
let v = env!("CARGO_PKG_VERSION");
|
||||
let reassembled_version = v.split_once('+').map_or(v.to_string(), |(main, rest)| {
|
||||
let reassembled_version = v.split_once('+').map_or(v.into(), |(main, rest)| {
|
||||
format!("{main}+{}", rest.split('.').next().unwrap_or(""))
|
||||
});
|
||||
|
||||
@@ -617,7 +617,7 @@ async fn create_tray_menu(
|
||||
.filter_map(|item| {
|
||||
let mut parts = item.split(',');
|
||||
match (parts.next(), parts.next()) {
|
||||
(Some(func), Some(key)) => Some((func.to_string(), key.to_string())),
|
||||
(Some(func), Some(key)) => Some((func.into(), key.into())),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
@@ -690,11 +690,11 @@ async fn create_tray_menu(
|
||||
.get(proxy_str)
|
||||
.and_then(|h| h.history.last())
|
||||
.map(|h| match h.delay {
|
||||
0 => "-ms".to_string(),
|
||||
delay if delay >= 10000 => "-ms".to_string(),
|
||||
0 => "-ms".into(),
|
||||
delay if delay >= 10000 => "-ms".into(),
|
||||
_ => format!("{}ms", h.delay),
|
||||
})
|
||||
.unwrap_or_else(|| "-ms".to_string());
|
||||
.unwrap_or_else(|| "-ms".into());
|
||||
|
||||
let display_text = format!("{} | {}", proxy_str, delay_text);
|
||||
|
||||
@@ -773,7 +773,7 @@ async fn create_tray_menu(
|
||||
.iter()
|
||||
.filter_map(|group| group.get("name"))
|
||||
.filter_map(|name| name.as_str())
|
||||
.map(|name| name.to_string())
|
||||
.map(|name| name.into())
|
||||
.collect::<Vec<String>>()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
|
||||
Reference in New Issue
Block a user