fix: specify type for mode and host variables to improve clarity and type safety (#5052)

* fix: specify type for mode and host variables to improve clarity and type safety

* fix: specify types for pac_url and host variables to enhance type safety

* fix: change type of pac_url from Url to String for consistency in handling PAC output
This commit is contained in:
Tunglies
2025-10-14 13:16:11 +08:00
committed by GitHub
parent 3d96a575c0
commit 76ca24086b

View File

@@ -227,7 +227,7 @@ impl AsyncProxyQuery {
if let Ok(output) = output
&& output.status.success()
{
let mode = String::from_utf8_lossy(&output.stdout).trim().into();
let mode: String = String::from_utf8_lossy(&output.stdout).trim().into();
if mode.contains("auto") {
// 获取 PAC URL
let pac_output = Command::new("gsettings")
@@ -238,7 +238,7 @@ impl AsyncProxyQuery {
if let Ok(pac_output) = pac_output
&& pac_output.status.success()
{
let pac_url = String::from_utf8_lossy(&pac_output.stdout)
let pac_url: String = String::from_utf8_lossy(&pac_output.stdout)
.trim()
.trim_matches('\'')
.trim_matches('"')
@@ -452,7 +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().into();
let mode: String = String::from_utf8_lossy(&mode_output.stdout).trim().into();
if mode.contains("manual") {
// 获取HTTP代理设置
let host_result = Command::new("gsettings")
@@ -469,7 +469,7 @@ impl AsyncProxyQuery {
&& host_output.status.success()
&& port_output.status.success()
{
let host = String::from_utf8_lossy(&host_output.stdout)
let host: String = String::from_utf8_lossy(&host_output.stdout)
.trim()
.trim_matches('\'')
.trim_matches('"')
@@ -511,7 +511,7 @@ impl AsyncProxyQuery {
// 解析主机和端口
let (host, port) = if let Some(colon_pos) = url.rfind(':') {
let host = url[..colon_pos].into();
let host: String = url[..colon_pos].into();
let port = url[colon_pos + 1..].parse::<u16>().unwrap_or(8080);
(host, port)
} else {