Extract yaak-api crate with sysproxy for OS-level proxy detection

- New crates/yaak-api crate with no Tauri dependency
- Uses sysproxy to auto-detect OS proxy settings (macOS, Windows, Linux)
- Moved yaak_api_client from yaak-tauri-utils, now takes version string
- Removed api_client and error modules from yaak-tauri-utils
- Updated all callers in license, plugins, notifications, and URI scheme
This commit is contained in:
Gregory Schier
2026-02-12 08:20:08 -08:00
parent 83f6f9786b
commit 38153118bc
17 changed files with 360 additions and 200 deletions
-6
View File
@@ -6,10 +6,4 @@ publish = false
[dependencies]
tauri = { workspace = true }
reqwest = { workspace = true, features = ["gzip"] }
thiserror = { workspace = true }
serde = { workspace = true, features = ["derive"] }
regex = "1.11.0"
yaak-common = { workspace = true }
yaak-models = { workspace = true }
log = { workspace = true }
@@ -1,73 +0,0 @@
use crate::error::Result;
use log::{debug, warn};
use reqwest::{Client, Proxy};
use std::time::Duration;
use tauri::http::{HeaderMap, HeaderValue};
use tauri::{AppHandle, Manager, Runtime};
use yaak_common::platform::{get_ua_arch, get_ua_platform};
use yaak_models::models::{ProxySetting, ProxySettingAuth};
use yaak_models::query_manager::QueryManager;
pub fn yaak_api_client<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Client> {
let platform = get_ua_platform();
let version = app_handle.package_info().version.clone();
let arch = get_ua_arch();
let ua = format!("Yaak/{version} ({platform}; {arch})");
let mut default_headers = HeaderMap::new();
default_headers.insert("Accept", HeaderValue::from_str("application/json").unwrap());
let mut builder = reqwest::ClientBuilder::new()
.timeout(Duration::from_secs(20))
.default_headers(default_headers)
.gzip(true)
.user_agent(ua);
// Apply proxy settings from global app settings
let qm = app_handle.state::<QueryManager>();
let db = qm.inner().connect();
let proxy = db.get_settings().proxy;
match &proxy {
None => { /* System default */ }
Some(ProxySetting::Disabled) => {
builder = builder.no_proxy();
}
Some(ProxySetting::Enabled { http, https, auth, bypass, disabled }) => {
if !disabled {
if !http.is_empty() {
match Proxy::http(http) {
Ok(mut p) => {
if let Some(ProxySettingAuth { user, password }) = auth {
debug!("Using http proxy auth");
p = p.basic_auth(user.as_str(), password.as_str());
}
p = p.no_proxy(reqwest::NoProxy::from_string(bypass));
builder = builder.proxy(p);
}
Err(e) => {
warn!("Failed to apply http proxy: {e:?}");
}
}
}
if !https.is_empty() {
match Proxy::https(https) {
Ok(mut p) => {
if let Some(ProxySettingAuth { user, password }) = auth {
debug!("Using https proxy auth");
p = p.basic_auth(user.as_str(), password.as_str());
}
p = p.no_proxy(reqwest::NoProxy::from_string(bypass));
builder = builder.proxy(p);
}
Err(e) => {
warn!("Failed to apply https proxy: {e:?}");
}
}
}
}
}
}
let client = builder.build()?;
Ok(client)
}
@@ -1,19 +0,0 @@
use serde::{Serialize, Serializer};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
}
impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}
pub type Result<T> = std::result::Result<T, Error>;
-2
View File
@@ -1,3 +1 @@
pub mod api_client;
pub mod error;
pub mod window;