From 709ce4c8dd9bc1e0e39f5a24e23ef14bc6a9e607 Mon Sep 17 00:00:00 2001 From: LTbinglingfeng Date: Sat, 7 Feb 2026 12:31:17 +0800 Subject: [PATCH] feat(config): warn restart required when commercial mode changes --- src/i18n/locales/en.json | 1 + src/i18n/locales/ru.json | 1 + src/i18n/locales/zh-CN.json | 1 + src/pages/ConfigPage.tsx | 17 +++++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index e5d4001..668d118 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -1094,6 +1094,7 @@ "gemini_api_key": "Gemini API key", "codex_api_key": "Codex API key", "claude_api_key": "Claude API key", + "commercial_mode_restart_required": "Commercial mode setting changed. Please restart the service for it to take effect", "copy_failed": "Copy failed", "link_copied": "Link copied to clipboard" }, diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 80c0b9f..7b62437 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -1099,6 +1099,7 @@ "gemini_api_key": "API-ключ Gemini", "codex_api_key": "API-ключ Codex", "claude_api_key": "API-ключ Claude", + "commercial_mode_restart_required": "Режим коммерческого использования изменён. Перезапустите сервис, чтобы применить изменения", "copy_failed": "Не удалось скопировать", "link_copied": "Ссылка скопирована в буфер обмена" }, diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 014f25d..6bf2332 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -1094,6 +1094,7 @@ "gemini_api_key": "Gemini API密钥", "codex_api_key": "Codex API密钥", "claude_api_key": "Claude API密钥", + "commercial_mode_restart_required": "商业模式开关已变更,请重启服务后生效", "copy_failed": "复制失败", "link_copied": "已复制" }, diff --git a/src/pages/ConfigPage.tsx b/src/pages/ConfigPage.tsx index eaf9442..0191c31 100644 --- a/src/pages/ConfigPage.tsx +++ b/src/pages/ConfigPage.tsx @@ -5,6 +5,7 @@ import CodeMirror, { ReactCodeMirrorRef } from '@uiw/react-codemirror'; import { yaml } from '@codemirror/lang-yaml'; import { search, searchKeymap, highlightSelectionMatches } from '@codemirror/search'; import { keymap } from '@codemirror/view'; +import { parse as parseYaml } from 'yaml'; import { Card } from '@/components/ui/Card'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; @@ -17,6 +18,16 @@ import styles from './ConfigPage.module.scss'; type ConfigEditorTab = 'visual' | 'source'; +function readCommercialModeFromYaml(yamlContent: string): boolean { + try { + const parsed = parseYaml(yamlContent); + if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return false; + return Boolean((parsed as Record)['commercial-mode']); + } catch { + return false; + } +} + export function ConfigPage() { const { t } = useTranslation(); const { showNotification } = useNotificationStore(); @@ -78,13 +89,19 @@ export function ConfigPage() { const handleSave = async () => { setSaving(true); try { + const previousCommercialMode = readCommercialModeFromYaml(content); const nextContent = activeTab === 'visual' ? applyVisualChangesToYaml(content) : content; + const nextCommercialMode = readCommercialModeFromYaml(nextContent); + const commercialModeChanged = previousCommercialMode !== nextCommercialMode; await configFileApi.saveConfigYaml(nextContent); const latestContent = await configFileApi.fetchConfigYaml(); setDirty(false); setContent(latestContent); loadVisualValuesFromYaml(latestContent); showNotification(t('config_management.save_success'), 'success'); + if (commercialModeChanged) { + showNotification(t('notification.commercial_mode_restart_required'), 'warning'); + } } catch (err: unknown) { const message = err instanceof Error ? err.message : ''; showNotification(`${t('notification.save_failed')}: ${message}`, 'error');