feat: complete stage 4 cleanup and code formatting
This commit completes stage 4 of the refactoring plan, focusing on cleanup and optimization of the modernized codebase. ## Key Changes ### Code Cleanup - Remove legacy `src/lib/styles.ts` (no longer needed) - Remove old modal components (`ImportProgressModal.tsx`, `ProviderList.tsx`) - Streamline `src/lib/tauri-api.ts` from 712 lines to 17 lines (-97.6%) - Remove global `window.api` pollution - Keep only event listeners (`tauriEvents.onProviderSwitched`) - All API calls now use modular `@/lib/api/*` layer ### Type System - Clean up `src/vite-env.d.ts` (remove 156 lines of outdated types) - Remove obsolete global type declarations - All TypeScript checks pass with zero errors ### Code Formatting - Format all source files with Prettier (82 files) - Fix formatting issues in 15 files: - App.tsx and core components - MCP management components - Settings module components - Provider management components - UI components ### Documentation Updates - Update `REFACTORING_CHECKLIST.md` with stage 4 progress - Mark completed tasks in `REFACTORING_MASTER_PLAN.md` ## Impact **Code Reduction:** - Total: -1,753 lines, +384 lines (net -1,369 lines) - tauri-api.ts: 712 → 17 lines (-97.6%) - Removed styles.ts: -82 lines - Removed vite-env.d.ts declarations: -156 lines **Quality Improvements:** - ✅ Zero TypeScript errors - ✅ Zero TODO/FIXME comments - ✅ 100% Prettier compliant - ✅ Zero `window.api` references - ✅ Fully modular API layer ## Testing - [x] TypeScript compilation passes - [x] Code formatting validated - [x] No linting errors Stage 4 completion: 100% Ready for stage 5 (testing and bug fixes)
This commit is contained in:
@@ -62,12 +62,17 @@ const computeDefaultAppConfigDir = async (): Promise<string | undefined> => {
|
||||
const home = await homeDir();
|
||||
return await join(home, ".cc-switch");
|
||||
} catch (error) {
|
||||
console.error("[useSettings] Failed to resolve default app config dir", error);
|
||||
console.error(
|
||||
"[useSettings] Failed to resolve default app config dir",
|
||||
error,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const computeDefaultConfigDir = async (app: AppType): Promise<string | undefined> => {
|
||||
const computeDefaultConfigDir = async (
|
||||
app: AppType,
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const home = await homeDir();
|
||||
const folder = app === "claude" ? ".claude" : ".codex";
|
||||
@@ -83,8 +88,12 @@ export function useSettings(): UseSettingsResult {
|
||||
const { data, isLoading } = useSettingsQuery();
|
||||
const saveMutation = useSaveSettingsMutation();
|
||||
|
||||
const [settingsState, setSettingsState] = useState<SettingsFormState | null>(null);
|
||||
const [appConfigDir, setAppConfigDir] = useState<string | undefined>(undefined);
|
||||
const [settingsState, setSettingsState] = useState<SettingsFormState | null>(
|
||||
null,
|
||||
);
|
||||
const [appConfigDir, setAppConfigDir] = useState<string | undefined>(
|
||||
undefined,
|
||||
);
|
||||
const [configPath, setConfigPath] = useState("");
|
||||
const [isPortable, setIsPortable] = useState(false);
|
||||
const [requiresRestart, setRequiresRestart] = useState(false);
|
||||
@@ -135,7 +144,8 @@ export function useSettings(): UseSettingsResult {
|
||||
...data,
|
||||
showInTray: data.showInTray ?? true,
|
||||
minimizeToTrayOnClose: data.minimizeToTrayOnClose ?? true,
|
||||
enableClaudePluginIntegration: data.enableClaudePluginIntegration ?? false,
|
||||
enableClaudePluginIntegration:
|
||||
data.enableClaudePluginIntegration ?? false,
|
||||
claudeConfigDir: sanitizeDir(data.claudeConfigDir),
|
||||
codexConfigDir: sanitizeDir(data.codexConfigDir),
|
||||
language: normalizedLanguage,
|
||||
@@ -286,8 +296,8 @@ export function useSettings(): UseSettingsResult {
|
||||
const key: DirectoryKey = app === "claude" ? "claude" : "codex";
|
||||
const currentValue =
|
||||
key === "claude"
|
||||
? settingsState?.claudeConfigDir ?? resolvedDirs.claude
|
||||
: settingsState?.codexConfigDir ?? resolvedDirs.codex;
|
||||
? (settingsState?.claudeConfigDir ?? resolvedDirs.claude)
|
||||
: (settingsState?.codexConfigDir ?? resolvedDirs.codex);
|
||||
|
||||
try {
|
||||
const picked = await settingsApi.selectConfigDirectory(currentValue);
|
||||
@@ -377,7 +387,8 @@ export function useSettings(): UseSettingsResult {
|
||||
...data,
|
||||
showInTray: data.showInTray ?? true,
|
||||
minimizeToTrayOnClose: data.minimizeToTrayOnClose ?? true,
|
||||
enableClaudePluginIntegration: data.enableClaudePluginIntegration ?? false,
|
||||
enableClaudePluginIntegration:
|
||||
data.enableClaudePluginIntegration ?? false,
|
||||
claudeConfigDir: sanitizeDir(data.claudeConfigDir),
|
||||
codexConfigDir: sanitizeDir(data.codexConfigDir),
|
||||
language: normalizedLanguage,
|
||||
@@ -387,7 +398,8 @@ export function useSettings(): UseSettingsResult {
|
||||
syncLanguage(initialLanguageRef.current);
|
||||
setAppConfigDir(initialAppConfigDirRef.current);
|
||||
setResolvedDirs({
|
||||
appConfig: initialAppConfigDirRef.current ?? defaultsRef.current.appConfig,
|
||||
appConfig:
|
||||
initialAppConfigDirRef.current ?? defaultsRef.current.appConfig,
|
||||
claude: normalized.claudeConfigDir ?? defaultsRef.current.claude,
|
||||
codex: normalized.codexConfigDir ?? defaultsRef.current.codex,
|
||||
});
|
||||
@@ -423,7 +435,10 @@ export function useSettings(): UseSettingsResult {
|
||||
await settingsApi.applyClaudePluginConfig({ official: true });
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("[useSettings] Failed to sync Claude plugin config", error);
|
||||
console.warn(
|
||||
"[useSettings] Failed to sync Claude plugin config",
|
||||
error,
|
||||
);
|
||||
toast.error(
|
||||
t("notifications.syncClaudePluginFailed", {
|
||||
defaultValue: "同步 Claude 插件失败",
|
||||
@@ -436,7 +451,10 @@ export function useSettings(): UseSettingsResult {
|
||||
window.localStorage.setItem("language", payload.language as Language);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("[useSettings] Failed to persist language preference", error);
|
||||
console.warn(
|
||||
"[useSettings] Failed to persist language preference",
|
||||
error,
|
||||
);
|
||||
}
|
||||
|
||||
initialLanguageRef.current = payload.language as Language;
|
||||
|
||||
Reference in New Issue
Block a user