From 83f6f9786bf841d13906ac14464666eab754a54a Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 12 Feb 2026 06:57:35 -0800 Subject: [PATCH] Fix license activation and plugin requests ignoring proxy settings Make yaak_api_client() read proxy settings from the database and apply them to the reqwest client. Also replace bare reqwest::Client::new() calls in license activate/deactivate with yaak_api_client() so they get proxy support (and consistent UA/headers/timeout). Fixes https://yaak.app/feedback/posts/cannot-activate-license Co-Authored-By: Claude Opus 4.6 --- Cargo.lock | 2 + crates-tauri/yaak-license/src/license.rs | 4 +- crates-tauri/yaak-tauri-utils/Cargo.toml | 2 + .../yaak-tauri-utils/src/api_client.rs | 59 +++++++++++++++++-- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6897229a..96e7a227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8301,12 +8301,14 @@ dependencies = [ name = "yaak-tauri-utils" version = "0.1.0" dependencies = [ + "log", "regex", "reqwest", "serde", "tauri", "thiserror 2.0.17", "yaak-common", + "yaak-models", ] [[package]] diff --git a/crates-tauri/yaak-license/src/license.rs b/crates-tauri/yaak-license/src/license.rs index dc6c185e..b1417bff 100644 --- a/crates-tauri/yaak-license/src/license.rs +++ b/crates-tauri/yaak-license/src/license.rs @@ -118,7 +118,7 @@ pub async fn activate_license( license_key: &str, ) -> Result<()> { info!("Activating license {}", license_key); - let client = reqwest::Client::new(); + let client = yaak_api_client(window.app_handle())?; let payload = ActivateLicenseRequestPayload { license_key: license_key.to_string(), app_platform: get_os_str().to_string(), @@ -155,7 +155,7 @@ pub async fn deactivate_license(window: &WebviewWindow) -> Result let app_handle = window.app_handle(); let activation_id = get_activation_id(app_handle).await; - let client = reqwest::Client::new(); + let client = yaak_api_client(window.app_handle())?; let path = format!("/licenses/activations/{}/deactivate", activation_id); let payload = DeactivateLicenseRequestPayload { app_platform: get_os_str().to_string(), diff --git a/crates-tauri/yaak-tauri-utils/Cargo.toml b/crates-tauri/yaak-tauri-utils/Cargo.toml index 11652f1a..c70ea825 100644 --- a/crates-tauri/yaak-tauri-utils/Cargo.toml +++ b/crates-tauri/yaak-tauri-utils/Cargo.toml @@ -11,3 +11,5 @@ thiserror = { workspace = true } serde = { workspace = true, features = ["derive"] } regex = "1.11.0" yaak-common = { workspace = true } +yaak-models = { workspace = true } +log = { workspace = true } diff --git a/crates-tauri/yaak-tauri-utils/src/api_client.rs b/crates-tauri/yaak-tauri-utils/src/api_client.rs index cc308126..44cfab28 100644 --- a/crates-tauri/yaak-tauri-utils/src/api_client.rs +++ b/crates-tauri/yaak-tauri-utils/src/api_client.rs @@ -1,9 +1,12 @@ use crate::error::Result; -use reqwest::Client; +use log::{debug, warn}; +use reqwest::{Client, Proxy}; use std::time::Duration; use tauri::http::{HeaderMap, HeaderValue}; -use tauri::{AppHandle, Runtime}; +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(app_handle: &AppHandle) -> Result { let platform = get_ua_platform(); @@ -13,12 +16,58 @@ pub fn yaak_api_client(app_handle: &AppHandle) -> Result let mut default_headers = HeaderMap::new(); default_headers.insert("Accept", HeaderValue::from_str("application/json").unwrap()); - let client = reqwest::ClientBuilder::new() + let mut builder = reqwest::ClientBuilder::new() .timeout(Duration::from_secs(20)) .default_headers(default_headers) .gzip(true) - .user_agent(ua) - .build()?; + .user_agent(ua); + // Apply proxy settings from global app settings + let qm = app_handle.state::(); + 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) }