Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(desktop): reland open Settings with Cmd/Ctrl+, (MUL-6233) (#7076)
Jiayuan Zhang1b6d42864f94
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.tsindex 17b75327f5..274e6bb3aa 100644--- a/apps/desktop/src/main/index.ts+++ b/apps/desktop/src/main/index.ts@@ -295,6 +295,13 @@ function installWindowShortcutHandler(window: BrowserWindow): void {if (result === "close-tab") {event.preventDefault();window.webContents.send("tab:close-active");+ } else if (result === "open-settings") {+ event.preventDefault();+ // Settings is a tab, so it can only live in the tabbed main window.+ // Routing through the queue means the chord also works from a+ // dedicated issue window — and from one that outlived the main window,+ // which is recreated and only then handed the request.+ dispatchToMainRenderer("settings:open", null);} else if (result) {event.preventDefault();}diff --git a/apps/desktop/src/main/keyboard-shortcuts.test.ts b/apps/desktop/src/main/keyboard-shortcuts.test.tsindex 0e13643c6b..3768c82f86 100644--- a/apps/desktop/src/main/keyboard-shortcuts.test.ts+++ b/apps/desktop/src/main/keyboard-shortcuts.test.ts@@ -164,6 +164,51 @@ describe("handleAppShortcut — unrelated keys pass through", () => {});});+describe("handleAppShortcut — open settings (Cmd/Ctrl+,)", () => {+ it('returns "open-settings" on Cmd+, (macOS)', () => {+ const wc = makeWc();+ expect(handleAppShortcut(key(",", { meta: true }), wc, "darwin")).toBe(+ "open-settings",+ );+ });++ it('returns "open-settings" on Ctrl+, (Linux/Windows)', () => {+ const wc = makeWc();+ expect(handleAppShortcut(key(",", { control: true }), wc, "linux")).toBe(+ "open-settings",+ );+ expect(handleAppShortcut(key(",", { control: true }), wc, "win32")).toBe(+ "open-settings",+ );+ });++ it("does not trigger without Cmd/Ctrl modifier", () => {+ const wc = makeWc();+ expect(handleAppShortcut(key(","), wc, "darwin")).toBe(false);+ });++ it("does not trigger with extra modifiers", () => {+ const wc = makeWc();+ expect(+ handleAppShortcut(key(",", { meta: true, alt: true }), wc, "darwin"),+ ).toBe(false);+ expect(+ handleAppShortcut(key(",", { meta: true, shift: true }), wc, "darwin"),+ ).toBe(false);+ });++ it("swallows auto-repeat without queuing another request", () => {+ const wc = makeWc();+ expect(+ handleAppShortcut(+ { ...key(",", { meta: true }), isAutoRepeat: true },+ wc,+ "darwin",+ ),+ ).toBe(true);+ });+});+describe("handleAppShortcut — close tab (Cmd/Ctrl+W)", () => {it('returns "close-tab" on Cmd+W (macOS)', () => {const wc = makeWc();diff --git a/apps/desktop/src/main/keyboard-shortcuts.ts b/apps/desktop/src/main/keyboard-shortcuts.tsindex 61b0d63110..27026b0076 100644--- a/apps/desktop/src/main/keyboard-shortcuts.ts+++ b/apps/desktop/src/main/keyboard-shortcuts.ts@@ -42,8 +42,10 @@ const ZOOM_MAX = 4.5;* - `false`: not handled, let Electron continue* - `true`: handled (preventDefault), no further action* - `"close-tab"`: Cmd/Ctrl+W intercepted — caller should send IPC to renderer+ * - `"open-settings"`: Cmd/Ctrl+, intercepted — caller should route the+ * request to the tabbed main window*/-export type ShortcutResult = boolean | "close-tab";+export type ShortcutResult = boolean | "close-tab" | "open-settings";export function handleAppShortcut(input: ShortcutInput,@@ -89,6 +91,17 @@ export function handleAppShortcut(return true;}+ // Cmd/Ctrl + "," → open Settings, the macOS Preferences convention (and+ // what editors bind on every platform). Handled here rather than in the+ // renderer so the chord fires from any window and any focus context —+ // including while the caret sits in a text field, where a document-level+ // listener would have to make an exception for itself.+ if (input.key === "," && !input.shift) {+ // Holding the chord must not queue one request per repeat.+ if (input.isAutoRepeat) return true;+ return "open-settings";+ }+// Cmd/Ctrl + W → close active tab (or window if last tab).// Cmd/Ctrl + Shift + W is reserved for "close window" — do not intercept.// Return a signal so the caller can send IPC to the renderer.diff --git a/apps/desktop/src/preload/index.d.ts b/apps/desktop/src/preload/index.d.tsindex 4f64e96abc..9442364af0 100644--- a/apps/desktop/src/preload/index.d.ts+++ b/apps/desktop/src/preload/index.d.ts@@ -105,6 +105,9 @@ interface DesktopAPI {/** Listen for Cmd/Ctrl+W tab-close requests from the main process.* Returns an unsubscribe function. */onCloseActiveTab: (callback: () => void) => () => void;+ /** Listen for Cmd/Ctrl+, requests to open Settings, delivered to the main+ * window whichever window had focus. Returns an unsubscribe function. */+ onOpenSettings: (callback: () => void) => () => void;/** Ask the main process to close the window. */closeWindow: () => void;/** Open an issue-detail tab in a dedicated native window. */diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.tsindex 4d96bf9f37..179fd586b9 100644--- a/apps/desktop/src/preload/index.ts+++ b/apps/desktop/src/preload/index.ts@@ -218,6 +218,11 @@ const desktopAPI = {ipcRenderer.removeListener("tab:close-active", handler);};},+ /** Listen for Cmd/Ctrl+, requests to open Settings. Only the main window+ * subscribes — main delivers the chord there even when it was pressed in+ * an issue window, because Settings is a tab. Returns an unsubscribe fn. */+ onOpenSettings: (callback: () => void) =>+ subscribeToMainRendererChannel("settings:open", () => callback()),/** Ask the main process to close the window (used after closing the last tab). */closeWindow: () => ipcRenderer.send("window:close"),/** Open a validated issue-detail route in a dedicated native window. */diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsxindex b82448dd5a..52c830546d 100644--- a/apps/desktop/src/renderer/src/App.tsx+++ b/apps/desktop/src/renderer/src/App.tsx@@ -19,6 +19,7 @@ import { UpdateNotification } from "./components/update-notification";import { IssueWindow } from "./components/issue-window";import { useTabStore } from "./stores/tab-store";import { useWindowOverlayStore } from "./stores/window-overlay-store";+import { useOpenSettingsShortcut } from "./hooks/use-open-settings-shortcut";import { useDaemonIPCBridge } from "./platform/daemon-ipc-bridge";import { syncDaemonOnLogin } from "./platform/daemon-login-sync";import { createDesktopLocaleAdapter } from "./platform/i18n-adapter";@@ -383,6 +384,9 @@ export default function App() {const windowContext =window.desktopAPI.windowContext ?? { kind: "main" as const };useCmdWCloseTab();+ // Mounted at the App root for the same reason as Cmd+W: the chord has to+ // work in every renderer state, not only inside the tab shell.+ useOpenSettingsShortcut();// Flush a freeze/crash breadcrumb the main process parked from a previous// session. A true hang or process death can't report itself when it happensdiff --git a/apps/desktop/src/renderer/src/hooks/use-open-settings-shortcut.test.tsx b/apps/desktop/src/renderer/src/hooks/use-open-settings-shortcut.test.tsxnew file mode 100644index 0000000000..760e4883e4--- /dev/null+++ b/apps/desktop/src/renderer/src/hooks/use-open-settings-shortcut.test.tsx@@ -0,0 +1,131 @@+// @vitest-environment jsdom+import { beforeEach, describe, expect, it, vi } from "vitest";+import { render } from "@testing-library/react";+import { useTabStore } from "@/stores/tab-store";+import { useWindowOverlayStore } from "@/stores/window-overlay-store";+import {+ openSettingsTab,+ useOpenSettingsShortcut,+} from "./use-open-settings-shortcut";++function Probe() {+ useOpenSettingsShortcut();+ return null;+}++/** One workspace with a single issues tab open. */+function seedTabs() {+ useTabStore.setState({+ activeWorkspaceSlug: "acme",+ byWorkspace: {+ acme: {+ tabs: [+ {+ id: "t1",+ url: "/acme/issues",+ resourceKey: "/acme/issues",+ title: "",+ pinned: false,+ history: { stack: ["/acme/issues"], index: 0 },+ memento: { scroll: {}, view: {} },+ },+ ],+ activeTabId: "t1",+ recentTabIds: ["t1"],+ },+ },+ });+}++function tabUrls(): string[] {+ return useTabStore.getState().byWorkspace.acme?.tabs.map((t) => t.url) ?? [];+}++function activeTabUrl(): string | undefined {+ const group = useTabStore.getState().byWorkspace.acme;+ return group?.tabs.find((t) => t.id === group.activeTabId)?.url;+}++/** Installs a desktopAPI stub; `deliver()` plays the chord main would send. */+function stubDesktopAPI(kind: "main" | "issue") {+ let handler: (() => void) | null = null;+ const onOpenSettings = vi.fn((callback: () => void) => {+ handler = callback;+ return () => {+ handler = null;+ };+ });+ (window as unknown as { desktopAPI: Record<string, unknown> }).desktopAPI = {+ windowContext:+ kind === "main"+ ? { kind: "main" }+ : { kind: "issue", path: "/acme/issues/abc", workspaceSlug: "acme" },+ onOpenSettings,+ };+ return { onOpenSettings, deliver: () => handler?.() };+}++describe("openSettingsTab", () => {+ beforeEach(() => {+ seedTabs();+ useWindowOverlayStore.setState({ overlay: null });+ });++ it("opens Settings for the active workspace and focuses it", () => {+ openSettingsTab();++ expect(tabUrls()).toEqual(["/acme/issues", "/acme/settings"]);+ expect(activeTabUrl()).toBe("/acme/settings");+ });++ it("reuses the Settings tab instead of stacking duplicates", () => {+ openSettingsTab();+ useTabStore.getState().setActiveTab("t1");+ openSettingsTab();++ expect(tabUrls()).toEqual(["/acme/issues", "/acme/settings"]);+ expect(activeTabUrl()).toBe("/acme/settings");+ });++ it("does nothing while a pre-workspace overlay covers the window", () => {+ useWindowOverlayStore.setState({ overlay: { type: "onboarding" } });++ openSettingsTab();++ expect(tabUrls()).toEqual(["/acme/issues"]);+ });++ it("does nothing without an active workspace (logged out)", () => {+ useTabStore.setState({ activeWorkspaceSlug: null });++ expect(() => openSettingsTab()).not.toThrow();+ expect(tabUrls()).toEqual(["/acme/issues"]);+ });+});++describe("useOpenSettingsShortcut", () => {+ beforeEach(() => {+ seedTabs();+ useWindowOverlayStore.setState({ overlay: null });+ });++ it("opens Settings when main delivers the chord", () => {+ const { deliver } = stubDesktopAPI("main");+ render(<Probe />);++ deliver();++ expect(activeTabUrl()).toBe("/acme/settings");+ });++ // Main routes the chord to the tabbed window; an issue renderer that also+ // subscribed would mark the channel ready and drain the request into a+ // window that has no tabs to open it in.+ it("does not subscribe in a dedicated issue window", () => {+ const { onOpenSettings } = stubDesktopAPI("issue");++ render(<Probe />);++ expect(onOpenSettings).not.toHaveBeenCalled();+ });+});diff --git a/apps/desktop/src/renderer/src/hooks/use-open-settings-shortcut.ts b/apps/desktop/src/renderer/src/hooks/use-open-settings-shortcut.tsnew file mode 100644index 0000000000..f88bafb553--- /dev/null+++ b/apps/desktop/src/renderer/src/hooks/use-open-settings-shortcut.ts@@ -0,0 +1,44 @@+import { useEffect } from "react";+import { paths } from "@multica/core/paths";+import { useTabStore } from "@/stores/tab-store";+import { useWindowOverlayStore } from "@/stores/window-overlay-store";++/**+ * Open Settings for the active workspace, the way Cmd/Ctrl+, does it.+ *+ * Open-or-activate (`openTab`) rather than in-tab navigation: a preferences+ * chord should never discard the page the user was working on, and pressing+ * it twice should return to the Settings tab that is already open instead of+ * stacking duplicates.+ *+ * No-ops when there is nothing to open into — logged out, zero workspaces, or+ * a pre-workspace overlay (onboarding, invite, create workspace) covering the+ * window, where a new tab would appear behind a full-window takeover.+ */+export function openSettingsTab(): void {+ if (useWindowOverlayStore.getState().overlay) return;+ const store = useTabStore.getState();+ const slug = store.activeWorkspaceSlug;+ if (!slug) return;+ // Empty seed title: the tab bar derives the real one from the URL, same as+ // every other programmatic openTab caller.+ store.openTab(paths.workspace(slug).settings(), "", { activate: true });+}++/**+ * Cmd/Ctrl+, opens Settings — matched in the main process (see+ * main/keyboard-shortcuts.ts) so it fires from any window and any focus+ * context, then delivered here.+ *+ * Only the tabbed main window subscribes: main routes the chord to that+ * window regardless of which one had focus, and a second subscriber in an+ * issue window would drain the request into a renderer that has no tabs.+ */+export function useOpenSettingsShortcut(): void {+ useEffect(() => {+ if (window.desktopAPI.windowContext?.kind === "issue") return undefined;+ // Optional call keeps renderer HMR safe while an old preload is still+ // attached to a refreshed React tree, same as reportAuthSession in App.+ return window.desktopAPI.onOpenSettings?.(openSettingsTab);+ }, []);+}diff --git a/apps/desktop/src/shared/main-renderer-messages.ts b/apps/desktop/src/shared/main-renderer-messages.tsindex 7469311559..cb1a0c868c 100644--- a/apps/desktop/src/shared/main-renderer-messages.ts+++ b/apps/desktop/src/shared/main-renderer-messages.ts@@ -10,6 +10,7 @@ export const MAIN_RENDERER_MESSAGE_CHANNELS = ["auth:token","invite:open","inbox:open",+ "settings:open",] as const;export type MainRendererMessageChannel =diff --git a/packages/core/shortcuts/definitions.test.ts b/packages/core/shortcuts/definitions.test.tsindex 8eab645b3e..8a2580dd07 100644--- a/packages/core/shortcuts/definitions.test.ts+++ b/packages/core/shortcuts/definitions.test.ts@@ -184,6 +184,19 @@ describe("keyboard shortcut definitions", () => {).toBe(false);});+ it("reserves the preferences chord on every runtime", () => {+ // Desktop opens Settings from the main process (before-input-event) and+ // browsers open their own settings, so Mod+, can never be recorded for a+ // product action.+ const chord = createShortcutChord(",", { primary: true });+ expect(isReservedShortcut(chord, "macos", "desktop")).toBe(true);+ expect(isReservedShortcut(chord, "macos", "web")).toBe(true);+ expect(isReservedShortcut(chord, "windows", "desktop")).toBe(true);+ expect(isShortcutAllowedForAction("goSettings", chord, "macos", "desktop")).toBe(false);+ // Only with the primary modifier — a bare comma stays typeable.+ expect(isReservedShortcut(createShortcutChord(","), "macos", "desktop")).toBe(false);+ });+it("reserves browser-owned accelerators on web but frees the bare chords on desktop", () => {for (const key of ["P", "L", "T", "N", "D", "U"]) {const chord = createShortcutChord(key, { primary: true });diff --git a/packages/core/shortcuts/definitions.ts b/packages/core/shortcuts/definitions.tsindex 2c18629997..4c4ae98d11 100644--- a/packages/core/shortcuts/definitions.ts+++ b/packages/core/shortcuts/definitions.ts@@ -298,6 +298,10 @@ const PRIMARY_RESERVED_KEYS = new Set([// Window operations the app itself owns on every runtime: W closes the// tab, R/F5 is the reload guard, Q quits."W", "R", "Q",+ // Preferences: the desktop app opens Settings from the main process, and on+ // web the browser opens its own settings — neither leaves the chord free for+ // a product action.+ ",",// Fundamental editing operations should never become product actions."A", "C", "V", "X", "Y", "Z",// Zoom accelerators: fixed app shortcuts on desktop, browser zoom on web.diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.jsonindex 155bb57584..6f39934da1 100644--- a/packages/views/locales/en/settings.json+++ b/packages/views/locales/en/settings.json@@ -135,6 +135,7 @@"fixed": {"title": "Fixed system shortcuts","description": "Window and accessibility shortcuts stay fixed so they remain reliable. Zoom and tab controls apply to the desktop app.",+ "open_settings": "Open Settings","close_tab": "Close active tab","zoom_in": "Zoom in","zoom_out": "Zoom out",diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.jsonindex be0582365a..335bcae2a2 100644--- a/packages/views/locales/ja/settings.json+++ b/packages/views/locales/ja/settings.json@@ -135,6 +135,7 @@"fixed": {"title": "固定のシステムショートカット","description": "ウィンドウとアクセシビリティのショートカットは信頼性のため固定されています。ズームとタブ操作はデスクトップアプリに適用されます。",+ "open_settings": "設定を開く","close_tab": "アクティブなタブを閉じる","zoom_in": "拡大","zoom_out": "縮小",diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.jsonindex 7114813a41..cf57ae489b 100644--- a/packages/views/locales/ko/settings.json+++ b/packages/views/locales/ko/settings.json@@ -135,6 +135,7 @@"fixed": {"title": "고정 시스템 단축키","description": "창 및 접근성 단축키는 안정성을 위해 고정됩니다. 확대/축소 및 탭 제어는 데스크톱 앱에 적용됩니다.",+ "open_settings": "설정 열기","close_tab": "활성 탭 닫기","zoom_in": "확대","zoom_out": "축소",diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.jsonindex 78b3373ef2..f9b1ccdf41 100644--- a/packages/views/locales/zh-Hans/settings.json+++ b/packages/views/locales/zh-Hans/settings.json@@ -135,6 +135,7 @@"fixed": {"title": "固定的系统快捷键","description": "窗口和无障碍快捷键保持固定,确保始终可靠。缩放和标签页操作仅适用于桌面端。",+ "open_settings": "打开设置","close_tab": "关闭当前标签页","zoom_in": "放大","zoom_out": "缩小",diff --git a/packages/views/settings/components/keyboard-shortcuts-tab.tsx b/packages/views/settings/components/keyboard-shortcuts-tab.tsxindex f65d3e7b4f..da5b6d428c 100644--- a/packages/views/settings/components/keyboard-shortcuts-tab.tsx+++ b/packages/views/settings/components/keyboard-shortcuts-tab.tsx@@ -195,6 +195,7 @@ export function KeyboardShortcutsTab() {description={t(($) => $.shortcuts.fixed.description)}><SettingsCard>+ <FixedShortcutRow label={t(($) => $.shortcuts.fixed.open_settings)} shortcut={createShortcutChord(",", { primary: true })} /><FixedShortcutRow label={t(($) => $.shortcuts.fixed.close_tab)} shortcut={createShortcutChord("W", { primary: true })} /><FixedShortcutRow label={t(($) => $.shortcuts.fixed.zoom_in)} shortcut={createShortcutChord("Plus", { primary: true })} /><FixedShortcutRow label={t(($) => $.shortcuts.fixed.zoom_out)} shortcut={createShortcutChord("Minus", { primary: true })} />