api/controls: add bounds option to show()
This commit is contained in:
parent
c637ab8492
commit
572bb0cdbe
23
gluon.d.ts
vendored
23
gluon.d.ts
vendored
@ -210,7 +210,7 @@ type IdleAutoOptions = {
|
|||||||
* How long the window should be minimized before hibernating, in seconds.
|
* How long the window should be minimized before hibernating, in seconds.
|
||||||
* @default 5
|
* @default 5
|
||||||
*/
|
*/
|
||||||
timeMinimizedToHibernate?: Number
|
timeMinimizedToHibernate?: number
|
||||||
};
|
};
|
||||||
|
|
||||||
type IdleApi = {
|
type IdleApi = {
|
||||||
@ -279,6 +279,20 @@ type BrowserVersions = {
|
|||||||
jsEngine: VersionInfo
|
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 = {
|
type ControlsApi = {
|
||||||
/** Minimize the browser window. */
|
/** Minimize the browser window. */
|
||||||
minimize(): Promise<void>,
|
minimize(): Promise<void>,
|
||||||
@ -289,8 +303,11 @@ type ControlsApi = {
|
|||||||
*/
|
*/
|
||||||
maximize(): Promise<void>,
|
maximize(): Promise<void>,
|
||||||
|
|
||||||
/** Show (unminimize) the browser window. */
|
/** Show (unminimize) the browser window and optionally set the bounds (position/size). */
|
||||||
show(): Promise<void>
|
show(
|
||||||
|
/** Set the bounds (position and/or size) of the browser window optionally as well. */
|
||||||
|
bounds?: WindowBounds
|
||||||
|
): Promise<void>
|
||||||
};
|
};
|
||||||
|
|
||||||
type Window = {
|
type Window = {
|
||||||
|
11
src/api/controls.js
vendored
11
src/api/controls.js
vendored
@ -1,7 +1,13 @@
|
|||||||
export default async (CDP) => {
|
export default async (CDP) => {
|
||||||
const { windowId } = await CDP.send('Browser.getWindowForTarget');
|
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 {
|
return {
|
||||||
minimize: async () => {
|
minimize: async () => {
|
||||||
@ -12,9 +18,10 @@ export default async (CDP) => {
|
|||||||
await setWindowState('maximized');
|
await setWindowState('maximized');
|
||||||
},
|
},
|
||||||
|
|
||||||
show: async () => {
|
show: async bounds => {
|
||||||
await setWindowState('minimized');
|
await setWindowState('minimized');
|
||||||
await setWindowState('normal');
|
await setWindowState('normal');
|
||||||
|
if (bounds) await setWindowState(undefined, bounds);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user