diff --git a/src-tauri/src/http_request.rs b/src-tauri/src/http_request.rs index 82b84898..1348d741 100644 --- a/src-tauri/src/http_request.rs +++ b/src-tauri/src/http_request.rs @@ -123,7 +123,12 @@ pub async fn send_http_request( match settings.proxy { Some(ProxySetting::Disabled) => client_builder = client_builder.no_proxy(), - Some(ProxySetting::Enabled { http, https, auth }) => { + Some(ProxySetting::Enabled { + http, + https, + auth, + disabled, + }) if !disabled => { debug!("Using proxy http={http} https={https}"); let mut proxy = Proxy::custom(move |url| { let http = if http.is_empty() { None } else { Some(http.to_owned()) }; @@ -143,7 +148,7 @@ pub async fn send_http_request( client_builder = client_builder.proxy(proxy); } - None => {} // Nothing to do for this one, as it is the default + _ => {} // Nothing to do for this one, as it is the default } // Add cookie store if specified diff --git a/src-tauri/yaak-models/src/models.rs b/src-tauri/yaak-models/src/models.rs index 970ed1f9..607734d2 100644 --- a/src-tauri/yaak-models/src/models.rs +++ b/src-tauri/yaak-models/src/models.rs @@ -31,6 +31,9 @@ macro_rules! impl_model { #[ts(export, export_to = "gen_models.ts")] pub enum ProxySetting { Enabled { + #[serde(default)] + // This was added after on so give it a default to be able to deserialize older values + disabled: bool, http: String, https: String, auth: Option, diff --git a/src-web/components/Settings/SettingsProxy.tsx b/src-web/components/Settings/SettingsProxy.tsx index f6c9bf1e..2c33f5c5 100644 --- a/src-web/components/Settings/SettingsProxy.tsx +++ b/src-web/components/Settings/SettingsProxy.tsx @@ -24,6 +24,7 @@ export function SettingsProxy() { } else if (v === 'enabled') { await patchModel(settings, { proxy: { + disabled: false, type: 'enabled', http: '', https: '', @@ -42,16 +43,42 @@ export function SettingsProxy() { /> {settings.proxy?.type === 'enabled' && ( - + { + const { proxy } = settings; + const http = proxy?.type === 'enabled' ? proxy.http : ''; + const https = proxy?.type === 'enabled' ? proxy.https : ''; + const auth = proxy?.type === 'enabled' ? proxy.auth : null; + const disabled = !enabled; + await patchModel(settings, { + proxy: { type: 'enabled', http, https, auth, disabled }, + }); + }} + /> + { - const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : ''; - const auth = settings.proxy?.type === 'enabled' ? settings.proxy.auth : null; - await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } }); + const { proxy } = settings; + const https = proxy?.type === 'enabled' ? proxy.https : ''; + const auth = proxy?.type === 'enabled' ? proxy.auth : null; + const disabled = proxy?.type === 'enabled' ? proxy.disabled : false; + await patchModel(settings, { + proxy: { + type: 'enabled', + http, + https, + auth, + disabled, + }, + }); }} /> { - const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : ''; - const auth = settings.proxy?.type === 'enabled' ? settings.proxy.auth : null; - await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } }); + const { proxy } = settings; + const http = proxy?.type === 'enabled' ? proxy.http : ''; + const auth = proxy?.type === 'enabled' ? proxy.auth : null; + const disabled = proxy?.type === 'enabled' ? proxy.disabled : false; + await patchModel(settings, { + proxy: { type: 'enabled', http, https, auth, disabled }, + }); }} /> @@ -71,10 +102,14 @@ export function SettingsProxy() { checked={settings.proxy.auth != null} title="Enable authentication" onChange={async (enabled) => { - const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : ''; - const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : ''; + const { proxy } = settings; + const http = proxy?.type === 'enabled' ? proxy.http : ''; + const https = proxy?.type === 'enabled' ? proxy.https : ''; + const disabled = proxy?.type === 'enabled' ? proxy.disabled : false; const auth = enabled ? { user: '', password: '' } : null; - await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } }); + await patchModel(settings, { + proxy: { type: 'enabled', http, https, auth, disabled }, + }); }} /> @@ -87,12 +122,15 @@ export function SettingsProxy() { placeholder="myUser" defaultValue={settings.proxy.auth.user} onChange={async (user) => { - const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : ''; - const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : ''; - const password = - settings.proxy?.type === 'enabled' ? (settings.proxy.auth?.password ?? '') : ''; + const { proxy } = settings; + const http = proxy?.type === 'enabled' ? proxy.http : ''; + const https = proxy?.type === 'enabled' ? proxy.https : ''; + const disabled = proxy?.type === 'enabled' ? proxy.disabled : false; + const password = proxy?.type === 'enabled' ? (proxy.auth?.password ?? '') : ''; const auth = { user, password }; - await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } }); + await patchModel(settings, { + proxy: { type: 'enabled', http, https, auth, disabled }, + }); }} /> { - const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : ''; - const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : ''; - const user = - settings.proxy?.type === 'enabled' ? (settings.proxy.auth?.user ?? '') : ''; + const { proxy } = settings; + const http = proxy?.type === 'enabled' ? proxy.http : ''; + const https = proxy?.type === 'enabled' ? proxy.https : ''; + const disabled = proxy?.type === 'enabled' ? proxy.disabled : false; + const user = proxy?.type === 'enabled' ? (proxy.auth?.user ?? '') : ''; const auth = { user, password }; - await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } }); + await patchModel(settings, { + proxy: { type: 'enabled', http, https, auth, disabled }, + }); }} />