This commit is contained in:
2025-08-06 15:39:05 +08:00
parent 351a79d54c
commit 6798be3b42
26 changed files with 1243 additions and 469 deletions

View File

@@ -3,6 +3,7 @@ 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';
import { useTranslation } from '@/hooks/useTranslation';
export interface ProxySettings {
http_proxy: string | null;
@@ -18,6 +19,7 @@ interface ProxySettingsProps {
}
export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
const { t } = useTranslation();
const [settings, setSettings] = useState<ProxySettings>({
http_proxy: null,
https_proxy: null,
@@ -43,13 +45,13 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
await invoke('save_proxy_settings', { settings });
setOriginalSettings(settings);
setToast({
message: 'Proxy settings saved and applied successfully.',
message: t('settings.proxySettingsSaved'),
type: 'success',
});
} catch (error) {
console.error('Failed to save proxy settings:', error);
setToast({
message: 'Failed to save proxy settings',
message: t('settings.saveProxySettingsFailed'),
type: 'error',
});
throw error; // Re-throw to let parent handle the error
@@ -72,7 +74,7 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
} catch (error) {
console.error('Failed to load proxy settings:', error);
setToast({
message: 'Failed to load proxy settings',
message: t('settings.loadProxySettingsFailed'),
type: 'error',
});
}
@@ -89,18 +91,18 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
return (
<div className="space-y-6">
<div>
<h3 className="text-lg font-medium">Proxy Settings</h3>
<h3 className="text-lg font-medium">{t('settings.proxySettingsTitle')}</h3>
<p className="text-sm text-muted-foreground">
Configure proxy settings for Claude API requests
{t('settings.proxySettingsDesc')}
</p>
</div>
<div className="space-y-4">
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<Label htmlFor="proxy-enabled">Enable Proxy</Label>
<Label htmlFor="proxy-enabled">{t('settings.enableProxy')}</Label>
<p className="text-sm text-muted-foreground">
Use proxy for all Claude API requests
{t('settings.enableProxyDesc')}
</p>
</div>
<Switch
@@ -112,7 +114,7 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
<div className="space-y-4" style={{ opacity: settings.enabled ? 1 : 0.5 }}>
<div className="space-y-2">
<Label htmlFor="http-proxy">HTTP Proxy</Label>
<Label htmlFor="http-proxy">{t('settings.httpProxy')}</Label>
<Input
id="http-proxy"
placeholder="http://proxy.example.com:8080"
@@ -123,7 +125,7 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
</div>
<div className="space-y-2">
<Label htmlFor="https-proxy">HTTPS Proxy</Label>
<Label htmlFor="https-proxy">{t('settings.httpsProxy')}</Label>
<Input
id="https-proxy"
placeholder="http://proxy.example.com:8080"
@@ -134,7 +136,7 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
</div>
<div className="space-y-2">
<Label htmlFor="no-proxy">No Proxy</Label>
<Label htmlFor="no-proxy">{t('settings.noProxy')}</Label>
<Input
id="no-proxy"
placeholder="localhost,127.0.0.1,.example.com"
@@ -143,12 +145,12 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
disabled={!settings.enabled}
/>
<p className="text-xs text-muted-foreground">
Comma-separated list of hosts that should bypass the proxy
{t('settings.noProxyDesc')}
</p>
</div>
<div className="space-y-2">
<Label htmlFor="all-proxy">All Proxy (Optional)</Label>
<Label htmlFor="all-proxy">All Proxy ({t('agents.optional')})</Label>
<Input
id="all-proxy"
placeholder="socks5://proxy.example.com:1080"
@@ -157,7 +159,7 @@ export function ProxySettings({ setToast, onChange }: ProxySettingsProps) {
disabled={!settings.enabled}
/>
<p className="text-xs text-muted-foreground">
Proxy URL to use for all protocols if protocol-specific proxies are not set
{t('settings.allProxyDesc')}
</p>
</div>
</div>