api/controls: add bounds option to show()

This commit is contained in:
CanadaHonk 2023-01-27 21:52:16 +00:00
parent c637ab8492
commit 572bb0cdbe
2 changed files with 29 additions and 5 deletions

23
gluon.d.ts vendored
View File

@ -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<void>,
@ -289,8 +303,11 @@ type ControlsApi = {
*/
maximize(): Promise<void>,
/** Show (unminimize) the browser window. */
show(): Promise<void>
/** 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<void>
};
type Window = {

11
src/api/controls.js vendored
View File

@ -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);
}
};
};