mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 02:05:57 +08:00
refactor(common-config): consolidate hasContent methods into adapters
- Add hasContent method to CommonConfigAdapter interface - Move isSubset utility to configMerge.ts for reuse - Export preserveCodexConfigFormat from adapters for hook use - Add hasContentByAppType dispatcher for unified content detection - Remove dead code from providerConfigUtils (hasCommonConfigSnippet, hasTomlCommonConfigSnippet, hasGeminiCommonConfigSnippet)
This commit is contained in:
+5
-21
@@ -2,11 +2,7 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { Provider } from "@/types";
|
||||
import { providersApi } from "./providers";
|
||||
import {
|
||||
hasCommonConfigSnippet,
|
||||
hasTomlCommonConfigSnippet,
|
||||
hasGeminiCommonConfigSnippet,
|
||||
} from "@/utils/providerConfigUtils";
|
||||
import { hasContentByAppType } from "@/hooks/commonConfigAdapters";
|
||||
|
||||
export type AppType = "claude" | "codex" | "gemini";
|
||||
|
||||
@@ -358,22 +354,10 @@ function detectCommonConfigEnabledByContent(
|
||||
);
|
||||
if (candidates.length === 0) return false;
|
||||
|
||||
switch (appType) {
|
||||
case "codex":
|
||||
return candidates.some((snippet) =>
|
||||
hasTomlCommonConfigSnippet(settingsConfigStr, snippet),
|
||||
);
|
||||
case "gemini":
|
||||
return candidates.some((snippet) =>
|
||||
hasGeminiCommonConfigSnippet(settingsConfigStr, snippet),
|
||||
);
|
||||
case "claude":
|
||||
return candidates.some((snippet) =>
|
||||
hasCommonConfigSnippet(settingsConfigStr, snippet),
|
||||
);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
// 使用统一的 adapter-based hasContent 检查
|
||||
return candidates.some((snippet) =>
|
||||
hasContentByAppType(appType, settingsConfigStr, snippet),
|
||||
);
|
||||
}
|
||||
|
||||
/** 更新供应商配置的结果 */
|
||||
|
||||
Reference in New Issue
Block a user