From dc9f2ef8ceeef0d2ccd8d132ef713ce10f7f8d0a Mon Sep 17 00:00:00 2001 From: t4we fan Date: Tue, 25 Aug 2026 01:12:34 +0800 Subject: [PATCH] fix(desktop): size dialogs by content area --- dsh-plugin-desktop/src/desktop-dialog-window.ts | 13 +++++++++---- .../tests/desktop-dialog-window.spec.ts | 8 +++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dsh-plugin-desktop/src/desktop-dialog-window.ts b/dsh-plugin-desktop/src/desktop-dialog-window.ts index 770a4bce5e..c18580f4c8 100644 --- a/dsh-plugin-desktop/src/desktop-dialog-window.ts +++ b/dsh-plugin-desktop/src/desktop-dialog-window.ts @@ -155,11 +155,16 @@ export class DesktopDialogWindow { } const renderedHeight = parseDesktopDialogLayout(href) if (renderedHeight === undefined || window.isDestroyed()) return - const bounds = window.getBounds() + const previousBounds = window.getBounds() + // The renderer reports web-content height. setBounds() consumes the + // outer window height and clips the footer wherever native chrome or + // invisible window borders consume part of that space. + window.setContentSize(DIALOG_WIDTH, renderedHeight, false) + const sizedBounds = window.getBounds() window.setBounds({ - ...bounds, - y: bounds.y + Math.round((bounds.height - renderedHeight) / 2), - height: renderedHeight, + ...sizedBounds, + x: previousBounds.x + Math.round((previousBounds.width - sizedBounds.width) / 2), + y: previousBounds.y + Math.round((previousBounds.height - sizedBounds.height) / 2), }, false) layoutReady = true if (documentReady) reveal() diff --git a/dsh-plugin-desktop/tests/desktop-dialog-window.spec.ts b/dsh-plugin-desktop/tests/desktop-dialog-window.spec.ts index c71f3d2485..180dc79d39 100644 --- a/dsh-plugin-desktop/tests/desktop-dialog-window.spec.ts +++ b/dsh-plugin-desktop/tests/desktop-dialog-window.spec.ts @@ -22,6 +22,11 @@ const electron = vi.hoisted(() => { private bounds: Electron.Rectangle readonly getBounds = vi.fn(() => ({ ...this.bounds })) readonly setBounds = vi.fn((bounds: Electron.Rectangle) => { this.bounds = { ...bounds } }) + readonly setContentSize = vi.fn((width: number, height: number) => { + // Model native/invisible chrome so the test distinguishes content size + // from outer bounds instead of accidentally treating them as identical. + this.bounds = { ...this.bounds, width: width + 8, height: height + 12 } + }) readonly loadFile = vi.fn(async () => {}) readonly once = vi.fn((event: string, listener: Listener) => { this.onceListeners.set(event, listener) }) readonly on = vi.fn((event: string, listener: Listener) => { this.listeners.set(event, listener) }) @@ -102,7 +107,8 @@ describe('DesktopDialogWindow', () => { const layoutEvent = { preventDefault: vi.fn() } navigate?.(layoutEvent, 'dsh-desktop-dialog://layout?height=236') expect(layoutEvent.preventDefault).toHaveBeenCalledOnce() - expect(window?.setBounds).toHaveBeenCalledWith({ x: 0, y: 32, width: 480, height: 236 }, false) + expect(window?.setContentSize).toHaveBeenCalledWith(480, 236, false) + expect(window?.setBounds).toHaveBeenCalledWith({ x: -4, y: 26, width: 488, height: 248 }, false) expect(window?.show).toHaveBeenCalledOnce() const event = { preventDefault: vi.fn() } navigate?.(event, 'dsh-desktop-dialog://response?id=0')