🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(settings): 快捷键设置页展示桌面端应用菜单快捷键 (#22113)
Mocha8db4223bbb2e
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.jsonindex 433d5fe106b..20c9cea086a 100644--- a/locales/en-US/setting.json+++ b/locales/en-US/setting.json@@ -985,6 +985,8 @@"hotkey.errors.NO_MODIFIER": "Hotkey must include a modifier key (Ctrl, Alt, Shift, etc.)","hotkey.errors.SYSTEM_OCCUPIED": "Hotkey is occupied by the system or another application","hotkey.errors.UNKNOWN": "Update failed: Unknown error",+ "hotkey.group.appMenu": "App Menu",+ "hotkey.group.appMenuDesc": "Shortcuts built into the desktop app menu. They follow the system platform and cannot be customized yet.","hotkey.group.conversation": "Conversation","hotkey.group.desktop": "Desktop","hotkey.group.essential": "Essential",diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.jsonindex 590f0ac4b4e..6e6c328043e 100644--- a/locales/zh-CN/setting.json+++ b/locales/zh-CN/setting.json@@ -985,6 +985,8 @@"hotkey.errors.NO_MODIFIER": "快捷键必须包含修饰键(Ctrl、Alt、Shift等)","hotkey.errors.SYSTEM_OCCUPIED": "快捷键已被系统或其他应用程序占用","hotkey.errors.UNKNOWN": "更新失败:未知错误",+ "hotkey.group.appMenu": "应用菜单",+ "hotkey.group.appMenuDesc": "桌面端应用菜单内置的快捷键,随系统平台变化,暂不支持自定义。","hotkey.group.conversation": "会话","hotkey.group.desktop": "桌面端","hotkey.group.essential": "基础",diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.tsindex 39e3ed4e4c0..2d5befc7726 100644--- a/packages/locales/src/default/setting.ts+++ b/packages/locales/src/default/setting.ts@@ -956,6 +956,9 @@ export default {'hotkey.errors.NO_MODIFIER': 'Hotkey must include a modifier key (Ctrl, Alt, Shift, etc.)','hotkey.errors.SYSTEM_OCCUPIED': 'Hotkey is occupied by the system or another application','hotkey.errors.UNKNOWN': 'Update failed: Unknown error',+ 'hotkey.group.appMenu': 'App Menu',+ 'hotkey.group.appMenuDesc':+ 'Shortcuts built into the desktop app menu. They follow the system platform and cannot be customized yet.','hotkey.group.conversation': 'Conversation','hotkey.group.desktop': 'Desktop','hotkey.group.essential': 'Essential',diff --git a/src/features/Settings/hotkey/features/AppMenu.tsx b/src/features/Settings/hotkey/features/AppMenu.tsxnew file mode 100644index 00000000000..26a2eadf043--- /dev/null+++ b/src/features/Settings/hotkey/features/AppMenu.tsx@@ -0,0 +1,85 @@+'use client';++import { HotkeyInput } from '@lobehub/ui';+import { Form, type FormGroupItem, useForm } from '@lobehub/ui/form';+import { memo, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import useSWR from 'swr';++import { SettingsSectionSkeleton } from '@/components/Skeleton';+import { FORM_STYLE } from '@/const/layoutTokens';+import { isDesktop } from '@/const/version';+import { SettingsSearchAnchor } from '@/features/SettingsSearch/anchor';+import { electronKeys } from '@/libs/swr/keys';+import { electronSystemService } from '@/services/electron/system';++import { collectAppMenuHotkeys } from './appMenuHotkeys';++/**+ * Read-only list of the desktop app menu accelerators (New Agent, New Topic, Zoom, …).+ * Reads the live Electron menu, so labels are localized and keys match the current platform.+ */+const AppMenuHotkeys = memo(() => {+ const { t } = useTranslation('setting');+ const form = useForm();+ const { data, isLoading } = useSWR(+ // Desktop-only IPC: never fetch off-desktop.+ isDesktop ? electronKeys.appMenu() : null,+ () => electronSystemService.getAppMenu(),+ {+ // The section simply stays hidden; the menu itself still works.+ onError: (error: unknown) => console.error('Failed to load the app menu hotkeys:', error),+ revalidateOnFocus: false,+ },+ );++ const hotkeys = useMemo(() => collectAppMenuHotkeys(data ?? []), [data]);++ if (isLoading)+ return (+ <SettingsSectionSkeleton+ groups={[+ {+ // Hotkey recorder inputs settle at 335x36.+ control: { height: 36, width: 335 },+ rows: 8,+ titleWidth: 96,+ withDesc: false,+ },+ ]}+ />+ );++ if (hotkeys.length === 0) return null;++ const appMenu: FormGroupItem = {+ children: hotkeys.map((item) => ({+ children: (+ <HotkeyInput disabled allowReset={false} resetValue={item.keys} value={item.keys} />+ ),+ label: item.label,+ tag: item.menu,+ })),+ desc: t('hotkey.group.appMenuDesc'),+ title: (+ <SettingsSearchAnchor id={'hotkey-app-menu'}>+ {t('hotkey.group.appMenu')}+ </SettingsSearchAnchor>+ ),+ };++ return (+ <Form+ collapsible={false}+ form={form}+ items={[appMenu]}+ itemsType={'group'}+ variant={'filled'}+ {...FORM_STYLE}+ />+ );+});++AppMenuHotkeys.displayName = 'AppMenuHotkeys';++export default AppMenuHotkeys;diff --git a/src/features/Settings/hotkey/features/Desktop.tsx b/src/features/Settings/hotkey/features/Desktop.tsxindex bd034b7010e..56fd6dfece2 100644--- a/src/features/Settings/hotkey/features/Desktop.tsx+++ b/src/features/Settings/hotkey/features/Desktop.tsx@@ -3,7 +3,7 @@import { HotkeyInput, Spin, toast } from '@lobehub/ui';import { Form, type FormGroupItem, useForm } from '@lobehub/ui/form';import isEqual from 'fast-deep-equal';-import { memo, useState } from 'react';+import { memo, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';import { SettingsSectionSkeleton } from '@/components/Skeleton';@@ -14,9 +14,23 @@ import { useElectronStore } from '@/store/electron';import { desktopHotkeysSelectors } from '@/store/electron/selectors';import { type DesktopHotkeyConfig, type DesktopHotkeyItem } from '@/types/hotkey';+import { acceleratorToHotkey } from './appMenuHotkeys';+const HotkeySetting = memo(() => {const { t } = useTranslation(['setting', 'hotkey']);- const hotkeys = useElectronStore(desktopHotkeysSelectors.hotkeys, isEqual);+ const storedHotkeys = useElectronStore(desktopHotkeysSelectors.hotkeys, isEqual);+ // Main process stores Electron accelerators (`CommandOrControl+,`); HotkeyInput reads `mod+comma`.+ // Normalize the form values themselves: Form binds fields by name and overrides a field's `value`.+ const hotkeys = useMemo(+ () =>+ Object.fromEntries(+ Object.entries(storedHotkeys).map(([id, accelerator]) => [+ id,+ acceleratorToHotkey(accelerator),+ ]),+ ) as DesktopHotkeyConfig,+ [storedHotkeys],+ );const form = useForm({ initialValues: hotkeys, values: hotkeys });const [isHotkeysInit, updateDesktopHotkey, useFetchDesktopHotkeys] = useElectronStore((s) => [diff --git a/src/features/Settings/hotkey/features/appMenuHotkeys.test.ts b/src/features/Settings/hotkey/features/appMenuHotkeys.test.tsnew file mode 100644index 00000000000..3381a732558--- /dev/null+++ b/src/features/Settings/hotkey/features/appMenuHotkeys.test.ts@@ -0,0 +1,104 @@+import type { AppMenuNode } from '@lobechat/electron-client-ipc';+import { describe, expect, it } from 'vitest';++import { acceleratorToHotkey, collectAppMenuHotkeys } from './appMenuHotkeys';++describe('acceleratorToHotkey', () => {+ it.each([+ ['Alt+Ctrl+A', 'alt+ctrl+a'],+ ['Alt+Command+A', 'alt+meta+a'],+ ['CmdOrCtrl+W', 'mod+w'],+ ['CommandOrControl+,', 'mod+comma'],+ ['Shift+Command+H', 'shift+meta+h'],+ ['Command+[', 'meta+bracketleft'],+ ['Command+]', 'meta+bracketright'],+ ['CmdOrCtrl+=', 'mod+equal'],+ ['CmdOrCtrl+-', 'mod+minus'],+ ['CmdOrCtrl+Plus', 'mod+equal'],+ ['CmdOrCtrl++', 'mod+equal'],+ ['CmdOrCtrl+Shift+R', 'mod+shift+r'],+ ['Alt+Left', 'alt+left'],+ ['F12', 'f12'],+ ])('%s -> %s', (accelerator, expected) => {+ expect(acceleratorToHotkey(accelerator)).toBe(expected);+ });+});++describe('collectAppMenuHotkeys', () => {+ const item = (id: string, label: string, accelerator?: string): AppMenuNode => ({+ accelerator,+ enabled: true,+ id,+ label,+ type: 'normal',+ });++ it('keeps only accelerator items in menu order, tagged with their top-level menu', () => {+ const nodes: AppMenuNode[] = [+ {+ children: [+ item('new-topic', 'New Topic', 'Ctrl+N'),+ { enabled: false, id: '', label: '', type: 'separator' },+ item('new-agent', 'New Agent', 'Alt+Ctrl+A'),+ item('preferences', 'Preferences'),+ ],+ enabled: true,+ id: 'file',+ label: 'File',+ type: 'submenu',+ },+ {+ children: [item('undo', 'Undo')],+ enabled: true,+ id: 'edit',+ label: 'Edit',+ type: 'submenu',+ },+ {+ children: [+ {+ children: [item('zoom-in', 'Zoom In', 'CmdOrCtrl+=')],+ enabled: true,+ id: 'zoom',+ label: 'Zoom',+ type: 'submenu',+ },+ ],+ enabled: true,+ id: 'view',+ label: 'View',+ type: 'submenu',+ },+ ];++ expect(collectAppMenuHotkeys(nodes)).toEqual([+ { id: 'new-topic', keys: 'ctrl+n', label: 'New Topic', menu: 'File' },+ { id: 'new-agent', keys: 'alt+ctrl+a', label: 'New Agent', menu: 'File' },+ { id: 'zoom-in', keys: 'mod+equal', label: 'Zoom In', menu: 'View' },+ ]);+ });++ it('lists an item repeated across menus once, under its first menu', () => {+ const nodes: AppMenuNode[] = [+ {+ children: [item('file-close', 'Close', 'Ctrl+W')],+ enabled: true,+ id: 'file',+ label: 'File',+ type: 'submenu',+ },+ {+ children: [item('window-close', 'Close', 'Ctrl+W'), item('min', 'Minimize', 'Ctrl+M')],+ enabled: true,+ id: 'window',+ label: 'Window',+ type: 'submenu',+ },+ ];++ expect(collectAppMenuHotkeys(nodes)).toEqual([+ { id: 'file-close', keys: 'ctrl+w', label: 'Close', menu: 'File' },+ { id: 'min', keys: 'ctrl+m', label: 'Minimize', menu: 'Window' },+ ]);+ });+});diff --git a/src/features/Settings/hotkey/features/appMenuHotkeys.ts b/src/features/Settings/hotkey/features/appMenuHotkeys.tsnew file mode 100644index 00000000000..60dce524c53--- /dev/null+++ b/src/features/Settings/hotkey/features/appMenuHotkeys.ts@@ -0,0 +1,74 @@+import type { AppMenuNode } from '@lobechat/electron-client-ipc';++export interface AppMenuHotkey {+ id: string;+ /** Hotkey string understood by `@lobehub/ui` `Hotkey` / `HotkeyInput`, e.g. `alt+ctrl+a`. */+ keys: string;+ label: string;+ /** Label of the top-level menu (File, View, …) the item belongs to. */+ menu: string;+}++const ACCELERATOR_KEY_MAP: Record<string, string> = {+ '-': 'minus',+ ',': 'comma',+ '.': 'period',+ '/': 'slash',+ ';': 'semicolon',+ '=': 'equal',+ '[': 'bracketleft',+ '\\': 'backslash',+ ']': 'bracketright',+ '`': 'backquote',+ "'": 'quote',+ 'cmd': 'meta',+ 'cmdorctrl': 'mod',+ 'command': 'meta',+ 'commandorcontrol': 'mod',+ 'control': 'ctrl',+ 'escape': 'esc',+ 'option': 'alt',+ 'plus': 'equal',+ 'return': 'enter',+ 'super': 'meta',+};++/** Convert an Electron accelerator (`Alt+CmdOrCtrl+A`) into a lobe-ui hotkey string. */+export const acceleratorToHotkey = (accelerator: string): string =>+ accelerator+ // `CmdOrCtrl++` binds the plus key itself; keep it from vanishing in the split.+ .replace(/\+\+$/, '+plus')+ .split('+')+ .map((key) => {+ const lower = key.toLowerCase();+ return ACCELERATOR_KEY_MAP[lower] ?? lower;+ })+ .join('+');++/**+ * Flatten every app menu item that carries an accelerator, in menu order, tagged with the+ * label of the top-level menu it lives in. Items repeated across menus (e.g. Minimize / Close in+ * both File and Window) are listed once, under their first menu.+ */+export const collectAppMenuHotkeys = (nodes: AppMenuNode[]): AppMenuHotkey[] => {+ const walk = (items: AppMenuNode[], menu: string): AppMenuHotkey[] =>+ items.flatMap((node) => {+ if (node.type === 'submenu') return walk(node.children ?? [], menu);+ if (node.type === 'separator' || !node.accelerator) return [];++ return [+ { id: node.id, keys: acceleratorToHotkey(node.accelerator), label: node.label, menu },+ ];+ });++ const seen = new Set<string>();++ return nodes+ .flatMap((node) => (node.type === 'submenu' ? walk(node.children ?? [], node.label) : []))+ .filter((item) => {+ const key = `${item.label}\u0000${item.keys}`;+ if (seen.has(key)) return false;+ seen.add(key);+ return true;+ });+};diff --git a/src/features/Settings/hotkey/index.tsx b/src/features/Settings/hotkey/index.tsxindex 8b7eb2c98ef..4e159e191b2 100644--- a/src/features/Settings/hotkey/index.tsx+++ b/src/features/Settings/hotkey/index.tsx@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';import { isDesktop } from '@/const/version';import SettingHeader from '@/features/Settings/features/SettingHeader';+import AppMenu from './features/AppMenu';import Conversation from './features/Conversation';import Desktop from './features/Desktop';import Essential from './features/Essential';@@ -19,6 +20,7 @@ const Page = ({ showSettingHeader = true }: PageProps) => {{isDesktop && <Desktop />}<Essential /><Conversation />+ {isDesktop && <AppMenu />}</>);};diff --git a/src/features/SettingsSearch/items.ts b/src/features/SettingsSearch/items.tsindex 224bc4f715b..e31715ace4e 100644--- a/src/features/SettingsSearch/items.ts+++ b/src/features/SettingsSearch/items.ts@@ -617,6 +617,13 @@ export const SETTINGS_SEARCH_ITEMS: SettingsSearchItem[] = [tab: SettingsTabs.Hotkey,visible: (ctx) => ctx.isDesktop,},+ {+ anchor: 'hotkey-app-menu',+ keywords: ['shortcut', 'keyboard', 'menu', 'new agent', 'new topic', 'zoom'],+ labelKey: 'hotkey.group.appMenu',+ tab: SettingsTabs.Hotkey,+ visible: (ctx) => ctx.isDesktop,+ },// Business pages below are rendered by business slots (cloud implementation);// their tabs only appear when the business build provides them, so tab// visibility via useCategory is the effective gate — no per-item gate needed.diff --git a/src/libs/swr/keys.ts b/src/libs/swr/keys.tsindex e0519c372d3..1dbf9aad852 100644--- a/src/libs/swr/keys.ts+++ b/src/libs/swr/keys.ts@@ -976,6 +976,7 @@ export const imessageKeys = {export const electronKeys = {/** Claude Code logins held on this machine (device-local, never persisted). */claudeCodeAccounts: def('electron:claudeCodeAccounts', () => ['electron:claudeCodeAccounts']),+ appMenu: def('electron:getAppMenu', () => ['electron:getAppMenu']),appTrayVisible: def('electron:getAppTrayVisible', () => ['electron:getAppTrayVisible']),desktopHotkeys: def('electron:getDesktopHotkeys', () => ['electron:getDesktopHotkeys']),gatewayDeviceInfo: def('electron:getGatewayDeviceInfo', () => ['electron:getGatewayDeviceInfo']),