mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 09:51:10 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -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]]
|
||||
|
||||
@@ -118,7 +118,7 @@ pub async fn activate_license<R: Runtime>(
|
||||
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<R: Runtime>(window: &WebviewWindow<R>) -> 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(),
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Client> {
|
||||
let platform = get_ua_platform();
|
||||
@@ -13,12 +16,58 @@ pub fn yaak_api_client<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Client>
|
||||
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::<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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user