import { useState, useEffect } from 'react'; import { invoke } from '@tauri-apps/api/core'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Switch } from '@/components/ui/switch'; export interface ProxySettings { http_proxy: string | null; https_proxy: string | null; no_proxy: string | null; all_proxy: string | null; enabled: boolean; } interface ProxySettingsProps { setToast: (toast: { message: string; type: 'success' | 'error' } | null) => void; onChange?: (hasChanges: boolean, getSettings: () => ProxySettings, saveSettings: () => Promise) => void; } export function ProxySettings({ setToast, onChange }: ProxySettingsProps) { const [settings, setSettings] = useState({ http_proxy: null, https_proxy: null, no_proxy: null, all_proxy: null, enabled: false, }); const [originalSettings, setOriginalSettings] = useState({ http_proxy: null, https_proxy: null, no_proxy: null, all_proxy: null, enabled: false, }); useEffect(() => { loadSettings(); }, []); // Save settings function const saveSettings = async () => { try { await invoke('save_proxy_settings', { settings }); setOriginalSettings(settings); setToast({ message: 'Proxy settings saved and applied successfully.', type: 'success', }); } catch (error) { console.error('Failed to save proxy settings:', error); setToast({ message: 'Failed to save proxy settings', type: 'error', }); throw error; // Re-throw to let parent handle the error } }; // Notify parent component of changes useEffect(() => { if (onChange) { const hasChanges = JSON.stringify(settings) !== JSON.stringify(originalSettings); onChange(hasChanges, () => settings, saveSettings); } }, [settings, originalSettings, onChange]); const loadSettings = async () => { try { const loadedSettings = await invoke('get_proxy_settings'); setSettings(loadedSettings); setOriginalSettings(loadedSettings); } catch (error) { console.error('Failed to load proxy settings:', error); setToast({ message: 'Failed to load proxy settings', type: 'error', }); } }; const handleInputChange = (field: keyof ProxySettings, value: string) => { setSettings(prev => ({ ...prev, [field]: value || null, })); }; return (

Proxy Settings

Configure proxy settings for Claude API requests

Use proxy for all Claude API requests

setSettings(prev => ({ ...prev, enabled: checked }))} />
handleInputChange('http_proxy', e.target.value)} disabled={!settings.enabled} />
handleInputChange('https_proxy', e.target.value)} disabled={!settings.enabled} />
handleInputChange('no_proxy', e.target.value)} disabled={!settings.enabled} />

Comma-separated list of hosts that should bypass the proxy

handleInputChange('all_proxy', e.target.value)} disabled={!settings.enabled} />

Proxy URL to use for all protocols if protocol-specific proxies are not set

); }