From 41efb3f95bfd2795a8c463b1686a93e1c8fa27e4 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Fri, 25 Mar 2016 22:03:15 +0100 Subject: [PATCH] Update browser-window module --- github-electron/github-electron-main-tests.ts | 2 +- .../github-electron.browser-window.d.ts | 514 +++++++++++++++++- 2 files changed, 497 insertions(+), 19 deletions(-) diff --git a/github-electron/github-electron-main-tests.ts b/github-electron/github-electron-main-tests.ts index af44415b8..76084ad9f 100644 --- a/github-electron/github-electron-main-tests.ts +++ b/github-electron/github-electron-main-tests.ts @@ -462,7 +462,7 @@ var template = [ { label: 'Reload', accelerator: 'Command+R', - click: () => { BrowserWindow.getFocusedWindow().reloadIgnoringCache(); } + click: () => { BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache(); } }, { label: 'Toggle DevTools', diff --git a/github-electron/github-electron.browser-window.d.ts b/github-electron/github-electron.browser-window.d.ts index 0fafe6685..35383a90a 100644 --- a/github-electron/github-electron.browser-window.d.ts +++ b/github-electron/github-electron.browser-window.d.ts @@ -15,6 +15,103 @@ declare namespace Electron { * You can also create a window without chrome by using Frameless Window API. */ class BrowserWindow extends EventEmitter { + /** + * Emitted when the document changed its title, + * calling event.preventDefault() would prevent the native window’s title to change. + */ + on(event: 'page-title-updated', listener: (event: Event) => void): this; + /** + * Emitted when the window is going to be closed. It’s emitted before the beforeunload + * and unload event of the DOM. Calling event.preventDefault() will cancel the close. + */ + on(event: 'close', listener: (event: Event) => void): this; + /** + * Emitted when the window is closed. After you have received this event + * you should remove the reference to the window and avoid using it anymore. + */ + on(event: 'closed', listener: Function): this; + /** + * Emitted when the web page becomes unresponsive. + */ + on(event: 'unresponsive', listener: Function): this; + /** + * Emitted when the unresponsive web page becomes responsive again. + */ + on(event: 'responsive', listener: Function): this; + /** + * Emitted when the window loses focus. + */ + on(event: 'blur', listener: Function): this; + /** + * Emitted when the window gains focus. + */ + on(event: 'focus', listener: Function): this; + /** + * Emitted when the window is shown. + */ + on(event: 'show', listener: Function): this; + /** + * Emitted when the window is hidden. + */ + on(event: 'hide', listener: Function): this; + /** + * Emitted when window is maximized. + */ + on(event: 'maximize', listener: Function): this; + /** + * Emitted when the window exits from maximized state. + */ + on(event: 'unmaximize', listener: Function): this; + /** + * Emitted when the window is minimized. + */ + on(event: 'minimize', listener: Function): this; + /** + * Emitted when the window is restored from minimized state. + */ + on(event: 'restore', listener: Function): this; + /** + * Emitted when the window is getting resized. + */ + on(event: 'resize', listener: Function): this; + /** + * Emitted when the window is getting moved to a new position. + */ + on(event: 'move', listener: Function): this; + /** + * Emitted when the window enters full screen state. + */ + on(event: 'enter-full-screen', listener: Function): this; + /** + * Emitted when the window leaves full screen state. + */ + on(event: 'leave-full-screen', listener: Function): this; + /** + * Emitted when the window enters full screen state triggered by HTML API. + */ + on(event: 'enter-html-full-screen', listener: Function): this; + /** + * Emitted when the window leaves full screen state triggered by HTML API. + */ + on(event: 'leave-html-full-screen', listener: Function): this; + /** + * Emitted when an App Command is invoked. These are typically related + * to keyboard media keys or browser commands, as well as the "Back" / + * "Forward" buttons built into some mice on Windows. + * Note: This is only implemented on Windows. + */ + on(event: 'app-command', listener: (event: Event, command: string) => void): this; + /** + * Emitted when scroll wheel event phase has begun. + * Note: This is only implemented on OS X. + */ + on(event: 'scroll-touch-begin', listener: Function): this; + /** + * Emitted when scroll wheel event phase has ended. + * Note: This is only implemented on OS X. + */ + on(event: 'scroll-touch-end', listener: Function): this; + on(event: string, listener: Function): this; constructor(options?: BrowserWindowOptions); /** * @returns All opened browser windows. @@ -50,12 +147,6 @@ declare namespace Electron { * the renderer process (web page) has crashed. */ webContents: WebContents; - /** - * Get the WebContents of devtools of this window. - * Note: Users should never store this object because it may become null when - * the devtools has been closed. - */ - devToolsWebContents: WebContents; /** * Get the unique ID of this window. */ @@ -77,6 +168,10 @@ declare namespace Electron { * Focus on the window. */ focus(): void; + /** + * Remove focus on the window. + */ + blur(): void; /** * @returns Whether the window is focused. */ @@ -130,10 +225,22 @@ declare namespace Electron { * @returns Whether the window is in fullscreen mode. */ isFullScreen(): boolean; + /** + * This will have a window maintain an aspect ratio. + * The extra size allows a developer to have space, specified in pixels, + * not included within the aspect ratio calculations. + * This API already takes into account the difference between a window’s size and its content size. + * + * Note: This API is available only on OS X. + */ + setAspectRatio(aspectRatio: number, extraSize?: { + width: number, + height: number + }): void; /** * Resizes and moves the window to width, height, x, y. */ - setBounds(options: Rectangle): void; + setBounds(options: Rectangle, animate?: boolean): void; /** * @returns The window's width, height, x and y values. */ @@ -141,7 +248,7 @@ declare namespace Electron { /** * Resizes the window to width and height. */ - setSize(width: number, height: number): void; + setSize(width: number, height: number, animate?: boolean): void; /** * @returns The window's width and height. */ @@ -149,7 +256,7 @@ declare namespace Electron { /** * Resizes the window's client area (e.g. the web page) to width and height. */ - setContentSize(width: number, height: number): void; + setContentSize(width: number, height: number, animate?: boolean): void; /** * @returns The window's client area's width and height. */ @@ -178,6 +285,54 @@ declare namespace Electron { * @returns Whether the window can be manually resized by user. */ isResizable(): boolean; + /** + * Sets whether the window can be moved by user. On Linux does nothing. + * Note: This API is available only on OS X and Windows. + */ + setMovable(movable: boolean): void; + /** + * Note: This API is available only on OS X and Windows. + * @returns Whether the window can be moved by user. On Linux always returns true. + */ + isMovable(): boolean; + /** + * Sets whether the window can be manually minimized by user. On Linux does nothing. + * Note: This API is available only on OS X and Windows. + */ + setMinimizable(minimizable: boolean): void; + /** + * Note: This API is available only on OS X and Windows. + * @returns Whether the window can be manually minimized by user. On Linux always returns true. + */ + isMinimizable(): boolean; + /** + * Sets whether the window can be manually maximized by user. On Linux does nothing. + * Note: This API is available only on OS X and Windows. + */ + setMaximizable(maximizable: boolean): void; + /** + * Note: This API is available only on OS X and Windows. + * @returns Whether the window can be manually maximized by user. On Linux always returns true. + */ + isMaximizable(): boolean; + /** + * Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window. + */ + setFullScreenable(fullscreenable: boolean): void; + /** + * @returns Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window. + */ + isFullScreenable(): boolean; + /** + * Sets whether the window can be manually closed by user. On Linux does nothing. + * Note: This API is available only on OS X and Windows. + */ + setClosable(closable: boolean): void; + /** + * Note: This API is available only on OS X and Windows. + * @returns Whether the window can be manually closed by user. On Linux always returns true. + */ + isClosable(): boolean; /** * Sets whether the window should show always on top of other windows. After * setting this, the window is still a normal window, not a toolbox window @@ -195,7 +350,7 @@ declare namespace Electron { /** * Moves window to x and y. */ - setPosition(x: number, y: number): void; + setPosition(x: number, y: number, animate?: boolean): void; /** * @returns The window's current position. */ @@ -225,6 +380,29 @@ declare namespace Electron { * @returns Whether the window is in kiosk mode. */ isKiosk(): boolean; + /** + * The native type of the handle is HWND on Windows, NSView* on OS X, + * and Window (unsigned long) on Linux. + * @returns The platform-specific handle of the window as Buffer. + */ + getNativeWindowHandle(): Buffer; + /** + * Hooks a windows message. The callback is called when the message is received in the WndProc. + * Note: This API is available only on Windows. + */ + hookWindowMessage(message: number, callback: Function): void; + /** + * @returns Whether the message is hooked. + */ + isWindowMessageHooked(message: number): boolean; + /** + * Unhook the window message. + */ + unhookWindowMessage(message: number): void; + /** + * Unhooks all of the window messages. + */ + unhookAllWindowMessages(): void; /** * Sets the pathname of the file the window represents, and the icon of the * file will show in window's title bar. @@ -247,11 +425,6 @@ declare namespace Electron { * @returns Whether the window's document has been edited. */ isDocumentEdited(): boolean; - reloadIgnoringCache(): void; - /** - * Starts inspecting element at position (x, y). - */ - inspectElement(x: number, y: number): void; focusOnWebView(): void; blurWebView(): void; /** @@ -315,6 +488,22 @@ declare namespace Electron { * @param description Provided to Accessibility screen readers. */ setOverlayIcon(overlay: NativeImage, description: string): void; + /** + * Sets whether the window should have a shadow. On Windows and Linux does nothing. + * Note: This API is available only on OS X. + */ + setHasShadow(hasShadow: boolean): void; + /** + * Note: This API is available only on OS X. + * @returns whether the window has a shadow. On Windows and Linux always returns true. + */ + hasShadow(): boolean; + /** + * Add a thumbnail toolbar with a specified set of buttons to the thumbnail image + * of a window in a taskbar button layout. + * @returns Whether the thumbnail has been added successfully. + */ + setThumbarButtons(buttons: ThumbarButton[]): boolean; /** * Shows pop-up dictionary that searches the selected word on the page. * Note: This API is available only on OS X. @@ -350,58 +539,347 @@ declare namespace Electron { * @returns Whether the window is visible on all workspaces. */ isVisibleOnAllWorkspaces(): boolean; + /** + * Ignore all moused events that happened in the window. + * Note: This API is available only on OS X. + */ + setIgnoreMouseEvents(ignore: boolean): void; + } + + type ThumbarButtonFlags = 'enabled' | 'disabled' | 'dismissonclick' | 'nobackground' | 'hidden' | 'noninteractive'; + + interface ThumbarButton { + icon: NativeImage | string; + click: Function; + tooltip?: string; + flags?: ThumbarButtonFlags[]; } interface WebPreferences { + /** + * Whether node integration is enabled. + * Default: true. + */ nodeIntegration?: boolean; + /** + * Specifies a script that will be loaded before other scripts run in the page. + * This script will always have access to node APIs no matter whether node integration is turned on or off. + * The value should be the absolute file path to the script. + * When node integration is turned off, the preload script can reintroduce + * Node global symbols back to the global scope. + */ preload?: string; + /** + * Sets the session used by the page. Instead of passing the Session object directly, + * you can also choose to use the partition option instead, which accepts a partition string. + * When both session and partition are provided, session would be preferred. + * Default: the default session. + */ session?: Session; + /** + * Sets the session used by the page according to the session’s partition string. + * If partition starts with persist:, the page will use a persistent session available + * to all pages in the app with the same partition. if there is no persist: prefix, + * the page will use an in-memory session. By assigning the same partition, + * multiple pages can share the same session. + * Default: the default session. + */ partition?: string; + /** + * The default zoom factor of the page, 3.0 represents 300%. + * Default: 1.0. + */ zoomFactor?: number; + /** + * Enables JavaScript support. + * Default: true. + */ javascript?: boolean; + /** + * When setting false, it will disable the same-origin policy (Usually using testing + * websites by people), and set allowDisplayingInsecureContent and allowRunningInsecureContent + * to true if these two options are not set by user. + * Default: true. + */ webSecurity?: boolean; + /** + * Allow an https page to display content like images from http URLs. + * Default: false. + */ allowDisplayingInsecureContent?: boolean; + /** + * Allow a https page to run JavaScript, CSS or plugins from http URLs. + * Default: false. + */ allowRunningInsecureContent?: boolean; + /** + * Enables image support. + * Default: true. + */ images?: boolean; + /** + * Make TextArea elements resizable. + * Default: true. + */ textAreasAreResizable?: boolean; + /** + * Enables WebGL support. + * Default: true. + */ webgl?: boolean; + /** + * Enables WebAudio support. + * Default: true. + */ webaudio?: boolean; + /** + * Whether plugins should be enabled. + * Default: false. + */ plugins?: boolean; + /** + * Enables Chromium’s experimental features. + * Default: false. + */ experimentalFeatures?: boolean; + /** + * Enables Chromium’s experimental canvas features. + * Default: false. + */ experimentalCanvasFeatures?: boolean; + /** + * Enables DirectWrite font rendering system on Windows. + * Default: true. + */ directWrite?: boolean; + /** + * A list of feature strings separated by ",". + */ blinkFeatures?: string; + /** + * Sets the default font for the font-family. + */ + defaultFontFamily?: { + /** + * Default: Times New Roman. + */ + standard?: string; + /** + * Default: Times New Roman. + */ + serif?: string; + /** + * Default: Arial. + */ + sansSerif?: string; + /** + * Default: Courier New. + */ + monospace?: string; + }; + /** + * Default: 16. + */ + defaultFontSize?: number; + /** + * Default: 13. + */ + defaultMonospaceFontSize?: number; + /** + * Default: 0. + */ + minimumFontSize?: number; + /** + * Default: ISO-8859-1. + */ + defaultEncoding?: string; } interface BrowserWindowOptions extends Rectangle { + /** + * Window’s width in pixels. + * Default: 800. + */ + width?: number; + /** + * Window’s height in pixels. + * Default: 600. + */ + height?: number; + /** + * Window’s left offset from screen. + * Default: center the window. + */ + x?: number; + /** + * Window’s top offset from screen. + * Default: center the window. + */ + y?: number; + /** + * The width and height would be used as web page’s size, which means + * the actual window’s size will include window frame’s size and be slightly larger. + * Default: false. */ useContentSize?: boolean; + /** + * Show window in the center of the screen. + * Default: true + */ center?: boolean; + /** + * Window’s minimum width. + * Default: 0. + */ minWidth?: number; + /** + * Window’s minimum height. + * Default: 0. + */ minHeight?: number; + /** + * Window’s maximum width. + * Default: no limit. + */ maxWidth?: number; + /** + * Window’s maximum height. + * Default: no limit. + */ maxHeight?: number; + /** + * Whether window is resizable. + * Default: true. + */ resizable?: boolean; + /** + * Whether window is movable. + * Note: This is not implemented on Linux. + * Default: true. + */ + movable?: boolean; + /** + * Whether window is minimizable. + * Note: This is not implemented on Linux. + * Default: true. + */ + minimizable?: boolean; + /** + * Whether window is maximizable. + * Note: This is not implemented on Linux. + * Default: true. + */ + maximizable?: boolean; + /** + * Whether window is closable. + * Note: This is not implemented on Linux. + * Default: true. + */ + closable?: boolean; + /** + * Whether the window should always stay on top of other windows. + * Default: false. + */ alwaysOnTop?: boolean; + /** + * Whether the window should show in fullscreen. + * When explicity set to false the fullscreen button will be hidden or disabled on OS X. + * Default: false. + */ fullscreen?: boolean; + /** + * Whether the maximize/zoom button on OS X should toggle full screen mode or maximize window. + * Default: true. + */ + fullscreenable?: boolean; + /** + * Whether to show the window in taskbar. + * Default: false. + */ skipTaskbar?: boolean; + /** + * The kiosk mode. + * Default: false. + */ kiosk?: boolean; + /** + * Default window title. + * Default: "Electron". + */ title?: string; + /** + *The window icon, when omitted on Windows the executable’s icon would be used as window icon. + */ icon?: NativeImage|string; + /** + * Whether window should be shown when created. + * Default: true. + */ show?: boolean; + /** + * Specify false to create a Frameless Window. + * Default: true. + */ frame?: boolean; + /** + * Whether the web view accepts a single mouse-down event that simultaneously activates the window. + * Default: false. + */ acceptFirstMouse?: boolean; + /** + * Whether to hide cursor when typing. + * Default: false. + */ disableAutoHideCursor?: boolean; + /** + * Auto hide the menu bar unless the Alt key is pressed. + * Default: true. + */ autoHideMenuBar?: boolean; + /** + * Enable the window to be resized larger than screen. + * Default: false. + */ enableLargerThanScreen?: boolean; + /** + * Window’s background color as Hexadecimal value, like #66CD00 or #FFF or #80FFFFFF (alpha is supported). + * Default: #000 (black) for Linux and Windows, #FFF for Mac (or clear if transparent). + */ backgroundColor?: string; + /** + * Whether window should have a shadow. + * Note: This is only implemented on OS X. + * Default: true. + */ + hasShadow?: boolean; + /** + * Forces using dark theme for the window. + * Note: Only works on some GTK+3 desktop environments. + * Default: false. + */ darkTheme?: boolean; - preload?: string; + /** + * Makes the window transparent. + * Default: false. + */ transparent?: boolean; - type?: string; - titleBarStyle?: string; + /** + * The type of window, default is normal window. + */ + type?: BrowserWindowType; + /** + * The style of window title bar. + */ + titleBarStyle?: 'default' | 'hidden' | 'hidden-inset'; + /** + * Settings of web page’s features. + */ webPreferences?: WebPreferences; } + type BrowserWindowType = BrowserWindowTypeLinux | BrowserWindowTypeMac; + type BrowserWindowTypeLinux = 'desktop' | 'dock' | 'toolbar' | 'splash' | 'notification'; + type BrowserWindowTypeMac = 'desktop' | 'textured'; + interface Rectangle { x?: number; y?: number;