Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): 插件停靠面板标准头新增关闭按钮,二次确认后停用插件
Liziddda79731105
diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPanels.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPanels.test.tsxindex f555426fb5..de30c3f883 100644--- a/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPanels.test.tsx+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/ghostPanels.test.tsx@@ -1,19 +1,41 @@// @vitest-environment jsdom-import { afterEach, describe, expect, it } from 'vitest';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { ConfirmDialogProvider } from '@/components/ui/confirm-dialog-provider';import type { GhostManifest, InstalledGhost } from '../../../shared/ghost';import {__resetGhostPanelBubbleStateForTest,getGhostPanelBubbleState,minimizeGhostPanel,} from '../../lib/ghostPanelBubbleState';-import { __resetPanelRegistryForTest, hasPanelKind, listPanelKinds } from '../../panels/registry';+import {+ __resetPanelRegistryForTest,+ getPanelKind,+ hasPanelKind,+ listPanelKinds,+} from '../../panels/registry';import {__resetGhostPanelsForTest,pickGhostPanelMediaUri,syncGhostPanelRegistrations,} from '../ghostPanels';+// 仓库同款 i18n mock:t 返回 key(带参拼上,便于断言)。+vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string, args?: Record<string, unknown>) =>+ args ? `${key}:${JSON.stringify(args)}` : key,+ }),+}));++// 面板体是 webview 供片,jsdom 渲不了也不该渲 —— 置空,只测宿主壳(标准头/关闭链路)。+vi.mock('../ghostPanelBody', async (importOriginal) => ({+ ...(await importOriginal<typeof import('../ghostPanelBody')>()),+ GhostChipPanelBody: () => null,+ GhostPanelError: () => null,+}));+/** 造一个已装意识(panel 可覆写/置空;enabled 默认 true)。 */function ghost(id: string, panel?: GhostManifest['panel'] | null, enabled = true): InstalledGhost {const manifest: GhostManifest = {@@ -30,9 +52,11 @@ function ghost(id: string, panel?: GhostManifest['panel'] | null, enabled = true}afterEach(() => {+ cleanup();__resetPanelRegistryForTest();__resetGhostPanelsForTest();__resetGhostPanelBubbleStateForTest();+ delete (window as unknown as { electronAPI?: unknown }).electronAPI;});describe('syncGhostPanelRegistrations · 注册表与已装清单对齐', () => {@@ -124,3 +148,46 @@ describe('syncGhostPanelRegistrations · 停用即休眠', () => {expect(hasPanelKind('ghost:a')).toBe(false);});});++describe('GhostPanel · 标准头关闭按钮(二次确认后停用插件)', () => {+ function renderPanel(setEnabled: ReturnType<typeof vi.fn>): void {+ (window as unknown as { electronAPI: unknown }).electronAPI = {+ ghosts: { setEnabled },+ };+ syncGhostPanelRegistrations([ghost('demo')]);+ const def = getPanelKind('ghost:demo');+ if (!def) throw new Error('面板未注册');+ const Component = def.Component;+ render(+ <ConfirmDialogProvider>+ <Component paneId="pane-1" />+ </ConfirmDialogProvider>,+ );+ }++ it('点关闭 → 弹确认框;确认后 setEnabled(id, false)', async () => {+ const setEnabled = vi.fn().mockResolvedValue({ ok: true });+ renderPanel(setEnabled);+ fireEvent.click(screen.getByRole('button', { name: 'panelChrome.closeAria' }));+ // 确认框标题带插件名(t mock 把插值参数拼在 key 后)。+ await screen.findByText('ghostPanel.disableConfirm.title:{"name":"demo 意识"}');+ expect(setEnabled).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole('button', { name: 'ghostPanel.disableConfirm.confirm' }));+ await waitFor(() => expect(setEnabled).toHaveBeenCalledWith('demo', false));+ expect(setEnabled).toHaveBeenCalledTimes(1);+ });++ it('点关闭后取消 → 不停用', async () => {+ const setEnabled = vi.fn().mockResolvedValue({ ok: true });+ renderPanel(setEnabled);+ fireEvent.click(screen.getByRole('button', { name: 'panelChrome.closeAria' }));+ await screen.findByText('ghostPanel.disableConfirm.title:{"name":"demo 意识"}');+ fireEvent.click(screen.getByRole('button', { name: 'commonUi.confirmDialog.cancel' }));+ await waitFor(() =>+ expect(+ screen.queryByText('ghostPanel.disableConfirm.title:{"name":"demo 意识"}'),+ ).toBeNull(),+ );+ expect(setEnabled).not.toHaveBeenCalled();+ });+});diff --git a/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx b/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsxindex 4938a88cc9..205973e22f 100644--- a/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx+++ b/apps/desktop/src/renderer/cindy-brain/ghostPanels.tsx@@ -1,13 +1,18 @@import { useEffect, useRef, useState, type ReactNode } from 'react';+import { useTranslation } from 'react-i18next';+import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';import { ghostPanelKind, type GhostManifest, type InstalledGhost } from '../../shared/ghost';import { minimizeGhostPanel, reconcileGhostPanelBubbles } from '../lib/ghostPanelBubbleState';+import { toast } from '../lib/toast';import { usePanelMaximize } from '../layout/panelMaximize';import { usePanelWidth } from '../layout/paneWidths';import { PanelChrome } from '../panels/PanelChrome';import { registerPanelKind, unregisterPanelKind, type PanelComponentProps } from '../panels/registry';+import { extractIpcError } from '../utils/ipcError';import { GhostChipPanelBody, GhostPanelError } from './ghostPanelBody';import { syncGhostTabRegistrations } from './ghostTabPlugins';+import { ghostInstallErrorKey } from './installErrorKey';import { pruneGhostSettingsSnapshots } from './ghostSettingsSnapshot';import { useGhostRuntimeState } from './runtimeStates';@@ -84,6 +89,25 @@ function GhostPanel({setClosing(true);closeTimerRef.current = window.setTimeout(() => minimizeGhostPanel(manifest.id), PANEL_EXIT_MS);};+ // 标准头「关闭」= 二次确认后停用整个插件(setEnabled false):面板、工具、+ // 沙箱一并休眠,与插件页全局开关同一条链路(ghosts:changed 广播回来时+ // 本面板经 syncGhostPanelRegistrations 注销,无需自己收尾)。恒在,不受+ // 身份卡 systemButtons 控制——它是宿主给用户的退路,不是作者可关的能力。+ const { t } = useTranslation();+ const { confirm } = useConfirmDialog();+ const beginClose = async (): Promise<void> => {+ const approved = await confirm({+ title: t('ghostPanel.disableConfirm.title', { name: manifest.name }),+ description: t('ghostPanel.disableConfirm.body'),+ confirmText: t('ghostPanel.disableConfirm.confirm'),+ });+ if (!approved) return;+ try {+ await window.electronAPI?.ghosts?.setEnabled(manifest.id, false);+ } catch (error) {+ toast.error(t(ghostInstallErrorKey(extractIpcError(error)?.code)));+ }+ };return (// 外层壳管布局占宽(出现/收起的宽度动画只动这层),内层 section 恒为// 实宽被裁切——展开像"拉开抽屉"露出成形的面板,webview 不逐帧改宽。@@ -116,6 +140,7 @@ function GhostPanel({? () => void window.electronAPI?.ghostPanelWindow?.setDetached(manifest.id, true): undefined}+ onClose={() => void beginClose()}/>{broken ? (<GhostPanelError manifest={manifest} state={runtimeState} />diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex abec4ece4c..34783ea396 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -3697,7 +3697,15 @@"maximizeAria": "Maximize panel","restoreAria": "Restore panel size","detachAria": "Open in a new window",- "minimizeAria": "Minimize to floating bubble"+ "minimizeAria": "Minimize to floating bubble",+ "closeAria": "Close panel and disable plugin"+ },+ "ghostPanel": {+ "disableConfirm": {+ "title": "Disable \"{{name}}\"?",+ "body": "Closing this panel disables the whole plugin — its panel and capabilities will pause. You can re-enable it anytime from Plugins in the sidebar.",+ "confirm": "Disable"+ }},"ghostPanelWindow": {"mergeBack": "Merge back into main window",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex d7db2fb122..659570bf86 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -3696,7 +3696,15 @@"maximizeAria": "パネルを最大化","restoreAria": "パネルのサイズを元に戻す","detachAria": "新しいウィンドウで開く",- "minimizeAria": "フローティングバブルに最小化"+ "minimizeAria": "フローティングバブルに最小化",+ "closeAria": "パネルを閉じてプラグインを無効化"+ },+ "ghostPanel": {+ "disableConfirm": {+ "title": "「{{name}}」を無効にしますか?",+ "body": "このパネルを閉じるとプラグイン全体が無効になり、パネルと機能が停止します。サイドバーの「プラグイン」からいつでも再度有効にできます。",+ "confirm": "無効にする"+ }},"ghostPanelWindow": {"mergeBack": "メインウィンドウに戻す",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex d1d614c39a..32d118195c 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -3696,7 +3696,15 @@"maximizeAria": "패널 최대화","restoreAria": "패널 크기 복원","detachAria": "새 창에서 열기",- "minimizeAria": "플로팅 버블로 최소화"+ "minimizeAria": "플로팅 버블로 최소화",+ "closeAria": "패널 닫기 및 플러그인 비활성화"+ },+ "ghostPanel": {+ "disableConfirm": {+ "title": "\"{{name}}\" 플러그인을 비활성화할까요?",+ "body": "이 패널을 닫으면 플러그인 전체가 비활성화되어 패널과 기능이 중지됩니다. 사이드바의 '플러그인'에서 언제든지 다시 활성화할 수 있습니다.",+ "confirm": "비활성화"+ }},"ghostPanelWindow": {"mergeBack": "메인 창으로 되돌리기",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 2b30ae259d..9bc12531ad 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -3696,7 +3696,15 @@"maximizeAria": "撑满内容区","restoreAria": "还原面板大小","detachAria": "在独立窗口中打开",- "minimizeAria": "最小化为浮动气泡"+ "minimizeAria": "最小化为浮动气泡",+ "closeAria": "关闭面板并停用插件"+ },+ "ghostPanel": {+ "disableConfirm": {+ "title": "停用「{{name}}」?",+ "body": "关闭这个面板会停用整个插件,它的面板和能力都会暂停。之后可以随时在侧边栏「插件」里重新开启。",+ "confirm": "停用"+ }},"ghostPanelWindow": {"mergeBack": "合并回主窗口",diff --git a/apps/desktop/src/renderer/panels/PanelChrome.tsx b/apps/desktop/src/renderer/panels/PanelChrome.tsxindex f2c1f782d7..49c363198b 100644--- a/apps/desktop/src/renderer/panels/PanelChrome.tsx+++ b/apps/desktop/src/renderer/panels/PanelChrome.tsx@@ -1,5 +1,5 @@import type { CSSProperties, ReactNode } from 'react';-import { Maximize2, Minimize2, Minus, PictureInPicture2 } from 'lucide-react';+import { Maximize2, Minimize2, Minus, PictureInPicture2, X } from 'lucide-react';import { useTranslation } from 'react-i18next';import { CHROME_ACTIONS_GEOMETRY } from '@/components/layout/chromeActionsGeometry';@@ -24,7 +24,9 @@ import { usePanelMaximize } from '../layout/panelMaximize';* - 「独立窗口」(detach):传 onDetach 即得,点击把面板抽进自己的 OS 窗口* (状态机在 main 的 ghost-panel-window/controller.ts);* - 「撑满内容区」(maximize):传 panelKind 即得,状态在 LayoutRoot 的- * PanelMaximizeContext。+ * PanelMaximizeContext;+ * - 「关闭」(close):传 onClose 即得,永远排最右。语义归调用方+ * (意识面板用它走"二次确认后停用插件",见 ghostPanels.tsx)。** 视觉走主题 token(规则 16);按钮 aria 文案走 i18n(panelChrome.*),* 标题由调用方传入并自行 i18n。@@ -44,6 +46,8 @@ export interface PanelChromeProps {onDetach?: () => void;/** 传入即长出「最小化为浮动气泡」系统按钮(排在独立窗口按钮左侧)。 */onMinimize?: () => void;+ /** 传入即长出「关闭」系统按钮(恒排最右);二次确认等语义归调用方。 */+ onClose?: () => void;}export function PanelChrome({@@ -52,6 +56,7 @@ export function PanelChrome({panelKind,onDetach,onMinimize,+ onClose,}: PanelChromeProps): ReactNode {const { t } = useTranslation();const maximize = usePanelMaximize();@@ -101,7 +106,7 @@ export function PanelChrome({<div className="min-w-0 truncate text-[12px] font-medium text-[var(--text-secondary)]">{title}</div>- {(actions || showMaximize || onDetach || onMinimize) && (+ {(actions || showMaximize || onDetach || onMinimize || onClose) && (<div className="flex shrink-0 items-center gap-0.5">{actions}{onMinimize && (@@ -136,6 +141,16 @@ export function PanelChrome({{isMaximized ? <Minimize2 size={14} /> : <Maximize2 size={14} />}</button>)}+ {onClose && (+ <button+ type="button"+ aria-label={t('panelChrome.closeAria')}+ onClick={onClose}+ className="inline-flex h-7 w-7 items-center justify-center rounded-full text-[var(--titlebar-icon)] transition-colors hover:bg-[var(--surface-hover)] hover:text-[var(--text-primary)]"+ >+ <X size={14} />+ </button>+ )}</div>)}</div>diff --git a/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx b/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsxindex 3713ccaa3a..f8a0f4dedb 100644--- a/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx+++ b/apps/desktop/src/renderer/panels/__tests__/PanelChrome.test.tsx@@ -110,4 +110,36 @@ describe('PanelChrome · 撑满系统按钮', () => {'panelChrome.maximizeAria',]);});++ it('传 onClose → 长出关闭按钮并触发回调;四按钮齐时关闭恒排最右', () => {+ const onClose = vi.fn();+ render(+ <PanelMaximizeContext.Provider value={{ maximizedKind: null, toggle: () => undefined }}>+ <PanelChrome+ title="测试面板"+ panelKind="ghost:demo"+ onDetach={() => undefined}+ onMinimize={() => undefined}+ onClose={onClose}+ />+ </PanelMaximizeContext.Provider>,+ );+ fireEvent.click(screen.getByRole('button', { name: 'panelChrome.closeAria' }));+ expect(onClose).toHaveBeenCalledTimes(1);+ const labels = screen+ .getAllByRole('button')+ .map((b) => b.getAttribute('aria-label'));+ expect(labels).toEqual([+ 'panelChrome.minimizeAria',+ 'panelChrome.detachAria',+ 'panelChrome.maximizeAria',+ 'panelChrome.closeAria',+ ]);+ });++ it('只传 onClose(无其它系统按钮)→ 只有关闭按钮', () => {+ render(<PanelChrome title="测试面板" onClose={() => undefined} />);+ expect(screen.getAllByRole('button')).toHaveLength(1);+ expect(screen.getByRole('button', { name: 'panelChrome.closeAria' })).toBeTruthy();+ });});