From 032a8203fdc53aab0a7d7a553ea6c5d999247660 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 8 Mar 2026 22:25:48 +0800 Subject: [PATCH] feat: show failover toggle independently on main page with confirm dialog Add enableFailoverToggle setting to control failover toggle visibility on the main page, decoupled from proxy takeover state. First-time enable shows a ConfirmDialog (same pattern as proxy toggle). The toggle row is placed in the Auto Failover accordion section in settings. --- src-tauri/src/settings.rs | 8 ++++ src/App.tsx | 18 +++------ src/components/settings/ProxyTabContent.tsx | 41 ++++++++++++++++++++- src/i18n/locales/en.json | 7 ++++ src/i18n/locales/ja.json | 7 ++++ src/i18n/locales/zh.json | 7 ++++ src/types.ts | 4 ++ 7 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rs index 8dbba9d1e..2358e622f 100644 --- a/src-tauri/src/settings.rs +++ b/src-tauri/src/settings.rs @@ -199,6 +199,12 @@ pub struct AppSettings { /// User has confirmed the stream check first-run notice #[serde(default, skip_serializing_if = "Option::is_none")] pub stream_check_confirmed: Option, + /// Whether to show the failover toggle independently on the main page + #[serde(default)] + pub enable_failover_toggle: bool, + /// User has confirmed the failover toggle first-run notice + #[serde(default, skip_serializing_if = "Option::is_none")] + pub failover_confirmed: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub language: Option, @@ -286,6 +292,8 @@ impl Default for AppSettings { proxy_confirmed: None, usage_confirmed: None, stream_check_confirmed: None, + enable_failover_toggle: false, + failover_confirmed: None, language: None, visible_apps: None, claude_config_dir: None, diff --git a/src/App.tsx b/src/App.tsx index 671b62373..76445a7d2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -981,23 +981,17 @@ function App() {
{currentView === "providers" && activeApp !== "opencode" && - activeApp !== "openclaw" && - settingsData?.enableLocalProxy && ( + activeApp !== "openclaw" && (
- -
+ {settingsData?.enableLocalProxy && ( + + )} + {settingsData?.enableFailoverToggle && ( -
+ )}
)}
{ + if (checked && !settings?.failoverConfirmed) { + setShowFailoverConfirm(true); + } else { + void onAutoSave({ enableFailoverToggle: checked }); + } + }; + + const handleFailoverConfirm = async () => { + setShowFailoverConfirm(false); + try { + await onAutoSave({ failoverConfirmed: true, enableFailoverToggle: true }); + } catch (error) { + console.error("Failover confirm failed:", error); + } + }; + return (
+ } + title={t("settings.advanced.proxy.enableFailoverToggle")} + description={t( + "settings.advanced.proxy.enableFailoverToggleDescription", + )} + checked={settings?.enableFailoverToggle ?? false} + onCheckedChange={handleFailoverToggleChange} + /> + {!isRunning && (

@@ -274,6 +303,16 @@ export function ProxyTabContent({ onConfirm={() => void handleProxyConfirm()} onCancel={() => setShowProxyConfirm(false)} /> + + void handleFailoverConfirm()} + onCancel={() => setShowFailoverConfirm(false)} + /> ); } diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 4571f452b..37b3a972c 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -190,6 +190,11 @@ "message": "Local proxy is an advanced feature. Please make sure you understand how it works before enabling.\n\nWe recommend consulting the relevant documentation or your provider for proper configuration.", "confirm": "I understand, enable" }, + "failover": { + "title": "Enable Failover", + "message": "Failover is an advanced feature. Please make sure you understand how it works before enabling.\n\nWe recommend configuring provider priorities in the failover queue first.", + "confirm": "I understand, enable" + }, "usage": { "title": "Configure Usage Query", "message": "Usage query requires a custom script or API parameters. Please make sure you have obtained the necessary information from your provider.\n\nIf unsure how to configure, please consult your provider's documentation first.", @@ -222,6 +227,8 @@ "description": "Control proxy service toggle, view status and port info", "enableFeature": "Show Proxy Toggle on Main Page", "enableFeatureDescription": "When enabled, the proxy and failover toggles will appear at the top of the main page", + "enableFailoverToggle": "Show Failover Toggle on Main Page", + "enableFailoverToggleDescription": "When enabled, the failover toggle will appear independently at the top of the main page", "running": "Running", "stopped": "Stopped" }, diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index 336a4970e..536c6614c 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -190,6 +190,11 @@ "message": "ローカルプロキシは上級機能です。有効にする前に、その仕組みを理解していることをご確認ください。\n\n適切な設定方法については、関連ドキュメントまたはプロバイダーにご相談ください。", "confirm": "理解しました、有効にする" }, + "failover": { + "title": "フェイルオーバーの有効化", + "message": "フェイルオーバーは上級機能です。有効にする前に、その仕組みを理解していることをご確認ください。\n\nフェイルオーバーキューでプロバイダーの優先順位を先に設定することをお勧めします。", + "confirm": "理解しました、有効にする" + }, "usage": { "title": "使用量クエリの設定", "message": "使用量クエリにはカスタムスクリプトまたは API パラメータが必要です。プロバイダーから必要な情報を取得していることをご確認ください。\n\n設定方法が不明な場合は、プロバイダーのドキュメントを先にご確認ください。", @@ -222,6 +227,8 @@ "description": "プロキシサービスの切り替え、ステータスとポート情報を表示", "enableFeature": "メインページにプロキシ切り替えを表示", "enableFeatureDescription": "有効にすると、メインページ上部にプロキシとフェイルオーバーの切り替えが表示されます", + "enableFailoverToggle": "メインページにフェイルオーバー切り替えを表示", + "enableFailoverToggleDescription": "有効にすると、メインページ上部にフェイルオーバー切り替えが独立して表示されます", "running": "実行中", "stopped": "停止中" }, diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index aa5c881d5..215e05f07 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -190,6 +190,11 @@ "message": "本地代理是一项高级功能,启用前请确保您已了解其工作原理。\n\n建议先查阅相关文档或咨询您的供应商,以获取正确的配置方式。", "confirm": "我已了解,继续启用" }, + "failover": { + "title": "启用故障转移功能", + "message": "故障转移是一项高级功能,启用前请确保您已了解其工作原理。\n\n建议先在故障转移队列中配置好供应商优先级。", + "confirm": "我已了解,继续启用" + }, "usage": { "title": "配置用量查询", "message": "用量查询需要配置专用的查询脚本或 API 参数,请确保您已从供应商处获取相关信息。\n\n如不确定如何配置,请先查阅供应商文档。", @@ -222,6 +227,8 @@ "description": "控制代理服务开关、查看状态与端口信息", "enableFeature": "在主页面显示本地代理开关", "enableFeatureDescription": "开启后,主页面顶部将显示代理和故障转移开关", + "enableFailoverToggle": "在主页面显示故障转移开关", + "enableFailoverToggleDescription": "开启后,主页面顶部将独立显示故障转移开关", "running": "运行中", "stopped": "已停止" }, diff --git a/src/types.ts b/src/types.ts index c71035546..5b1e2d692 100644 --- a/src/types.ts +++ b/src/types.ts @@ -233,6 +233,10 @@ export interface Settings { usageConfirmed?: boolean; // User has confirmed the stream check first-run notice streamCheckConfirmed?: boolean; + // Whether to show the failover toggle independently on the main page + enableFailoverToggle?: boolean; + // User has confirmed the failover toggle first-run notice + failoverConfirmed?: boolean; // User has confirmed the auto-sync traffic warning autoSyncConfirmed?: boolean; // 首选语言(可选,默认中文)