From 572bb0cdbe2883d2e689a2911410312f8f1f39df Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Fri, 27 Jan 2023 21:52:16 +0000 Subject: [PATCH] api/controls: add bounds option to show() --- gluon.d.ts | 23 ++++++++++++++++++++--- src/api/controls.js | 11 +++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gluon.d.ts b/gluon.d.ts index 75fd144..ce0316a 100644 --- a/gluon.d.ts +++ b/gluon.d.ts @@ -210,7 +210,7 @@ type IdleAutoOptions = { * How long the window should be minimized before hibernating, in seconds. * @default 5 */ - timeMinimizedToHibernate?: Number + timeMinimizedToHibernate?: number }; type IdleApi = { @@ -279,6 +279,20 @@ type BrowserVersions = { jsEngine: VersionInfo }; +type WindowBounds = { + /** The offset from the left edge of the screen to the window in pixels. */ + left?: number, + + /** The offset from the top edge of the screen to the window in pixels. */ + top?: number, + + /** The window width in pixels. */ + width?: number, + + /** The window height in pixels. */ + height?: number +}; + type ControlsApi = { /** Minimize the browser window. */ minimize(): Promise, @@ -289,8 +303,11 @@ type ControlsApi = { */ maximize(): Promise, - /** Show (unminimize) the browser window. */ - show(): Promise + /** Show (unminimize) the browser window and optionally set the bounds (position/size). */ + show( + /** Set the bounds (position and/or size) of the browser window optionally as well. */ + bounds?: WindowBounds + ): Promise }; type Window = { diff --git a/src/api/controls.js b/src/api/controls.js index 485aa19..b446863 100644 --- a/src/api/controls.js +++ b/src/api/controls.js @@ -1,7 +1,13 @@ export default async (CDP) => { const { windowId } = await CDP.send('Browser.getWindowForTarget'); - const setWindowState = async state => await CDP.send('Browser.setWindowBounds', { windowId, bounds: { windowState: state }}); + const setWindowState = (state, bounds = {}) => CDP.send('Browser.setWindowBounds', { + windowId, + bounds: { + windowState: state, + ...bounds + } + }); return { minimize: async () => { @@ -12,9 +18,10 @@ export default async (CDP) => { await setWindowState('maximized'); }, - show: async () => { + show: async bounds => { await setWindowState('minimized'); await setWindowState('normal'); + if (bounds) await setWindowState(undefined, bounds); } }; }; \ No newline at end of file