Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
feat: implement global proxy management with initialization and retrieval functions
Tonho9f3073f70089
diff --git a/src-tauri/src/core/http_client.rs b/src-tauri/src/core/http_client.rsindex 59629f94..e548af94 100644--- a/src-tauri/src/core/http_client.rs+++ b/src-tauri/src/core/http_client.rs@@ -1,5 +1,44 @@+use std::sync::LazyLock;+use std::sync::RwLock;+use omniget_core::models::settings::ProxySettings;+static GLOBAL_PROXY: LazyLock<RwLock<ProxySettings>> =+ LazyLock::new(|| RwLock::new(ProxySettings::default()));++pub fn init_proxy(proxy: ProxySettings) {+ if let Ok(mut guard) = GLOBAL_PROXY.write() {+ *guard = proxy;+ }+}++pub fn get_proxy_snapshot() -> ProxySettings {+ GLOBAL_PROXY+ .read()+ .map(|g| g.clone())+ .unwrap_or_default()+}++pub fn proxy_url() -> Option<String> {+ let proxy = get_proxy_snapshot();+ if !proxy.enabled || proxy.host.is_empty() {+ return None;+ }+ let scheme = match proxy.proxy_type.as_str() {+ "socks5" => "socks5",+ "https" => "https",+ _ => "http",+ };+ if !proxy.username.is_empty() {+ Some(format!(+ "{}://{}:{}@{}:{}",+ scheme, proxy.username, proxy.password, proxy.host, proxy.port+ ))+ } else {+ Some(format!("{}://{}:{}", scheme, proxy.host, proxy.port))+ }+}+pub fn apply_proxy(builder: reqwest::ClientBuilder,proxy: &ProxySettings,@@ -28,3 +67,8 @@ pub fn apply_proxy(}}}++pub fn apply_global_proxy(builder: reqwest::ClientBuilder) -> reqwest::ClientBuilder {+ let proxy = get_proxy_snapshot();+ apply_proxy(builder, &proxy)+}