From 754d31df4782f053924bee6793a7cd30651a7515 Mon Sep 17 00:00:00 2001 From: su-fen <715041@qq.com> Date: Tue, 21 Jul 2026 11:09:52 +0800 Subject: [PATCH] fix(updater): route update check/download/install through the app proxy github_client() already followed the app proxy for manifest lookup, but build_updater() left tauri-plugin-updater's own client untouched, so the authoritative check() and download_and_install() connected to GitHub directly (or silently picked up unrelated OS proxy env vars). Resolve the same app-proxy config into a Url for the updater builder so the whole update flow behaves consistently. Co-Authored-By: Claude Sonnet 5 --- .../src-tauri/src/commands/app/update.rs | 7 ++++ .../src-tauri/src/services/system_proxy.rs | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/crates/agent-gui/src-tauri/src/commands/app/update.rs b/crates/agent-gui/src-tauri/src/commands/app/update.rs index 21644d880..e9ca758a7 100644 --- a/crates/agent-gui/src-tauri/src/commands/app/update.rs +++ b/crates/agent-gui/src-tauri/src/commands/app/update.rs @@ -452,6 +452,13 @@ fn build_updater( builder = builder.pubkey(public_key); } + // 更新下载/安装与 github_client() 的探测请求保持同一份应用代理配置;未启用时 + // 显式 no_proxy(),避免插件内部 client 兜底读取 OS 代理环境变量。 + builder = match crate::services::system_proxy::current_proxy_url()? { + Some(proxy_url) => builder.proxy(proxy_url), + None => builder.no_proxy(), + }; + builder .endpoints(vec![manifest_url]) .map_err(|error| format!("invalid updater endpoint: {error}"))? diff --git a/crates/agent-gui/src-tauri/src/services/system_proxy.rs b/crates/agent-gui/src-tauri/src/services/system_proxy.rs index fc06be8af..8534f8cf5 100644 --- a/crates/agent-gui/src-tauri/src/services/system_proxy.rs +++ b/crates/agent-gui/src-tauri/src/services/system_proxy.rs @@ -282,6 +282,21 @@ pub fn blocking_client_builder() -> Result Result, String> { + match current_snapshot().mode { + ProxyMode::Disabled => Ok(None), + ProxyMode::Invalid(error) => Err(error), + ProxyMode::Enabled(config) => reqwest::Url::parse(&config.proxy_url()) + .map(Some) + .map_err(|_| format!("应用代理地址无效:{}", config.display_target())), + } +} + #[cfg(test)] mod tests { use super::*; @@ -403,4 +418,28 @@ mod tests { .expect("disabled proxy envs") .is_empty()); } + + #[test] + fn current_proxy_url_reflects_mode() { + set_config(None); + assert_eq!(current_proxy_url().expect("disabled proxy url"), None); + + set_config(Some(&json!({ + "enabled": true, "type": "http", "host": "proxy.local", "port": 8080 + }))); + assert_eq!( + current_proxy_url() + .expect("enabled proxy url") + .map(|url| url.to_string()), + Some("http://proxy.local:8080/".to_string()) + ); + + set_config(Some(&json!({ + "enabled": true, "type": "http", "host": "bad host/@", "port": 8080 + }))); + assert!(current_proxy_url().is_err()); + + // reset so other tests in this module observe the default disabled state + set_config(None); + } }