feat: allow set bypass without using default value

This commit is contained in:
MystiPanda
2024-07-01 22:53:06 +08:00
parent 6e374bcd4e
commit d81ef1d67c
8 changed files with 41 additions and 6 deletions

View File

@@ -75,6 +75,9 @@ pub struct IVerge {
/// enable proxy guard
pub enable_proxy_guard: Option<bool>,
/// always use default bypass
pub use_default_bypass: Option<bool>,
/// set system proxy bypass
pub system_proxy_bypass: Option<String>,
@@ -235,6 +238,7 @@ impl IVerge {
verge_port: Some(7899),
verge_http_enabled: Some(true),
enable_proxy_guard: Some(false),
use_default_bypass: Some(true),
proxy_guard_duration: Some(30),
auto_close_connection: Some(true),
auto_check_update: Some(true),
@@ -297,6 +301,7 @@ impl IVerge {
patch!(verge_http_enabled);
patch!(enable_system_proxy);
patch!(enable_proxy_guard);
patch!(use_default_bypass);
patch!(system_proxy_bypass);
patch!(proxy_guard_duration);
patch!(proxy_auto_config);

View File

@@ -42,8 +42,8 @@ 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,<local>";
fn get_bypass() -> String {
let bypass = DEFAULT_BYPASS.to_string();
// let bypass = DEFAULT_BYPASS.to_string();
let use_default = Config::verge().latest().use_default_bypass.unwrap_or(true);
let res = {
let verge = Config::verge();
let verge = verge.latest();
@@ -55,15 +55,23 @@ fn get_bypass() -> String {
};
#[cfg(target_os = "windows")]
let bypass = if custom_bypass.is_empty() {
bypass
DEFAULT_BYPASS.to_string()
} else {
format!("{};{}", bypass, custom_bypass)
if use_default {
format!("{};{}", DEFAULT_BYPASS, custom_bypass)
} else {
custom_bypass
}
};
#[cfg(not(target_os = "windows"))]
let bypass = if custom_bypass.is_empty() {
bypass
DEFAULT_BYPASS.to_string()
} else {
format!("{},{}", bypass, custom_bypass)
if use_default {
format!("{},{}", DEFAULT_BYPASS, custom_bypass)
} else {
custom_bypass
}
};
bypass