diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 9a532f76..66283b71 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -337,7 +337,7 @@ pub fn get_network_interfaces() -> Vec { for (interface_name, _) in &networks { result.push(interface_name.clone()); } - return result; + result } #[tauri::command] diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 3a06648f..a49659a5 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -137,7 +137,7 @@ pub async fn install_service(passwd: String) -> Result<()> { .output()?; let output = sudo( &passwd, - format!("{}", installer_path.to_string_lossy().replace(" ", "\\ ")), + installer_path.to_string_lossy().replace(" ", "\\ ").to_string(), ) .output()?; @@ -244,7 +244,7 @@ pub async fn uninstall_service(passwd: String) -> Result<()> { .output()?; let output = sudo( &passwd, - format!("{}", uninstaller_path.to_string_lossy().replace(" ", "\\ ")), + uninstaller_path.to_string_lossy().replace(" ", "\\ ").to_string(), ) .output()?; diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index a9060424..57ea66c4 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -66,12 +66,10 @@ fn get_bypass() -> String { #[cfg(not(target_os = "windows"))] let bypass = if custom_bypass.is_empty() { DEFAULT_BYPASS.to_string() + } else if use_default { + format!("{},{}", DEFAULT_BYPASS, custom_bypass) } else { - if use_default { - format!("{},{}", DEFAULT_BYPASS, custom_bypass) - } else { - custom_bypass - } + custom_bypass }; bypass diff --git a/src-tauri/src/enhance/seq.rs b/src-tauri/src/enhance/seq.rs index c253b1e6..81e722b5 100644 --- a/src-tauri/src/enhance/seq.rs +++ b/src-tauri/src/enhance/seq.rs @@ -12,7 +12,7 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping { let append = seq_map.append; 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() }); 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() { Some(item) } else { - item.get("name").map(|y| y.clone()) + item.get("name").cloned() } { delete_names.push(name.clone()); } @@ -34,7 +34,7 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping { } else { x.get("name") } { - !delete_names.contains(&x_name) + !delete_names.contains(x_name) } else { true } @@ -51,5 +51,5 @@ pub fn use_seq(seq_map: SeqMap, config: Mapping, name: &str) -> Mapping { let mut config = config.clone(); config.insert(Value::from(name), Value::from(seq)); - return config; + config } diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index 37ee2c28..8b90684d 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -184,12 +184,10 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { update_core_config().await?; } #[cfg(not(target_os = "windows"))] - if redir_enabled.is_some() || redir_port.is_some() { - if !generated { - Config::generate().await?; - CoreManager::global().run_core().await?; - generated = true; - } + if (redir_enabled.is_some() || redir_port.is_some()) && !generated { + Config::generate().await?; + CoreManager::global().run_core().await?; + generated = true; } #[cfg(target_os = "linux")] if tproxy_enabled.is_some() || tproxy_port.is_some() { @@ -199,16 +197,12 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { generated = true; } } - if socks_enabled.is_some() + if (socks_enabled.is_some() || http_enabled.is_some() || socks_port.is_some() - || http_port.is_some() - || mixed_port.is_some() - { - if !generated { - Config::generate().await?; - CoreManager::global().run_core().await?; - } + || http_port.is_some() || mixed_port.is_some()) && !generated { + Config::generate().await?; + CoreManager::global().run_core().await?; } if auto_launch.is_some() { sysopt::Sysopt::global().update_launch()?; diff --git a/src-tauri/src/utils/dirs.rs b/src-tauri/src/utils/dirs.rs index a44a1ce0..e4030620 100644 --- a/src-tauri/src/utils/dirs.rs +++ b/src-tauri/src/utils/dirs.rs @@ -48,11 +48,11 @@ pub fn app_home_dir() -> Result { match app_handle.path().data_dir() { Ok(dir) => { - return Ok(dir.join(APP_ID)); + Ok(dir.join(APP_ID)) } Err(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 { let app_handle = handle::Handle::global().app_handle().unwrap(); match app_handle.path().resource_dir() { Ok(dir) => { - return Ok(dir.join("resources")); + Ok(dir.join("resources")) } Err(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 diff --git a/src-tauri/src/utils/init.rs b/src-tauri/src/utils/init.rs index d7ee89a9..e56e7718 100644 --- a/src-tauri/src/utils/init.rs +++ b/src-tauri/src/utils/init.rs @@ -332,7 +332,7 @@ pub async fn startup_script() -> Result<()> { app_handle .shell() .command(shell_type) - .current_dir(working_dir.to_path_buf()) + .current_dir(working_dir) .args(&[script_path]) .output() .await?;