From 5ebe23abc8f51f7a29fe7a44d06926f0f8e2d851 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 17 Oct 2025 23:46:44 +0800 Subject: [PATCH] refactor: remove config file location display feature Remove the config file location display from settings dialog to simplify the user interface. Users who need to access the config file can still do so through the advanced settings section. Changes: - Removed ConfigPathDisplay component and its usage - Removed configPath and openConfigFolder from useSettings hook - Removed configPath and openConfigFolder from useSettingsMetadata hook - Removed related i18n keys: configFileLocation, openFolder - Updated settings dialog to remove the config path display section This simplifies the settings UI while maintaining access to config directory management through the advanced settings tab. --- src/components/settings/ConfigPathDisplay.tsx | 41 ------------------- src/components/settings/SettingsDialog.tsx | 7 ---- src/hooks/useSettings.ts | 6 --- src/hooks/useSettingsMetadata.ts | 33 +-------------- src/i18n/locales/en.json | 2 - src/i18n/locales/zh.json | 2 - 6 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 src/components/settings/ConfigPathDisplay.tsx diff --git a/src/components/settings/ConfigPathDisplay.tsx b/src/components/settings/ConfigPathDisplay.tsx deleted file mode 100644 index 5b13747..0000000 --- a/src/components/settings/ConfigPathDisplay.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { FolderOpen } from "lucide-react"; -import { Button } from "@/components/ui/button"; -import { useTranslation } from "react-i18next"; - -interface ConfigPathDisplayProps { - path: string; - onOpen: () => Promise | void; -} - -export function ConfigPathDisplay({ path, onOpen }: ConfigPathDisplayProps) { - const { t } = useTranslation(); - - return ( -
-
-

- {t("settings.configFileLocation")} -

-

- {t("settings.configFileLocationHint", { - defaultValue: "显示当前使用的配置文件路径。", - })} -

-
-
- - {path || t("common.loading")} - - -
-
- ); -} diff --git a/src/components/settings/SettingsDialog.tsx b/src/components/settings/SettingsDialog.tsx index b1aace9..1a219b4 100644 --- a/src/components/settings/SettingsDialog.tsx +++ b/src/components/settings/SettingsDialog.tsx @@ -13,7 +13,6 @@ import { Button } from "@/components/ui/button"; import { settingsApi } from "@/lib/api"; import { LanguageSettings } from "@/components/settings/LanguageSettings"; import { WindowSettings } from "@/components/settings/WindowSettings"; -import { ConfigPathDisplay } from "@/components/settings/ConfigPathDisplay"; import { DirectorySettings } from "@/components/settings/DirectorySettings"; import { ImportExportSection } from "@/components/settings/ImportExportSection"; import { AboutSection } from "@/components/settings/AboutSection"; @@ -38,7 +37,6 @@ export function SettingsDialog({ isLoading, isSaving, isPortable, - configPath, appConfigDir, resolvedDirs, updateSettings, @@ -48,7 +46,6 @@ export function SettingsDialog({ browseAppConfigDir, resetDirectory, resetAppConfigDir, - openConfigFolder, saveSettings, resetSettings, requiresRestart, @@ -208,10 +205,6 @@ export function SettingsDialog({ settings={settings} onChange={updateSettings} /> - ) : null} diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts index ad05f24..f880cfa 100644 --- a/src/hooks/useSettings.ts +++ b/src/hooks/useSettings.ts @@ -25,7 +25,6 @@ export interface UseSettingsResult { isLoading: boolean; isSaving: boolean; isPortable: boolean; - configPath: string; appConfigDir?: string; resolvedDirs: ResolvedDirectories; requiresRestart: boolean; @@ -36,7 +35,6 @@ export interface UseSettingsResult { browseAppConfigDir: () => Promise; resetDirectory: (app: AppType) => Promise; resetAppConfigDir: () => Promise; - openConfigFolder: () => Promise; saveSettings: () => Promise; resetSettings: () => void; acknowledgeRestart: () => void; @@ -92,11 +90,9 @@ export function useSettings(): UseSettingsResult { // 3️⃣ 元数据管理 const { - configPath, isPortable, requiresRestart, isLoading: isMetadataLoading, - openConfigFolder, acknowledgeRestart, setRequiresRestart, } = useSettingsMetadata(); @@ -195,7 +191,6 @@ export function useSettings(): UseSettingsResult { isLoading, isSaving: saveMutation.isPending, isPortable, - configPath, appConfigDir, resolvedDirs, requiresRestart, @@ -206,7 +201,6 @@ export function useSettings(): UseSettingsResult { browseAppConfigDir, resetDirectory, resetAppConfigDir, - openConfigFolder, saveSettings, resetSettings, acknowledgeRestart, diff --git a/src/hooks/useSettingsMetadata.ts b/src/hooks/useSettingsMetadata.ts index 9bfd584..b29e953 100644 --- a/src/hooks/useSettingsMetadata.ts +++ b/src/hooks/useSettingsMetadata.ts @@ -1,14 +1,10 @@ import { useCallback, useEffect, useState } from "react"; -import { useTranslation } from "react-i18next"; -import { toast } from "sonner"; import { settingsApi } from "@/lib/api"; export interface UseSettingsMetadataResult { - configPath: string; isPortable: boolean; requiresRestart: boolean; isLoading: boolean; - openConfigFolder: () => Promise; acknowledgeRestart: () => void; setRequiresRestart: (value: boolean) => void; } @@ -16,15 +12,10 @@ export interface UseSettingsMetadataResult { /** * useSettingsMetadata - 元数据管理 * 负责: - * - configPath(配置文件路径) * - isPortable(便携模式) * - requiresRestart(需要重启标志) - * - 打开配置文件夹 */ export function useSettingsMetadata(): UseSettingsMetadataResult { - const { t } = useTranslation(); - - const [configPath, setConfigPath] = useState(""); const [isPortable, setIsPortable] = useState(false); const [requiresRestart, setRequiresRestart] = useState(false); const [isLoading, setIsLoading] = useState(true); @@ -36,14 +27,10 @@ export function useSettingsMetadata(): UseSettingsMetadataResult { const load = async () => { try { - const [appConfigPath, portable] = await Promise.all([ - settingsApi.getAppConfigPath(), - settingsApi.isPortable(), - ]); + const portable = await settingsApi.isPortable(); if (!active) return; - setConfigPath(appConfigPath || ""); setIsPortable(portable); } catch (error) { console.error( @@ -63,32 +50,14 @@ export function useSettingsMetadata(): UseSettingsMetadataResult { }; }, []); - const openConfigFolder = useCallback(async () => { - try { - await settingsApi.openAppConfigFolder(); - } catch (error) { - console.error( - "[useSettingsMetadata] Failed to open config folder", - error, - ); - toast.error( - t("settings.openFolderFailed", { - defaultValue: "打开目录失败", - }), - ); - } - }, [t]); - const acknowledgeRestart = useCallback(() => { setRequiresRestart(false); }, []); return { - configPath, isPortable, requiresRestart, isLoading, - openConfigFolder, acknowledgeRestart, setRequiresRestart, }; diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index f922eef..6ea9d8b 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -107,8 +107,6 @@ "minimizeToTrayDescription": "When checked, clicking the close button will hide to system tray, otherwise the app will exit directly.", "enableClaudePluginIntegration": "Apply to Claude Code extension", "enableClaudePluginIntegrationDescription": "When enabled, the VS Code Claude Code extension provider will switch with this app", - "configFileLocation": "Configuration File Location", - "openFolder": "Open Folder", "configDirectoryOverride": "Configuration Directory Override (Advanced)", "configDirectoryDescription": "When using Claude Code or Codex in environments like WSL, you can manually specify the configuration directory in WSL to keep provider data consistent with the main environment.", "appConfigDir": "CC-Switch Configuration Directory", diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index d55ecf1..ee1c046 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -107,8 +107,6 @@ "minimizeToTrayDescription": "勾选后点击关闭按钮会隐藏到系统托盘,取消则直接退出应用。", "enableClaudePluginIntegration": "应用到 Claude Code 插件", "enableClaudePluginIntegrationDescription": "开启后 Vscode Claude Code 插件的供应商将随本软件切换", - "configFileLocation": "配置文件位置", - "openFolder": "打开文件夹", "configDirectoryOverride": "配置目录覆盖(高级)", "configDirectoryDescription": "在 WSL 等环境使用 Claude Code 或 Codex 的时候,可手动指定 WSL 里的配置目录,供应商数据与主环境保持一致。", "appConfigDir": "CC-Switch 配置目录",