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): 清理隐藏侧栏浏览器会话

DavidShen1170adb1f83d
diff --git a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
index 8694521de2..81267a1297 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/RightSidebarShell.tsx
@@ -209,6 +209,7 @@ export function RightSidebarShell({
);
const getBucketSnapshot = useCallback(() => getBucket(sessionId), [sessionId]);
const bucket = useSyncExternalStore(subscribeBucket, getBucketSnapshot);
+ const previousShellVisibleRef = useRef(shellVisible);
useEffect(() => {
// Phase 5: 推送当前焦点 RSB sessionId 给 main,让 RsbWebviewBackend 拿到。
@@ -219,7 +220,12 @@ export function RightSidebarShell({
void window.electronAPI?.rsbBrowserBridge
?.setActiveSession({ sessionId })
.catch(() => undefined);
+ } else if (previousShellVisibleRef.current) {
+ void window.electronAPI?.rsbBrowserBridge
+ ?.setActiveSession({ sessionId: null })
+ .catch(() => undefined);
}
+ previousShellVisibleRef.current = shellVisible;
if (!sessionId) return;
// 首次访问该 sessionId 时触发 IPC list 拉取;命中 cache 直接 noop。
// 完成后 setBucket → notify → subscribeBucket 唤醒 useSyncExternalStore 重渲染。
diff --git a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
index d0c2290510..1ad6f523eb 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/__tests__/RightSidebarShell.test.ts
@@ -266,7 +266,7 @@ describe('RightSidebarShell empty state', () => {
delete (window as unknown as { electronAPI?: unknown }).electronAPI;
});
- it('does not replace the active browser session while the detached shell is hidden', async () => {
+ it('clears the active browser session only when a visible detached shell is hidden', async () => {
const setActiveSession = window.electronAPI.rsbBrowserBridge.setActiveSession;
const view = render(
createElement(RightSidebarShell, {
@@ -292,6 +292,18 @@ describe('RightSidebarShell empty state', () => {
);
await waitFor(() => expect(setActiveSession).toHaveBeenCalledWith({ sessionId: 's1' }));
+
+ view.rerender(
+ createElement(RightSidebarShell, {
+ sessionId: 's1',
+ workdir: '/tmp/repo',
+ remoteHostId: null,
+ shellVisible: false,
+ isMac: true,
+ }),
+ );
+
+ await waitFor(() => expect(setActiveSession).toHaveBeenCalledWith({ sessionId: null }));
});
it('mounts only the active body first, then idle-mounts and keeps the rest alive', async () => {