feat: add proxy configuration support

- Add proxy settings UI component with enable/disable toggle
  - Support HTTP, HTTPS, NO_PROXY, and ALL_PROXY environment variables
  - Store proxy settings in app database for persistence
  - Apply proxy settings on app startup and when saved
  - Pass proxy environment variables to Claude command execution
  - Integrate proxy settings into main Settings page with unified save
  - Add proxy support for both system binary and sidecar execution

  This allows users to configure proxy settings for Claude API requests,
  which is essential for users behind corporate firewalls or in regions
  requiring proxy access.

  Fixes network connectivity issues in restricted environments.
This commit is contained in:
Catherine
2025-07-11 13:23:33 +08:00
committed by Vivek R
parent 67800087e9
commit 32a197100a
9 changed files with 715 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ use commands::storage::{
storage_list_tables, storage_read_table, storage_update_row, storage_delete_row,
storage_insert_row, storage_execute_sql, storage_reset_database,
};
use commands::proxy::{get_proxy_settings, save_proxy_settings, apply_proxy_settings};
use process::ProcessRegistryState;
use std::sync::Mutex;
use tauri::Manager;
@@ -57,6 +58,55 @@ fn main() {
.setup(|app| {
// Initialize agents database
let conn = init_database(&app.handle()).expect("Failed to initialize agents database");
// Load and apply proxy settings from the database
{
let db = AgentDb(Mutex::new(conn));
let proxy_settings = match db.0.lock() {
Ok(conn) => {
// Directly query proxy settings from the database
let mut settings = commands::proxy::ProxySettings::default();
let keys = vec![
("proxy_enabled", "enabled"),
("proxy_http", "http_proxy"),
("proxy_https", "https_proxy"),
("proxy_no", "no_proxy"),
("proxy_all", "all_proxy"),
];
for (db_key, field) in keys {
if let Ok(value) = conn.query_row(
"SELECT value FROM app_settings WHERE key = ?1",
rusqlite::params![db_key],
|row| row.get::<_, String>(0),
) {
match field {
"enabled" => settings.enabled = value == "true",
"http_proxy" => settings.http_proxy = Some(value).filter(|s| !s.is_empty()),
"https_proxy" => settings.https_proxy = Some(value).filter(|s| !s.is_empty()),
"no_proxy" => settings.no_proxy = Some(value).filter(|s| !s.is_empty()),
"all_proxy" => settings.all_proxy = Some(value).filter(|s| !s.is_empty()),
_ => {}
}
}
}
log::info!("Loaded proxy settings: enabled={}", settings.enabled);
settings
}
Err(e) => {
log::warn!("Failed to lock database for proxy settings: {}", e);
commands::proxy::ProxySettings::default()
}
};
// Apply the proxy settings
apply_proxy_settings(&proxy_settings);
}
// Re-open the connection for the app to manage
let conn = init_database(&app.handle()).expect("Failed to initialize agents database");
app.manage(AgentDb(Mutex::new(conn)));
// Initialize checkpoint state
@@ -195,6 +245,10 @@ fn main() {
commands::slash_commands::slash_command_get,
commands::slash_commands::slash_command_save,
commands::slash_commands::slash_command_delete,
// Proxy Settings
get_proxy_settings,
save_proxy_settings,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");