diff --git a/src/config/settings/jsonc-edit.ts b/src/config/settings/jsonc-edit.ts index 7a9fe5aa..9e8d51bc 100644 --- a/src/config/settings/jsonc-edit.ts +++ b/src/config/settings/jsonc-edit.ts @@ -15,7 +15,7 @@ import type { ConfigSettingsSnapshot, } from '../../types/settings'; import { resolveConfig } from '../resolve'; -import { getConfigValueAtPath } from './registry'; +import { getConfigValueAtPath, SECRET_PATHS } from './registry'; const JSONC_FORMATTING_OPTIONS: FormattingOptions = { insertSpaces: true, @@ -337,6 +337,20 @@ export function buildConfigSettingsSnapshot( values[field.configPath] = structuredClone(rawValue != null ? rawValue : resolvedValue); } + for (const secretPath of SECRET_PATHS) { + if (Object.hasOwn(values, secretPath)) { + continue; + } + const rawValue = getConfigValueAtPath(options.rawConfig, secretPath); + const resolvedValue = getConfigValueAtPath(options.resolvedConfig, secretPath); + if ( + (typeof rawValue === 'string' && rawValue.length > 0) || + (typeof resolvedValue === 'string' && resolvedValue.length > 0) + ) { + values[secretPath] = { configured: true }; + } + } + return { configPath: options.configPath, fields: options.fields, diff --git a/src/config/settings/registry.ts b/src/config/settings/registry.ts index 956ee466..8a21aa35 100644 --- a/src/config/settings/registry.ts +++ b/src/config/settings/registry.ts @@ -93,7 +93,7 @@ const JSON_OBJECT_FIELDS = new Set([ 'subtitleSidebar.css', ]); -const SECRET_PATHS = new Set(['ai.apiKey', 'jimaku.apiKey', 'anilist.accessToken']); +export const SECRET_PATHS = new Set(['ai.apiKey', 'jimaku.apiKey', 'anilist.accessToken']); const COLOR_SUFFIXES = new Set(['Color', 'color', 'backgroundColor', 'singleColor']); const SUBTITLE_CSS_MANAGED_CONFIG_PATHS = new Set([