diff --git a/Cargo.lock b/Cargo.lock index b66c7197..b13e42fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1907,6 +1907,15 @@ name = "libmpv2-sys" version = "4.0.0" source = "git+https://github.com/kohsine/libmpv2-rs.git#906d957e7bbc4c2a52c33cdb4f93c2a22e72f3c3" +[[package]] +name = "libproxy" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579703403a8f387e407bf0326c9ecd865bbd19bca62ca40f370870f8d8a0e7dc" +dependencies = [ + "libc", +] + [[package]] name = "libredox" version = "0.1.3" @@ -3347,6 +3356,7 @@ dependencies = [ "libc", "libloading", "libmpv2", + "libproxy", "md-5", "once_cell", "rand", diff --git a/Cargo.toml b/Cargo.toml index d35957b4..98ca940f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,6 +72,7 @@ xattr ={ version = "1.4.0" } [target.'cfg(target_os = "windows")'.dependencies] gdk4-win32 = { version = "0.9" } +libproxy = { version = "0.1.1" } [package.metadata.deb] maintainer = "Inaha " diff --git a/src/client/emby_client.rs b/src/client/emby_client.rs index 6313b7ca..9e8a87dd 100644 --- a/src/client/emby_client.rs +++ b/src/client/emby_client.rs @@ -131,8 +131,8 @@ fn generate_hash(s: &str) -> String { format!("{:x}", hasher.finish()) } -impl EmbyClient { - pub fn default() -> Self { +impl Default for EmbyClient { + fn default() -> Self { let mut headers = reqwest::header::HeaderMap::new(); headers.insert("Accept-Encoding", HeaderValue::from_static("gzip")); headers.insert( @@ -159,7 +159,9 @@ impl EmbyClient { server_name_hash: Mutex::new(String::new()), } } +} +impl EmbyClient { pub async fn init(&self, account: &Account) -> Result<(), Box> { self.header_change_url(&account.server, &account.port) .await?; diff --git a/src/client/proxy.rs b/src/client/proxy.rs index 0086ab6d..4e5c47fe 100644 --- a/src/client/proxy.rs +++ b/src/client/proxy.rs @@ -51,28 +51,23 @@ use windows::{ }; #[cfg(target_os = "windows")] pub fn get_proxy_settings() -> Option { - unsafe { - let mut proxy_config = WINHTTP_CURRENT_USER_IE_PROXY_CONFIG::default(); - if WinHttpGetIEProxyConfigForCurrentUser(&mut proxy_config).is_err() { - return None; - } + // FIXME: proxy should be a dynamic constructor + // + // This is only a temporary solution to get the proxy settings on Windows. + // ProxyFactory::get_proxies() is a blocking method, PAC may be a stream. + const EXAMPLE_PROXY: &str = "http://example.com"; - if !proxy_config.lpszProxy.is_null() { - return PCWSTR(proxy_config.lpszProxy.0).to_string().ok(); - } - - if !proxy_config.lpszAutoConfigUrl.is_null() { - return PCWSTR(proxy_config.lpszAutoConfigUrl.0) - .to_string() - .map(|proxy_url| { - proxy_url.split('/').collect::>()[..3] - .join("/") - .to_string() - }) - .ok(); - } - } - None + // FIEXME: user:password@ is not supported + // + // libproxy will return "direct://", if no proxy is found. + // protocol://[user:password@]proxyhost[:port], but reqwest cant parse [user:password@] + use libproxy::ProxyFactory; + ProxyFactory::new()? + .get_proxies(EXAMPLE_PROXY) + .ok()? + .first() + .filter(|&proxy| proxy != "direct://") + .cloned() } #[cfg(target_os = "linux")] diff --git a/src/lib.rs b/src/lib.rs index 61c5bda2..d84c991f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,13 +4,14 @@ use std::{ }; mod arg; -mod client; mod config; mod gstl; mod macros; mod ui; mod utils; +pub mod client; + #[cfg(target_os = "windows")] pub use client::windows_compat::theme::is_system_dark_mode_enabled;