Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): 标题栏左上角菜单新增「设置」入口 (#1881)

DavidShen88f970973a0c
diff --git a/apps/desktop/src/renderer/__tests__/menuButtonSettingsEntry.test.ts b/apps/desktop/src/renderer/__tests__/menuButtonSettingsEntry.test.ts
new file mode 100644
index 0000000000..074cde6746
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/menuButtonSettingsEntry.test.ts
@@ -0,0 +1,58 @@
+/**
+ * menuButtonSettingsEntry.test.ts
+ * ---------------------------------------------------------------------------
+ * Regression test for Issue #1881: Windows / Linux 缺少清晰可发现的「设置」入口。
+ *
+ * 契约:标题栏左上角应用内菜单(MenuButton)必须常驻「设置」菜单项——
+ * 非 darwin 平台没有原生应用菜单(installApplicationMenu 置 null),macOS
+ * 的「设置…」菜单项在这些平台不可见,此处是唯一的菜单型设置入口。
+ *
+ * 这份测试做静态源码扫描,确保以下契约不被未来的提交悄悄回退:
+ * 1. 菜单包含 settings 菜单项,文案走 i18n key `titleBar.menuItems.settings`。
+ * 2. 点击导航 `/settings`,且已在设置页时不重复导航(与 MainLayout
+ * 'open-settings' 命令、侧栏用户卡片同一行为)。
+ * 3. 四语言 locale 都提供 `titleBar.menuItems.settings` 文案。
+ */
+
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+
+const sourcePath = resolve(__dirname, '..', 'components', 'title-bar', 'MenuButton.tsx');
+const source = readFileSync(sourcePath, 'utf8');
+
+describe('MenuButton — settings menu item (#1881)', () => {
+ it('renders a settings item backed by the i18n key', () => {
+ expect(source).toContain("t('titleBar.menuItems.settings')");
+ });
+
+ it('navigates to /settings with a same-path guard', () => {
+ // 与 MainLayout 'open-settings' / UserInfoSection 相同的防重复导航语义
+ expect(source).toMatch(
+ /if \(location\.pathname !== '\/settings'\) \{\s*\n\s*navigate\('\/settings'\);/,
+ );
+ expect(source).toContain("import { useLocation, useNavigate } from 'react-router-dom';");
+ });
+
+ it('keeps the existing help / issues / check-for-updates items', () => {
+ expect(source).toContain("t('titleBar.menuItems.help')");
+ expect(source).toContain("t('titleBar.menuItems.issues')");
+ expect(source).toContain("t('titleBar.menuItems.checkForUpdates')");
+ });
+});
+
+describe('MenuButton — locale coverage for the settings item', () => {
+ const locales = ['zh-CN', 'en', 'ja', 'ko'] as const;
+
+ for (const lng of locales) {
+ it(`${lng} provides titleBar.menuItems.settings`, () => {
+ const localePath = resolve(__dirname, '..', 'i18n', 'locales', lng, 'common.json');
+ const locale = JSON.parse(readFileSync(localePath, 'utf8')) as {
+ titleBar: { menuItems: { settings?: string } };
+ };
+ const label = locale.titleBar.menuItems.settings;
+ expect(label, `${lng} 缺少 titleBar.menuItems.settings`).toBeTruthy();
+ expect(label).not.toContain('?');
+ });
+ }
+});
diff --git a/apps/desktop/src/renderer/components/title-bar/MenuButton.tsx b/apps/desktop/src/renderer/components/title-bar/MenuButton.tsx
index 3f40602b23..00f6043c08 100644
--- a/apps/desktop/src/renderer/components/title-bar/MenuButton.tsx
+++ b/apps/desktop/src/renderer/components/title-bar/MenuButton.tsx
@@ -1,6 +1,6 @@
import { Menu } from 'lucide-react';
import { useTranslation } from 'react-i18next';
-import { useNavigate } from 'react-router-dom';
+import { useLocation, useNavigate } from 'react-router-dom';
import { cn } from '@/lib/utils';
import { checkForUpdateWithToast } from '@/lib/checkForUpdateWithToast';
@@ -17,6 +17,7 @@ import {
export function MenuButton() {
const { t } = useTranslation();
const navigate = useNavigate();
+ const location = useLocation();
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
@@ -40,6 +41,22 @@ export function MenuButton() {
align="start"
className="bg-titlebar border-titlebar-border"
>
+ {/* 设置入口:Windows / Linux 没有原生应用菜单(installApplicationMenu 非
+ darwin 直接置 null),macOS「设置…」菜单项在这些平台不可见;侧栏底部
+ 用户卡片虽可进设置但无可见「设置」标识,可发现性不足(#1881)。此处
+ 常驻应用内左上角菜单,与 MainLayout 'open-settings' 命令同一行为:
+ 已在设置页时不重复导航,避免堆叠重复 history 记录。 */}
+ <DropdownMenuItem
+ className="focus:bg-titlebar-button-hover"
+ onSelect={() => {
+ log.info('Settings clicked');
+ if (location.pathname !== '/settings') {
+ navigate('/settings');
+ }
+ }}
+ >
+ {t('titleBar.menuItems.settings')}
+ </DropdownMenuItem>
<DropdownMenuItem
className="focus:bg-titlebar-button-hover"
onSelect={() => {
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index e88b9a5203..016c7c4d37 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -4291,6 +4291,7 @@
"maximize": "Maximize",
"close": "Close",
"menuItems": {
+ "settings": "Settings",
"help": "Help",
"issues": "Issues",
"checkForUpdates": "Check for Updates"
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 39f0b601c5..bc985008c6 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -4289,6 +4289,7 @@
"maximize": "最大化",
"close": "閉じる",
"menuItems": {
+ "settings": "設定",
"help": "ヘルプ",
"issues": "フィードバック",
"checkForUpdates": "更新を確認"
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index a3ebfabcd6..594a59b126 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -4289,6 +4289,7 @@
"maximize": "최대화",
"close": "닫기",
"menuItems": {
+ "settings": "설정",
"help": "도움말",
"issues": "이슈",
"checkForUpdates": "업데이트 확인"
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 9992ca7826..e107bb45a3 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -4289,6 +4289,7 @@
"maximize": "最大化",
"close": "关闭",
"menuItems": {
+ "settings": "设置",
"help": "帮助",
"issues": "问题反馈",
"checkForUpdates": "检查更新"