Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 限定插件分离面板变更范围
DavidShen368757c07c9f
diff --git a/apps/desktop/src/main/ghost-panel-window/__tests__/preload-contract.test.ts b/apps/desktop/src/main/ghost-panel-window/__tests__/preload-contract.test.tsindex 53daae0271..2b836405d9 100644--- a/apps/desktop/src/main/ghost-panel-window/__tests__/preload-contract.test.ts+++ b/apps/desktop/src/main/ghost-panel-window/__tests__/preload-contract.test.ts@@ -84,6 +84,13 @@ describe('ghost panel preload contract', () => {]));});+ it('guards plugin mutations to the current detached panel id', () => {+ expect(source).toContain("new URLSearchParams(window.location.search).get('ghostPanelWindow')");+ expect(source).toContain('mutationErrorForGhostPanel(id)');+ expect(source).toContain("ipcRenderer.invoke('ghosts:reload', id)");+ expect(source).toContain("ipcRenderer.invoke('ghosts:set-enabled', id, enabled)");+ });+it('uses shared lifecycle channel constants', () => {expect(source).toContain('GHOST_PANEL_WINDOW_RENDERER_READY_CHANNEL');expect(source).toContain('GHOST_PANEL_WINDOW_PRESENTATION_READY_CHANNEL');diff --git a/apps/desktop/src/preload/ghostPanelWindowPreload.ts b/apps/desktop/src/preload/ghostPanelWindowPreload.tsindex 1035fbd34e..d9610bbc79 100644--- a/apps/desktop/src/preload/ghostPanelWindowPreload.ts+++ b/apps/desktop/src/preload/ghostPanelWindowPreload.ts@@ -20,6 +20,7 @@ import { contextBridge, ipcRenderer } from 'electron';import type { AppearanceSettings } from '../shared/appearanceSettings';import type { LocalThemesResult } from '../shared/local-themes';import type { GhostPanelWindowsState } from '../shared/ghostPanelWindow';+import { isValidGhostId } from '../shared/ghost';import { DEFAULT_LOCALE, SUPPORTED_LOCALES, type SupportedLocale } from '../shared/locale';import {GHOST_PANEL_WINDOW_CLOSE_REQUESTED_CHANNEL,@@ -51,6 +52,18 @@ function onPayload<T>(channel: string, cb: (payload: T) => void): Unsub {return () => ipcRenderer.removeListener(channel, listener);}+const currentGhostPanelId = (() => {+ const raw = new URLSearchParams(window.location.search).get('ghostPanelWindow');+ return isValidGhostId(raw) ? raw : null;+})();++function mutationErrorForGhostPanel(id: string): Error | null {+ if (currentGhostPanelId === null || id !== currentGhostPanelId) {+ return new Error('ghost panel mutation must target the current panel');+ }+ return null;+}+// 事件扇出型通道(main 广播 → 所有 renderer),按名注册 listener,fan-out 在 preload 层。function fanOut(channel: string): (cb: (payload: unknown) => void) => Unsub {return (cb) => {@@ -179,10 +192,17 @@ contextBridge.exposeInMainWorld('electronAPI', {/** 已装清单(同步:与面板体同帧渲染,不闪占位)。 */listSync: (): { ghosts: unknown[] } => ipcRenderer.sendSync('ghosts:list'),/** 重载插件(面板崩溃后恢复)。 */- reload: (id: string): Promise<{ state: string }> => ipcRenderer.invoke('ghosts:reload', id),+ reload: (id: string): Promise<{ state: string }> => {+ const error = mutationErrorForGhostPanel(id);+ if (error) return Promise.reject(error);+ return ipcRenderer.invoke('ghosts:reload', id);+ },/** 启用/停用(面板错误态「关闭」按钮)。 */- setEnabled: (id: string, enabled: boolean): Promise<{ ok: true }> =>- ipcRenderer.invoke('ghosts:set-enabled', id, enabled),+ setEnabled: (id: string, enabled: boolean): Promise<{ ok: true }> => {+ const error = mutationErrorForGhostPanel(id);+ if (error) return Promise.reject(error);+ return ipcRenderer.invoke('ghosts:set-enabled', id, enabled);+ },/** 解析面板媒体 URI → cindy-media:// 地址(右键菜单 / 拖拽引渡)。 */resolvePanelMedia: (uri: string,