diff --git a/src-tauri/src/constants.rs b/src-tauri/src/constants.rs index da67ce13e..20b461f31 100644 --- a/src-tauri/src/constants.rs +++ b/src-tauri/src/constants.rs @@ -14,6 +14,12 @@ pub mod network { } } +pub mod proxy { + /// Single source of the macOS default bypass list; both proxy backends compose from it. + pub const MACOS_DEFAULT_BYPASS: &str = + "127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,localhost,*.local,*.crashlytics.com,"; +} + pub mod timing { use super::Duration; diff --git a/src-tauri/src/core/proxy_control.rs b/src-tauri/src/core/proxy_control.rs index e9f482247..19bc09456 100644 --- a/src-tauri/src/core/proxy_control.rs +++ b/src-tauri/src/core/proxy_control.rs @@ -6,7 +6,7 @@ use crate::{ notification::{self, FailedOperation}, runstate::RUN_STATE, service, - sysopt::Sysopt, + sysopt::{Sysopt, format_bypass}, }, process::AsyncHandler, utils::{ @@ -204,8 +204,6 @@ const fn refusal_classification(service_usable: Option) -> SysproxyFailure } const LOOPBACK_HOST: &str = "127.0.0.1"; -const MACOS_DEFAULT_BYPASS: &str = - "127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,localhost,*.local,*.crashlytics.com,"; const MAX_SERVICE_BYPASS_LEN: usize = 8192; static SERVICE_PROXY_OPERATIONS: ServiceProxyOperations = ServiceProxyOperations::new(); @@ -327,13 +325,7 @@ fn service_bypass(verge: &IVerge) -> Result { let custom = verge.system_proxy_bypass.as_deref().unwrap_or(""); ensure!(!custom.contains('\0'), "system proxy bypass contains NUL"); - let mut bypass = if custom.is_empty() { - MACOS_DEFAULT_BYPASS.to_owned() - } else if verge.use_default_bypass.unwrap_or(true) { - format!("{MACOS_DEFAULT_BYPASS},{custom}") - } else { - custom.to_owned() - }; + let mut bypass: String = format_bypass(verge.use_default_bypass.unwrap_or(true), custom).into(); truncate_utf8(&mut bypass, MAX_SERVICE_BYPASS_LEN); Ok(bypass) } diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index 6fccb0e3e..c503ab86c 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -268,10 +268,9 @@ static DEFAULT_BYPASS: &str = "localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8,172 #[cfg(any(target_os = "linux", target_os = "macos"))] static BYPASS_SEPARATOR: &str = ","; #[cfg(target_os = "macos")] -static DEFAULT_BYPASS: &str = - "127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,localhost,*.local,*.crashlytics.com,"; +static DEFAULT_BYPASS: &str = crate::constants::proxy::MACOS_DEFAULT_BYPASS; -fn format_bypass(use_default: bool, custom_bypass: &str) -> String { +pub(super) fn format_bypass(use_default: bool, custom_bypass: &str) -> String { if custom_bypass.is_empty() { DEFAULT_BYPASS.into() } else if use_default {