fix: code lint

This commit is contained in:
huzibaca 2024-09-24 20:06:25 +08:00
parent d9e5387bff
commit 57f1c005e6
7 changed files with 24 additions and 32 deletions

View File

@ -337,7 +337,7 @@ pub fn get_network_interfaces() -> Vec<String> {
for (interface_name, _) in &networks { for (interface_name, _) in &networks {
result.push(interface_name.clone()); result.push(interface_name.clone());
} }
return result; result
} }
#[tauri::command] #[tauri::command]

View File

@ -137,7 +137,7 @@ pub async fn install_service(passwd: String) -> Result<()> {
.output()?; .output()?;
let output = sudo( let output = sudo(
&passwd, &passwd,
format!("{}", installer_path.to_string_lossy().replace(" ", "\\ ")), installer_path.to_string_lossy().replace(" ", "\\ ").to_string(),
) )
.output()?; .output()?;
@ -244,7 +244,7 @@ pub async fn uninstall_service(passwd: String) -> Result<()> {
.output()?; .output()?;
let output = sudo( let output = sudo(
&passwd, &passwd,
format!("{}", uninstaller_path.to_string_lossy().replace(" ", "\\ ")), uninstaller_path.to_string_lossy().replace(" ", "\\ ").to_string(),
) )
.output()?; .output()?;

View File

@ -66,12 +66,10 @@ fn get_bypass() -> String {
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
let bypass = if custom_bypass.is_empty() { let bypass = if custom_bypass.is_empty() {
DEFAULT_BYPASS.to_string() DEFAULT_BYPASS.to_string()
} else if use_default {
format!("{},{}", DEFAULT_BYPASS, custom_bypass)
} else { } else {
if use_default { custom_bypass
format!("{},{}", DEFAULT_BYPASS, custom_bypass)
} else {
custom_bypass
}
}; };
bypass bypass

View File

@ -12,7 +12,7 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping {
let append = seq_map.append; let append = seq_map.append;
let delete = seq_map.delete; let delete = seq_map.delete;
let origin_seq = config.get(&name).map_or(Sequence::default(), |val| { let origin_seq = config.get(name).map_or(Sequence::default(), |val| {
val.as_sequence().unwrap_or(&Sequence::default()).clone() val.as_sequence().unwrap_or(&Sequence::default()).clone()
}); });
let mut seq = origin_seq.clone(); let mut seq = origin_seq.clone();
@ -23,7 +23,7 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping {
if let Some(name) = if item.is_string() { if let Some(name) = if item.is_string() {
Some(item) Some(item)
} else { } else {
item.get("name").map(|y| y.clone()) item.get("name").cloned()
} { } {
delete_names.push(name.clone()); delete_names.push(name.clone());
} }
@ -34,7 +34,7 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping {
} else { } else {
x.get("name") x.get("name")
} { } {
!delete_names.contains(&x_name) !delete_names.contains(x_name)
} else { } else {
true true
} }
@ -51,5 +51,5 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping {
let mut config = config.clone(); let mut config = config.clone();
config.insert(Value::from(name), Value::from(seq)); config.insert(Value::from(name), Value::from(seq));
return config; config
} }

View File

@ -184,12 +184,10 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
update_core_config().await?; update_core_config().await?;
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
if redir_enabled.is_some() || redir_port.is_some() { if (redir_enabled.is_some() || redir_port.is_some()) && !generated {
if !generated { Config::generate().await?;
Config::generate().await?; CoreManager::global().run_core().await?;
CoreManager::global().run_core().await?; generated = true;
generated = true;
}
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
if tproxy_enabled.is_some() || tproxy_port.is_some() { if tproxy_enabled.is_some() || tproxy_port.is_some() {
@ -199,16 +197,12 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
generated = true; generated = true;
} }
} }
if socks_enabled.is_some() if (socks_enabled.is_some()
|| http_enabled.is_some() || http_enabled.is_some()
|| socks_port.is_some() || socks_port.is_some()
|| http_port.is_some() || http_port.is_some() || mixed_port.is_some()) && !generated {
|| mixed_port.is_some() Config::generate().await?;
{ CoreManager::global().run_core().await?;
if !generated {
Config::generate().await?;
CoreManager::global().run_core().await?;
}
} }
if auto_launch.is_some() { if auto_launch.is_some() {
sysopt::Sysopt::global().update_launch()?; sysopt::Sysopt::global().update_launch()?;

View File

@ -48,11 +48,11 @@ pub fn app_home_dir() -> Result<PathBuf> {
match app_handle.path().data_dir() { match app_handle.path().data_dir() {
Ok(dir) => { Ok(dir) => {
return Ok(dir.join(APP_ID)); Ok(dir.join(APP_ID))
} }
Err(e) => { Err(e) => {
log::error!("Failed to get the app home directory: {}", e); log::error!("Failed to get the app home directory: {}", e);
return Err(anyhow::anyhow!("Failed to get the app homedirectory")); Err(anyhow::anyhow!("Failed to get the app homedirectory"))
} }
} }
} }
@ -62,13 +62,13 @@ pub fn app_resources_dir() -> Result<PathBuf> {
let app_handle = handle::Handle::global().app_handle().unwrap(); let app_handle = handle::Handle::global().app_handle().unwrap();
match app_handle.path().resource_dir() { match app_handle.path().resource_dir() {
Ok(dir) => { Ok(dir) => {
return Ok(dir.join("resources")); Ok(dir.join("resources"))
} }
Err(e) => { Err(e) => {
log::error!("Failed to get the resource directory: {}", e); log::error!("Failed to get the resource directory: {}", e);
return Err(anyhow::anyhow!("Failed to get the resource directory")); Err(anyhow::anyhow!("Failed to get the resource directory"))
} }
}; }
} }
/// profiles dir /// profiles dir

View File

@ -332,7 +332,7 @@ pub async fn startup_script() -> Result<()> {
app_handle app_handle
.shell() .shell()
.command(shell_type) .command(shell_type)
.current_dir(working_dir.to_path_buf()) .current_dir(working_dir)
.args(&[script_path]) .args(&[script_path])
.output() .output()
.await?; .await?;