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): 暂停隐藏侧栏的后台交互

DavidShen8dc7d0eb94e0
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 572f6f0471..93df9bd8ee 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
@@ -709,6 +709,26 @@ describe('setContext / routeCommand', () => {
expect(h.sends.at(-1)).toEqual({ channel: 'cmd-channel', payload: cmd });
});
+ it('queues passive commands while a cached detached window is hidden and flushes on reopen', async () => {
+ const h = makeHarness({ detached: true });
+ h.controller.setContext(ctx);
+ h.controller.prewarm();
+ const win = h.windows[0];
+ markReady(h.controller, win);
+ h.controller.open();
+ h.controller.close();
+ h.sends.length = 0;
+
+ const cmd = { type: 'close-orca-workers-tab' as const, sessionId: 's1' };
+ await expect(
+ h.controller.routeCommand({ command: cmd, allowOpen: false }),
+ ).resolves.toBe('queued');
+ expect(h.sends).toEqual([]);
+
+ h.controller.open();
+ expect(h.sends).toContainEqual({ channel: 'cmd-channel', payload: cmd });
+ });
+
it('detach preference change mid-wait: returns attached, no send to destroyed host', 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 821b0e23f5..129bd75ba8 100644
--- a/apps/desktop/src/main/right-sidebar-window/controller.ts
+++ b/apps/desktop/src/main/right-sidebar-window/controller.ts
@@ -357,7 +357,7 @@ export class RsbWindowController {
if (!this.canDispatchCommand(command)) return 'stale-context';
const windowAlive = this.winRef && !this.winRef.isDestroyed();
- if (!allowOpen && (!windowAlive || !this.presentationReady)) {
+ if (!allowOpen && (!windowAlive || !this.presentationReady || !this.visible)) {
this.enqueueDeferredCommand(command);
return 'queued';
}
@@ -498,6 +498,9 @@ export class RsbWindowController {
this.visible = true;
// lastOpen 由 open() 在外层写,这里只负责展示
this.deps.sendToWindow(win, RSB_WINDOW_VISIBILITY_CHANGED_CHANNEL, { visible: true });
+ // 隐藏复用期间的 passive 命令不能在用户看不见时改动子窗口 store;
+ // 窗口重新显示后按原顺序统一交付。
+ this.flushDeferredCommandsToDetachedHost();
this.broadcast();
}
diff --git a/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx b/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx
index afe30f4188..91581a06c0 100644
--- a/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/SidebarWindowLayout.tsx
@@ -72,6 +72,8 @@ export function SidebarWindowLayout() {
}, []);
const isMac = window.electronAPI?.platform === 'darwin';
const [ctx, setCtx] = useState<SidebarWindowContext | null>(null);
+ // 预热窗口初始隐藏;由 main 的 visibility push 驱动 Shell 内各子面板暂停/恢复。
+ const [windowVisible, setWindowVisible] = useState(false);
const presentationReadySentRef = useRef(false);
// 复用隐藏窗口时,Chromium 可能保留上一次关闭按钮的 focus / :hover 状态。
// 与资源用量窗口一致,隐藏时重挂载 chrome,确保再次显示从干净状态开始。
@@ -120,6 +122,7 @@ export function SidebarWindowLayout() {
// 隐藏/显示时刷新 context(主窗 session 可能已切换)并重置瞬时交互态。
useEffect(() => {
return window.electronAPI.rightSidebarWindow.onVisibilityChanged((payload) => {
+ setWindowVisible(payload.visible);
if (!payload.visible) {
if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
setWindowChromeRevision((revision) => revision + 1);
@@ -243,6 +246,7 @@ export function SidebarWindowLayout() {
workdir={ctx?.workdir ?? ''}
remoteHostId={ctx?.remoteHostId ?? null}
deviceLinkDeviceId={ctx?.deviceLinkDeviceId}
+ shellVisible={windowVisible}
isMac={isMac}
/>
{!sessionId && (
diff --git a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx
index 2baae6c815..4429377dcf 100644
--- a/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx
+++ b/apps/desktop/src/renderer/components/layout/__tests__/ReusableWindowChrome.test.tsx
@@ -10,6 +10,7 @@ const mocks = vi.hoisted(() => ({
ghostVisibilityListener: null as ((payload: { visible: boolean }) => void) | null,
ghostMinimizeListener: null as (() => void) | null,
ghostMinimizeEnabled: true,
+ sidebarShellVisible: undefined as boolean | undefined,
minimizeGhostPanel: vi.fn(),
restoreGhostPanel: vi.fn(),
}));
@@ -36,7 +37,12 @@ vi.mock('@/components/title-bar/WindowControls', () => ({
);
},
}));
-vi.mock('@/features/right-sidebar/RightSidebarShell', () => ({ RightSidebarShell: () => null }));
+vi.mock('@/features/right-sidebar/RightSidebarShell', () => ({
+ RightSidebarShell: ({ shellVisible }: { shellVisible?: boolean }) => {
+ mocks.sidebarShellVisible = shellVisible;
+ return null;
+ },
+}));
vi.mock('@/features/device-link/useDeviceLinkRemoteProjects', () => ({
useDeviceLinkRemoteProjects: vi.fn(),
}));
@@ -121,6 +127,7 @@ describe('reusable auxiliary window chrome', () => {
mocks.ghostVisibilityListener = null;
mocks.ghostMinimizeListener = null;
mocks.ghostMinimizeEnabled = true;
+ mocks.sidebarShellVisible = undefined;
Object.defineProperty(window, 'electronAPI', {
configurable: true,
value: {
@@ -258,6 +265,17 @@ describe('reusable auxiliary window chrome', () => {
);
});
+ it('passes cached-window visibility through to right-sidebar tab bodies', async () => {
+ render(<SidebarWindowLayout />);
+ expect(mocks.sidebarShellVisible).toBe(false);
+
+ await act(async () => mocks.sidebarVisibilityListener?.({ visible: true }));
+ expect(mocks.sidebarShellVisible).toBe(true);
+
+ await act(async () => mocks.sidebarVisibilityListener?.({ visible: false }));
+ expect(mocks.sidebarShellVisible).toBe(false);
+ });
+
it('respects a plugin manifest that disables minimize in the detached window', async () => {
mocks.ghostMinimizeEnabled = false;