Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 收紧分离窗口权限与最小化语义
DavidShend20f77b5f366
diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.tsindex 6d69de1d49..aec0ebce0e 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/preload-contract.test.ts@@ -132,7 +132,6 @@ describe('sidebarWindowPreload 椤跺眰濂戠害', () => {expect(topLevel).toEqual(expect.arrayContaining(['localThemes']));expect(topLevel).toEqual(expect.arrayContaining(['appShortcuts']));expect(topLevel).toEqual(expect.arrayContaining(['theme']));- expect(topLevel).toEqual(expect.arrayContaining(['safeStorageRead', 'safeStorageRemove']));expect(topLevel).toEqual(expect.arrayContaining(['search']));});@@ -212,6 +211,7 @@ describe('sidebarWindowPreload 椤跺眰濂戠害', () => {'resourceUsageWindow', 'ghostPanelWindow','pluginMarket', 'deepLink', 'gitContext','cacheMediaForSession',+ 'safeStorageStore', 'safeStorageRead', 'safeStorageRemove',];for (const key of forbidden) {expect(topLevel).not.toEqual(expect.arrayContaining([key]));diff --git a/apps/desktop/src/preload/sidebarWindowPreload.ts b/apps/desktop/src/preload/sidebarWindowPreload.tsindex c29d4e3fbf..0348f39f6c 100644--- a/apps/desktop/src/preload/sidebarWindowPreload.ts+++ b/apps/desktop/src/preload/sidebarWindowPreload.ts@@ -71,12 +71,6 @@ contextBridge.exposeInMainWorld('electronAPI', {scope: string,msg: string,): void => ipcRenderer.send('renderer:log', level, scope, msg),- safeStorageStore: (key: string, value: string): Promise<boolean> =>- ipcRenderer.invoke('safe-storage-store', key, value),- safeStorageRead: (key: string): Promise<string | null> =>- ipcRenderer.invoke('safe-storage-read', key),- safeStorageRemove: (key: string): Promise<{ success: boolean; error?: string }> =>- ipcRenderer.invoke('safe-storage-remove', key),onLocaleChanged: (cb: (locale: SupportedLocale) => void): (() => void) =>onPayload(RSB_WINDOW_LOCALE_CHANGED_CHANNEL, cb),appearanceSettings: {diff --git a/apps/desktop/src/renderer/__tests__/windowCloseBehavior.test.tsx b/apps/desktop/src/renderer/__tests__/windowCloseBehavior.test.tsxindex 295d6483fc..d022b67808 100644--- a/apps/desktop/src/renderer/__tests__/windowCloseBehavior.test.tsx+++ b/apps/desktop/src/renderer/__tests__/windowCloseBehavior.test.tsx@@ -75,6 +75,13 @@ describe('Windows close behavior', () => {expect(window.electronAPI.windowMinimize).not.toHaveBeenCalled();});+ it('hides minimize when the current surface opts out', () => {+ installWindowsApi(null);+ render(<WindowControls showMinimize={false} />);++ expect(screen.queryByRole('button', { name: 'titleBar.minimize' })).toBeNull();+ });+it('does not subscribe to main-window close requests from a secondary window', () => {window.history.replaceState({}, '', '/?secondaryWindow=1');const api = installWindowsApi(null);diff --git a/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsx b/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsxindex 58ef8c8f43..97e94d86fa 100644--- a/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/GhostPanelWindowLayout.tsx@@ -61,13 +61,15 @@ export function GhostPanelWindowLayout() {// 停用/卸载的瞬�?main �?reconcile 会收�?这里只兜住收窗前的一两帧�?const manifest = ghost && ghost.enabled !== false ? ghost.manifest : undefined;const title = manifest?.panel?.title ?? manifest?.name ?? '';+ const minimizeEnabled =+ manifest !== undefined && manifest.panel?.systemButtons?.minimize !== false;const presentationReadySentRef = useRef(false);// 复用隐藏窗口时,Chromium 可能保留上一次关闭按钮的 focus / :hover 状态�?// 与资源用量窗口一致,隐藏时重挂载 chrome,确保再次显示从干净状态开始�?const [windowChromeRevision, setWindowChromeRevision] = useState(0);const minimizeToBubble = async (): Promise<void> => {- if (!ghostId) return;+ if (!ghostId || !minimizeEnabled) return;minimizeGhostPanel(ghostId);try {await window.electronAPI.ghostPanelWindow.setDetached(ghostId, false);@@ -128,10 +130,11 @@ export function GhostPanelWindowLayout() {}, [ghostId, manifest, confirm, t, window.electronAPI.ghostPanelWindow]);useEffect(() => {+ if (!minimizeEnabled) return;return window.electronAPI.ghostPanelWindow.onMinimizeRequested(() => {void minimizeToBubble();});- }, [ghostId, window.electronAPI.ghostPanelWindow]);+ }, [ghostId, minimizeEnabled, window.electronAPI.ghostPanelWindow]);useEffect(() => {return window.electronAPI.onLocaleChanged?.((locale) => {@@ -187,6 +190,7 @@ export function GhostPanelWindowLayout() {<WindowControlskey={windowChromeRevision}onMinimize={minimizeToBubble}+ showMinimize={minimizeEnabled}onClose={disableAndClose}/></div>diff --git a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsxindex 3ceaa862e0..2baae6c815 100644--- a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx+++ b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx@@ -9,19 +9,30 @@ const mocks = vi.hoisted(() => ({sidebarVisibilityListener: null as ((payload: { visible: boolean }) => void) | null,ghostVisibilityListener: null as ((payload: { visible: boolean }) => void) | null,ghostMinimizeListener: null as (() => void) | null,+ ghostMinimizeEnabled: true,minimizeGhostPanel: vi.fn(),restoreGhostPanel: vi.fn(),}));vi.mock('@/components/title-bar/WindowControls', () => ({- WindowControls: ({ onMinimize }: { onMinimize?: () => void | Promise<void> }) => {+ WindowControls: ({+ onMinimize,+ showMinimize = true,+ }: {+ onMinimize?: () => void | Promise<void>;+ showMinimize?: boolean;+ }) => {const [mountId] = React.useState(() => ++mocks.controlsMounts);return (- <button- data-testid="window-controls"- data-mount-id={mountId}- onClick={() => void onMinimize?.()}- />+ <div data-testid="window-controls" data-mount-id={mountId}>+ {showMinimize && (+ <button+ type="button"+ aria-label="titleBar.minimize"+ onClick={() => void onMinimize?.()}+ />+ )}+ </div>);},}));@@ -54,7 +65,16 @@ vi.mock('@/cindy-brain/useInstalledGhosts', () => ({useInstalledGhosts: () => [{enabled: true,- manifest: { id: 'test-ghost', name: 'Test Ghost', panel: { title: 'Test Panel' } },+ manifest: {+ id: 'test-ghost',+ name: 'Test Ghost',+ panel: {+ title: 'Test Panel',+ ...(mocks.ghostMinimizeEnabled+ ? {}+ : { systemButtons: { minimize: false } }),+ },+ },},],}));@@ -100,6 +120,7 @@ describe('reusable auxiliary window chrome', () => {mocks.sidebarVisibilityListener = null;mocks.ghostVisibilityListener = null;mocks.ghostMinimizeListener = null;+ mocks.ghostMinimizeEnabled = true;Object.defineProperty(window, 'electronAPI', {configurable: true,value: {@@ -201,7 +222,7 @@ describe('reusable auxiliary window chrome', () => {it('minimizes a detached plugin window into the main-window Ghost bubble', async () => {render(<GhostPanelWindowLayout />);- fireEvent.click(screen.getByTestId('window-controls'));+ fireEvent.click(screen.getByRole('button', { name: 'titleBar.minimize' }));expect(mocks.minimizeGhostPanel).toHaveBeenCalledWith('test-ghost');expect(window.electronAPI.ghostPanelWindow.setDetached).toHaveBeenCalledWith(@@ -218,7 +239,7 @@ describe('reusable auxiliary window chrome', () => {render(<GhostPanelWindowLayout />);await act(async () => {- fireEvent.click(screen.getByTestId('window-controls'));+ fireEvent.click(screen.getByRole('button', { name: 'titleBar.minimize' }));});expect(mocks.minimizeGhostPanel).toHaveBeenCalledWith('test-ghost');@@ -236,4 +257,15 @@ describe('reusable auxiliary window chrome', () => {false,);});++ it('respects a plugin manifest that disables minimize in the detached window', async () => {+ mocks.ghostMinimizeEnabled = false;++ render(<GhostPanelWindowLayout />);++ expect(screen.queryByRole('button', { name: 'titleBar.minimize' })).toBeNull();+ expect(window.electronAPI.ghostPanelWindow.onMinimizeRequested).not.toHaveBeenCalled();+ expect(mocks.ghostMinimizeListener).toBeNull();+ expect(mocks.minimizeGhostPanel).not.toHaveBeenCalled();+ });});diff --git a/apps/desktop/src/renderer/components/title-bar/WindowControls.tsx b/apps/desktop/src/renderer/components/title-bar/WindowControls.tsxindex ec9a25e48d..5f2abaedfd 100644--- a/apps/desktop/src/renderer/components/title-bar/WindowControls.tsx+++ b/apps/desktop/src/renderer/components/title-bar/WindowControls.tsx@@ -22,6 +22,8 @@ interface WindowControlsProps {iconClassName?: string;/** Override the default minimize action for an auxiliary window. */onMinimize?: () => void | Promise<void>;+ /** Hide minimize when the current surface explicitly opts out of that action. */+ showMinimize?: boolean;/** Override the default close action for an auxiliary window. */onClose?: () => void | Promise<void>;}@@ -31,6 +33,7 @@ const DEFAULT_ICON_CLASS = 'text-titlebar-icon';export function WindowControls({iconClassName = DEFAULT_ICON_CLASS,onMinimize,+ showMinimize = true,onClose,}: WindowControlsProps = {}) {const [showCloseDialog, setShowCloseDialog] = useState(false);@@ -180,13 +183,15 @@ export function WindowControls({return (<><div className="flex gap-0.5">- <button- className={cn(controlBase, 'hover:bg-titlebar-control-hover')}- onClick={handleMinimizeClick}- aria-label={t('titleBar.minimize')}- >- <Minus size={14} />- </button>+ {showMinimize && (+ <button+ className={cn(controlBase, 'hover:bg-titlebar-control-hover')}+ onClick={handleMinimizeClick}+ aria-label={t('titleBar.minimize')}+ >+ <Minus size={14} />+ </button>+ )}<buttonclassName={cn(controlBase, 'hover:bg-titlebar-control-hover')}onClick={() => window.electronAPI.windowMaximize()}