Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 门控隐藏侧栏上下文与宿主

DavidShen68d836415b93
diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts
index 18537af09b..603cf5befb 100644
--- a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts
+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts
@@ -637,6 +637,28 @@ describe('getHostWebContents', () => {
expect(h.controller.getHostWebContents()).toBe(win.webContents);
});
+ it('detached + cached window hidden → main window webContents', () => {
+ const h = makeHarness({ detached: true });
+ h.controller.prewarm();
+ const win = h.windows[0];
+ markReady(h.controller, win);
+ h.controller.open();
+ h.controller.close();
+
+ expect(h.controller.getHostWebContents()).toBe(h.mainWin.webContents);
+ });
+
+ it('detached + native-minimized window → main window webContents', () => {
+ const h = makeHarness({ detached: true });
+ h.controller.prewarm();
+ const win = h.windows[0];
+ markReady(h.controller, win);
+ h.controller.open();
+ win.emitWindowEvent('minimize');
+
+ expect(h.controller.getHostWebContents()).toBe(h.mainWin.webContents);
+ });
+
it('after destroy: falls back to main', () => {
const h = makeHarness({ detached: true });
h.controller.prewarm();
@@ -677,6 +699,29 @@ describe('setContext / routeCommand', () => {
});
});
+ it('ignores refreshContext while the cached sidebar window is hidden', () => {
+ const h = makeHarness({ detached: true });
+ h.controller.prewarm();
+ const win = h.windows[0];
+ markReady(h.controller, win);
+ h.controller.setContext(ctx);
+
+ h.controller.refreshContext(win.webContents as unknown as WebContents);
+ expect(h.sends.filter((entry) => entry.channel === 'ctx-channel')).toEqual([]);
+
+ h.controller.open();
+ h.controller.refreshContext(win.webContents as unknown as WebContents);
+ expect(h.sends.filter((entry) => entry.channel === 'ctx-channel')).toEqual([
+ { channel: 'ctx-channel', payload: ctx },
+ ]);
+
+ h.controller.close();
+ h.controller.refreshContext(win.webContents as unknown as WebContents);
+ expect(h.sends.filter((entry) => entry.channel === 'ctx-channel')).toEqual([
+ { channel: 'ctx-channel', payload: ctx },
+ ]);
+ });
+
it('detached + allowOpen: opens window, waits ready, routes', async () => {
const h = makeHarness({ detached: true });
h.controller.setContext(ctx);
diff --git a/apps/desktop/src/main/right-sidebar-window/controller.ts b/apps/desktop/src/main/right-sidebar-window/controller.ts
index 1c8cc7b58f..137c64c03c 100644
--- a/apps/desktop/src/main/right-sidebar-window/controller.ts
+++ b/apps/desktop/src/main/right-sidebar-window/controller.ts
@@ -282,6 +282,9 @@ export class RsbWindowController {
refreshContext(sender: WebContents): void {
const win = this.winRef;
if (!win || win.isDestroyed() || sender !== win.webContents) return;
+ // 隐藏预热/复用窗口只保留已挂载的标签主体,不接收新的会话上下文。
+ // 显示时 renderer 会重新请求最新快照,再恢复交互。
+ if (!this.visible) return;
if (!this.lastContext) return;
this.deps.sendToWindow(win, this.deps.contextChannel, this.lastContext);
}
@@ -398,6 +401,7 @@ export class RsbWindowController {
getHostWebContents(): WebContents | null {
if (
this.deps.settings.read().detached &&
+ this.visible &&
this.winRef &&
!this.winRef.isDestroyed()
) {