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): prevent sidebar prewarm state restore (#3354)

DavidShenXD1721aa55b53e
diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/windowState.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/windowState.test.ts
new file mode 100644
index 0000000000..064fbf864f
--- /dev/null
+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/windowState.test.ts
@@ -0,0 +1,53 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({
+ manage: vi.fn(),
+ windowStateKeeper: vi.fn(),
+}));
+
+vi.mock('electron-window-state', () => ({ default: mocks.windowStateKeeper }));
+vi.mock('../../logger.js', () => ({
+ createLogger: () => ({ info: vi.fn(), warn: vi.fn(), error: vi.fn() }),
+}));
+vi.mock('../../windowFocusClassifier.js', () => ({ markAppContentWindow: vi.fn() }));
+vi.mock('../../window-behavior-settings-store.js', () => ({
+ readWindowBehaviorSettings: () => ({ swallowActivationClick: true }),
+}));
+vi.mock('../../secondary-windows.js', () => ({ installExternalLinkGuards: vi.fn() }));
+vi.mock('../../selection-context-menu.js', () => ({ installSelectionContextMenu: vi.fn() }));
+vi.mock('../../appearance-settings-ipc.js', () => ({ applyAppearanceToWindow: vi.fn() }));
+vi.mock('../registry.js', () => ({ markRsbWindowWebContentsId: vi.fn() }));
+
+import { createRightSidebarWindow } from '../window';
+
+describe('createRightSidebarWindow window state', () => {
+ beforeEach(() => {
+ mocks.windowStateKeeper.mockReturnValue({
+ x: 100,
+ y: 120,
+ width: 520,
+ height: 860,
+ manage: mocks.manage,
+ });
+ vi.stubGlobal('MAIN_WINDOW_VITE_DEV_SERVER_URL', undefined);
+ vi.stubGlobal('MAIN_WINDOW_VITE_NAME', 'main_window');
+ });
+
+ afterEach(() => {
+ vi.clearAllMocks();
+ vi.unstubAllGlobals();
+ });
+
+ it('restores geometry without restoring modes that can reveal the hidden prewarm window', () => {
+ const win = createRightSidebarWindow();
+
+ expect(mocks.windowStateKeeper).toHaveBeenCalledWith({
+ defaultWidth: 520,
+ defaultHeight: 860,
+ file: 'right-sidebar-window-state.json',
+ maximize: false,
+ fullScreen: false,
+ });
+ expect(mocks.manage).toHaveBeenCalledWith(win);
+ });
+});
diff --git a/apps/desktop/src/main/right-sidebar-window/window.ts b/apps/desktop/src/main/right-sidebar-window/window.ts
index 309f4e1157..55edfeb372 100644
--- a/apps/desktop/src/main/right-sidebar-window/window.ts
+++ b/apps/desktop/src/main/right-sidebar-window/window.ts
@@ -39,6 +39,10 @@ export function createRightSidebarWindow(): BrowserWindow {
defaultWidth: 520,
defaultHeight: 860,
file: 'right-sidebar-window-state.json',
+ // The window is prewarmed while hidden on every launch. Restoring either
+ // presentation mode can make Electron show it before the controller opens it.
+ maximize: false,
+ fullScreen: false,
});
const win = new BrowserWindow({