mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-28 09:10:18 +08:00
fix: common config checkbox state not persisting for Codex/Claude/Gemini (#2191)
修复:Codex/Claude/Gemini 通用配置勾选状态无法正确保存的问题 Co-authored-by: 曾兴 <zengx@gantsoftware.com>
This commit is contained in:
@@ -160,9 +160,13 @@ export function useCodexCommonConfig({
|
||||
config,
|
||||
commonConfigSnippet,
|
||||
);
|
||||
const hasCommon = initialEnabled ?? inferredHasCommon;
|
||||
|
||||
if (hasCommon && !inferredHasCommon) {
|
||||
// 优先级:显式设置的 initialEnabled > 从配置推断的值
|
||||
// 如果 initialEnabled 为 undefined,使用推断值
|
||||
const hasCommon = initialEnabled !== undefined ? initialEnabled : inferredHasCommon;
|
||||
|
||||
// 如果应该启用通用配置但配置中还没有,则自动添加
|
||||
if (hasCommon && !inferredHasCommon && parsedSnippet.hasContent) {
|
||||
const { updatedConfig, error } = updateTomlCommonConfigSnippet(
|
||||
codexConfig,
|
||||
commonConfigSnippet,
|
||||
|
||||
@@ -118,17 +118,22 @@ export function useCommonConfigSnippet({
|
||||
// 初始化时检查通用配置片段(编辑模式)
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
if (initialData && !isLoading) {
|
||||
if (initialData && !isLoading && !hasInitializedEditMode.current) {
|
||||
hasInitializedEditMode.current = true;
|
||||
|
||||
const configString = JSON.stringify(initialData.settingsConfig, null, 2);
|
||||
const inferredHasCommon = hasCommonConfigSnippet(
|
||||
configString,
|
||||
commonConfigSnippet,
|
||||
);
|
||||
const hasCommon = initialEnabled ?? inferredHasCommon;
|
||||
|
||||
// 优先级:显式设置的 initialEnabled > 从配置推断的值
|
||||
// 如果 initialEnabled 为 undefined,使用推断值
|
||||
const hasCommon = initialEnabled !== undefined ? initialEnabled : inferredHasCommon;
|
||||
setUseCommonConfig(hasCommon);
|
||||
|
||||
if (hasCommon && !inferredHasCommon && !hasInitializedEditMode.current) {
|
||||
hasInitializedEditMode.current = true;
|
||||
// 如果应该启用通用配置但配置中还没有,则自动添加
|
||||
if (hasCommon && !inferredHasCommon) {
|
||||
const { updatedConfig, error } = updateCommonConfigSnippet(
|
||||
settingsConfig,
|
||||
commonConfigSnippet,
|
||||
@@ -141,8 +146,6 @@ export function useCommonConfigSnippet({
|
||||
isUpdatingFromCommonConfig.current = false;
|
||||
}, 0);
|
||||
}
|
||||
} else {
|
||||
hasInitializedEditMode.current = true;
|
||||
}
|
||||
}
|
||||
}, [
|
||||
|
||||
@@ -244,9 +244,13 @@ export function useGeminiCommonConfig({
|
||||
env,
|
||||
parsed.env as Record<string, string>,
|
||||
);
|
||||
const hasCommon = initialEnabled ?? inferredHasCommon;
|
||||
|
||||
if (hasCommon && !inferredHasCommon) {
|
||||
// 优先级:显式设置的 initialEnabled > 从配置推断的值
|
||||
// 如果 initialEnabled 为 undefined,使用推断值
|
||||
const hasCommon = initialEnabled !== undefined ? initialEnabled : inferredHasCommon;
|
||||
|
||||
// 如果应该启用通用配置但配置中还没有,则自动添加
|
||||
if (hasCommon && !inferredHasCommon && Object.keys(parsed.env).length > 0) {
|
||||
const currentEnv = envStringToObj(envValue);
|
||||
const merged = applySnippetToEnv(currentEnv, parsed.env);
|
||||
const nextEnvString = envObjToString(merged);
|
||||
|
||||
Reference in New Issue
Block a user