// Type definitions for nw.js 0.13 // Project: http://nwjs.io // Definitions by: Alireza Dabiri Nejad // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// /** * Helpers class and interfaces defined here, to make `nw` module cleaner. */ declare module NWJS_Helpers { /** * Node.js v6.x EventEmitter Class */ class EventEmitter extends NodeJS.EventEmitter { static EventEmitter: EventEmitter; static listenerCount( emitter: EventEmitter, event: string ): number; // deprecated static defaultMaxListeners: number; addListener( event: string, listener: Function ): this; on( event: string, listener: Function ): this; once( event: string, listener: Function ): this; removeListener( event: string, listener: Function ): this; removeAllListeners( event?: string ): this; setMaxListeners( n: number ): this; getMaxListeners(): number; listeners( event: string ): Function[]; emit( event: string, ...args: any[] ): boolean; listenerCount( type: string ): number; } /** * The clipboard object. */ interface clip { /** * Write `data` of `type` to the clipboard. * * @param data {string} the data to write to the clipboard * @param type {string} (Optional) the type of the data. Support text, png, jpeg, html and rtf. By default, type is set to "text". * @param raw {boolean} (Optional) requiring raw image data. This option is only valid if type is png or jpeg. By default, raw is set to false. */ set( data: string, type?: string, raw?: boolean ): void; /** * Get the data of `type` from clipboard. * * @param type {string} (Optional) the type of the data. Support text, png, jpeg, html and rtf. By default, type is set to "text". * @param raw {boolean} (Optional) requiring raw image data. This option is only valid if type is png or jpeg. * @returns {string} the data retrieved from the clipboard. */ get( type?: string, raw?: boolean ): string; /** * Get an array contains list of available types of data in clipboard currenly. * You can use the returned list as a suggestion to get the right data from clipboard. * * @returns {string[]} List of available types of data in clipboard currenly. */ readAvailableTypes(): string[]; /** * Clear the clipboard. */ clear(): void; } /** * Object that contains options to use while creation of nw.Menu. example: new nw.Menu(MenuOption) */ interface MenuOption { /** * {string} (Optional) two types are accepted by this method: "menubar" or "contextmenu". The value is set to "contextmenu" by default. */ type: string; } /** * Options to modify default `edit` and `window` MenuItems in Mac. */ interface CreateMacBuiltinOption { /** * {Boolean} (Optional) do not populate the Edit menu */ hideEdit?: boolean; /** * {Boolean} (Optional) do not populate the Window menu */ hideWindow?: boolean; } /** * Options for MenuItem. */ interface MenuItemOption { /** * {string} (Optional) Label for normal item or checkbox */ label?: string; /** * {string} (Optional) Icon for normal item or checkbox */ icon?: string; /** * {string} (Optional) Tooltip for normal item or checkbox */ tooltip?: string; /** * {string} (Optional) The type of the item. Three types are accepted: normal, checkbox, separator */ type?: string | "normal" | "checkbox" | "separator"; /** * {Function} (Optional) The callback function when item is triggered by mouse click or keyboard shortcut */ click?: Function; /** * {boolean} (Optional) Whether the item is enabled or disabled. It"s set to true by default. */ enabled?: boolean; /** * {boolean} (Optional) Whether the checkbox is checked or not. It"s set to false by default. */ checked?: boolean; /** * {nw.Menu} (Optional) A submenu */ submenu?: nw.Menu; /** * {string} (Optional) The key of the shortcut */ key?: string; /** * {string} (Optional) The modifiers of the shortcut */ modifiers?: string; } /** * nw.Screen screen object */ interface screen { /** * Unique id for a screen */ id: number, /** * Physical screen resolution, can be negative, not necessarily start from 0,depending on screen arrangement */ bounds: { x: number, y: number, width: number, height: number }, /** * Useable area within the screen bound */ work_area: { x: number, y: number, width: number, height: number }, scaleFactor: number, isBuiltIn: boolean, rotation: number, touchSupport: number } /** * This API behaves similar functions as Screen.chooseDesktopMedia. But it doesn"t have GUI. */ interface DesktopCaptureMonitor extends EventEmitter { /** * Boolean of whether the DesktopCaptureMonitor is started. */ started: boolean; /** * The DesktopCaptureMonitor will start monitoring the system and trigger the the events. * * @param should_include_screens {boolean} Whether should include screens * @param should_include_windows {boolean} Whether should include windows */ start( should_include_screens: boolean, should_include_windows: boolean ): void; /** * The DesktopCaptureMonitor will stop monitoring the system. */ stop(): void; /** * Register and return a valid stream id passed into chromeMediaSourceId in getUserMedia constraints. * * @param id {string} valid stream id. */ registerStream( id: string ): void; on( event: string, listener: Function ): this; /** * Emit when a new source was added. * * @param event {string} Event name * @param listener {Function(id?,name?,order?,type?,primary?)} The callback that handles the `added` event. * - (optional) id {string} Is the media id. * - (optional) name {string} Is the title of the window or screen. * - (optional) order {number} Is the z-order of the windows, if screens are selected they will appear first. * - (optional) type {string} Type of the stream: "screen", "window", "other" or "unknown". * - (optional) primary {boolean} This will be true if the source is the primary monitor. (Windows OS only) */ on( event: 'added', listener: ( id?: string, name?: string, order?: number, type?: string, primary?: boolean ) => any ): this; /** * Emit when a source was removed. * * @param event {string} Event name * @param listener {Function(order?)} The callback that handles the `remove` event. * - (optional) order {number} Is the order of the media source that is no longer capturable. */ on( event: 'removed', listener: ( order?: number ) => any ): this; /** * Emit when the Z-order of a source changed (this may change for windows as others are focused). * * @param event {string} Event name * @param listener {Function(id?,new_order?,old_order?)} The callback that handles the `orderchanged` event. * - (optional) id {string} Is the media id of the screen or window that has changed z-order. * - (optional) new_order {number} Is the new z-order. * - (optional) old_order {number} Is the old z-order. */ on( event: 'orderchanged', listener: ( id?: string, new_order?: number, old_order?: number ) => any ): this; /** * Emit when the name of the source has changed. This can happen when a window changes title. * * @param event {string} Event name * @param listener {Function(id?,new_order?,old_order?)} The callback that handles the `namechanged ` event. * - (optional) id {string} Is the media id of the screen or window that has a name changed. * - (optional) name {string} Is the new name of the screen or window. */ on( event: 'namechanged', listener: ( id?: string, name?: string ) => any ): this; /** * Emit when the thumbnail of a source changed. * * @param event {string} Event name * @param listener {Function(id?,new_order?,old_order?)} The callback that handles the `thumbnailchanged ` event. * - (optional) id {string} Is the media id of the screen or window that has an updated thumbnail. * - (optional) name {string} Is the base64 encoded png of the thumbnail. */ on( event: 'thumbnailchanged', listener: ( id?: string, thumbnail?: string ) => any ): this; } /** * Shortcut option is an object contains initial settings for the Shortcut. */ interface ShortcutOption { /** * {Function} (Optional) A callback when the hotkey is triggered. */ active: Function; /** * {Function} (Optional) A callback when failed to register the hotkey. * * @param msg {string} Failure message */ failed: ( msg?: string ) => any; /** * {string} Key combinations of the shortcut, such as "ctrl+shift+a". */ key: string; } /** * Option for tray that contains initial settings for the Tray. */ interface TrayOption { /** * {string} title */ title?: string; /** * {string} tooltip */ tooltip?: string; /** * {string} icon */ icon?: string; /** * {string} alternate */ alticon?: string; /** * {boolean} whether icons are templates */ iconsAreTemplates?: boolean; /** * {Menu} popup menu */ menu?: nw.Menu; } /** * Options for nw.Window.get().print(). */ interface PrintOption { /** * The device name of the printer */ printer: string; /** * The path of the output PDF when printing to PDF */ pdf_path: string; /** * Whether to enable header and footer */ headerFooterEnabled: boolean; /** * Whether to use landscape or portrait */ landscape: boolean; /** * The paper size spec * example: 'mediaSize':{'name': 'CUSTOM', 'width_microns': 279400, 'height_microns': 215900, 'custom_display_name':'Letter', 'is_default': true} */ mediaSize: any; /** * Whether to print CSS backgrounds */ shouldPrintBackgrounds: boolean; } /** * Config for nw.Window.get().capturePage(). */ interface CapturePageConfig { /** * (Optional) The image format used to generate the image. It supports two formats: "png" and "jpeg". If ignored, it’s "jpeg" by default. */ format?: string /** * (Optional) It supports three types: "raw", "buffer" and "datauri". If ignored, it’s "datauri" by default. */ datatype?: string } /** * This includes multiple functions to manipulate the cookies. */ interface Cookies { /** * Retrieves information about a single cookie. * * @param details {Objet} Details to identify the cookie being retrieved. * @param callback {function(cookie?)} The callback when cookie retrieved. * - (Optional) cookie {Cookie} Contains details about the cookie. This parameter is null if no such cookie was found. */ get( details: CookiesGetDetails, callback: ( cookie?: Cookie ) => void ): void; /** * Retrieves all cookies from a single cookie store that match the given information. * * @param details {Objet} Information to filter the cookies being retrieved. * @param callback {function(cookies?)} The callback when cookies retrieved. * - (Optional) cookies {Cookie[]} All the existing, unexpired cookies that match the given cookie info. */ getAll( details: CookiesGetAllDetails, callback: ( cookies?: Cookie[] ) => void ): void; /** * Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist. * * @param details {Objet} Details about the cookie being set. * @param callback {function(cookie?)} The callback when cookie has been set. * - (Optional) cookie {Cookie} Contains details about the cookie that's been set. If setting failed for any reason, this will be "null", and "chrome.runtime.lastError" will be set. */ set( details: CookiesSetDetails, callback: ( cookie?: Cookie ) => void ): void; /** * Deletes a cookie by name. * * @param details {Objet} Information to identify the cookie to remove. * @param callback {function(cookie?)} The callback when cookie has been set. * - (Optional) details {Objet} Contains details about the cookie that's been removed. If removal failed for any reason, this will be "null", and "chrome.runtime.lastError" will be set. */ remove( details: CookiesRemoveDetails, callback: ( details?: CookiesRemovedDetails ) => void ): void; /** * Fired when a cookie is set or removed. */ onChanged: { /** * Add a new listener for onChanged event. * * @param callback {function(changeInfo?)} The callback when cookie has been changed. * - (Optional) changeInfo {Objet} Contains details about the cookie that's been changed. */ addListener( callback: ( changeInfo: CookiesOnChangedCallbackChangeInfo ) => void ): void; } } /** * Represents information about an HTTP cookie. */ interface Cookie { /** * The name of the cookie. */ name: string; /** * The value of the cookie. */ value: string; /** * The domain of the cookie (e.g. "www.google.com", "example.com"). */ domain: string; /** * True if the cookie is a host-only cookie (i.e. a request's host must exactly match the domain of the cookie). */ hostOnly: boolean; /** * The path of the cookie. */ path: string; /** * True if the cookie is marked as Secure (i.e. its scope is limited to secure channels, typically HTTPS). */ secure: boolean; /** * True if the cookie is marked as HttpOnly (i.e. the cookie is inaccessible to client-side scripts). */ httpOnly: boolean; /** * The cookie's same-site status (i.e. whether the cookie is sent with cross-site requests). */ sameSite: string | "no_restriction" | "lax" | "strict"; /** * True if the cookie is a session cookie, as opposed to a persistent cookie with an expiration date. */ session: boolean; /** * (Optional) The expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies. */ expirationDate?: number; /** * The ID of the cookie store containing this cookie. */ storeId: string; } /** * Coockies.get() details argument object */ interface CookiesGetDetails { /** * The URL with which the cookie to retrieve is associated. */ url: string; /** * The name of the cookie to retrieve. */ name: string; /** * The ID of the cookie store in which to look for the cookie. */ storeId: string; } /** * Coockies.getAll() details argument object */ interface CookiesGetAllDetails { /** * Restricts the retrieved cookies to those that would match the given URL. */ url?: string; /** * Filters the cookies by name. */ name?: string; /** * Restricts the retrieved cookies to those whose domains match or are subdomains of this one. */ domain?: string; /** * Restricts the retrieved cookies to those whose path exactly matches this string. */ path?: string; /** * Filters the cookies by their Secure property. */ secure?: boolean; /** * Filters out session vs. persistent cookies. */ session: boolean; /** * The cookie store to retrieve cookies from. If omitted, the current execution context's cookie store will be used. */ storeId?: string; } /** * Coockies.set() details argument object */ interface CookiesSetDetails { /** * The request-URI to associate with the setting of the cookie. */ url: string; /** * The name of the cookie. Empty by default if omitted. */ name?: string; /** * The value of the cookie. Empty by default if omitted. */ value?: string; /** * The domain of the cookie. If omitted, the cookie becomes a host-only cookie. */ domain?: string; /** * The path of the cookie. Defaults to the path portion of the url parameter. */ path?: string; /** * Whether the cookie should be marked as Secure. Defaults to false. */ secure?: boolean; /** * Whether the cookie should be marked as HttpOnly. Defaults to false. */ httpOnly?: boolean; /** * The cookie's same-site status: defaults to 'no_restriction'. */ sameSite?: string | "no_restriction" | "lax" | "strict"; /** * The expiration date of the cookie as the number of seconds since the UNIX epoch. If omitted, the cookie becomes a session cookie. */ expirationDate?: number; /** * The ID of the cookie store in which to set the cookie. By default, the cookie is set in the current execution context's cookie store. */ storeId?: string; } /** * Coockies.remove() details argument object */ interface CookiesRemoveDetails { /** * The URL associated with the cookie. */ url: string; /** * The name of the cookie to remove. */ name: string; /** * The ID of the cookie store to look in for the cookie. */ storeId: string; } /** * Coockies.remove() callback details argument object */ interface CookiesRemovedDetails { /** * The URL associated with the cookie that's been removed. */ url: string; /** * The name of the cookie that's been removed. */ name: string; /** * The ID of the cookie store from which the cookie was removed. */ storeId: string; } /** * Coockies.onChanged.addListener() callback details argument object */ interface CookiesOnChangedCallbackChangeInfo { /** * True if a cookie was removed. */ removed: boolean; /** * Information about the cookie that was set or removed. */ cookie: Cookie; /** * The underlying reason behind the cookie's change. */ cause: string | "evicted" | "expired" | "explicit" | "expired_overwrite" | "overwrite" } /** * nw.Window.get().on('new-win-policy') callback policy argument object */ interface WinPolicy { /** * Ignore the request, navigation won’t happen. */ ignore(): void; /** * Force the link to be opened in the same frame */ forceCurrent(): void; /** * Force the link to be a downloadable, or open by external program */ forceDownload(): void; /** * Force the link to be opened in a new window */ forceNewWindow(): void; /** * Force the link to be opened in a new popup window */ forceNewPopup(): void; /** * Control the options for the new popup window. * *@param m {Object} The object is in the same format as the Window subfields in manifest format. */ setNewWindowManifest( m: WindowOption ): void; } /** * nw.Window Option that is in the same format as the Window subfields in manifest format. */ interface WindowOption { /** * The id used to identify the window. */ id?: string; /** * The default title of window created by NW.js */ title?: string; /** * The initial width of the main window. */ width?: number; /** * The initial height of the main window. */ height?: number; /** * Path to window’s icon */ icon?: string; /** * Controls where window will be put, be `null` or `center` or `mouse` */ position?: string; /** * Minimum width of window */ min_width?: number; /** * Minimum height of window */ min_height?: number; /** * Maximum width of window */ max_width?: number; /** * Maximum height of window */ max_height?: number; /** * Show as desktop background window under X11 environment */ as_desktop?: boolean; /** * Whether window is resizable */ resizable?: boolean; /** * Whether the window should always stay on top of other windows. */ always_on_top?: boolean; /** * Whether the window should be visible on all workspaces simultaneously (on platforms that support multiple workspaces, currently Mac OS X and Linux). */ visible_on_all_workspaces?: boolean; /** * Whether window is fullscreen */ fullscreen?: boolean; /** * Whether the window is shown in taskbar or dock. The default is true. */ show_in_taskbar?: boolean; /** * Specify it to false to make the window frameless */ frame?: boolean; /** * Specify it to false if you want your app to be hidden on startup */ show?: boolean; /** * Whether to use Kiosk mode. */ kiosk?: boolean; /** * Whether to turn on transparent window mode. */ transparent?: boolean; } interface WindowOpenOption extends WindowOption { /** * (Optional) Whether to open a new window in a separate render process. */ new_instance?: boolean; /** * (Optional) The script to be injected before document loaded. */ inject_js_start?: string; /** * (Optional) The script to be injected before document unloaded. */ inject_js_end?: string; /** * (Optional) The id used to identify the window. */ id?: string; } /** * nw.Window.get().on('navigation') callback policy argument object */ interface WinNavigationPolicy { /** * Ignore the request, navigation won’t happen. */ ignore(): void; } interface win extends EventEmitter { /** * Get the corresponding DOM window object of the native window. */ window: Object; /** * Get or set left offset from window to screen. */ x: number; /** * Get or set top offset from window to screen. */ y: number; /** * Get or set window's width. */ width: number; /** * Get or set window's height. */ height: number; /** * Get or set window's title. */ title: string; /** * Get or set window's menubar. */ menu: nw.Menu; /** * Get whether we're in fullscreen mode. */ isFullscreen: boolean; /** * Get whether transparency is turned on */ isTransparent: boolean; /** * Get whether we're in kiosk mode. */ isKioskMode: boolean; /** * Get or set the page zoom. */ zoomLevel: number; /** * This includes multiple functions to manipulate the cookies. */ cookies: Cookies; /** * Moves a window's left and top edge to the specified coordinates. * * @param x {Integer} Offset to the left of the screen * @param y {Integer} Offset to the top of the screen */ moveTo( x: number, y: number ): void; /** * Moves a window a specified number of pixels relative to its current coordinates. * * @param x {Integer} Horizontal offset * @param y {Integer} Vertical offset */ moveBy( x: number, y: number ): void; /** * Resizes a window to the specified width and height. * * @param width {Integer} The width of the window * @param height {Integer} The height of the window */ resizeTo( width: number, height: number ): void; /** * Resizes a window by the specified amount. * * @param width {Integer} The offset width of the window * @param height {Integer} The offset height of the window */ resizeBy( width: number, height: number ): void; /** * Focus on the window. */ focus(): void; /** * Move focus away. */ blur(): void; /** * Show the window if it's not shown. * * @param is_show {boolean} (Optional) Specify whether the window should be shown or hidden. It's set to true by default. */ show( is_show?: boolean ): void; /** * Hide the window. */ hide(): void; /** * Close current window. * * @param force {boolean} (Optional) Specify whether to close the window forcely and bypass close event. */ close( force?: boolean ): void; /** * Reloads the current window. */ reload(): void; /** * Reloads the current page by starting a new renderer process from scratch. */ reloadDev(): void; /** * Like reload(), but don't use caches (aka 'shift-reload'). */ reloadIgnoringCache(): void; /** * Maximize the window on GTK and Windows, and zoom the window on Mac OS X. */ maximize(): void; /** * Minimize the window to task bar on Windows, iconify the window on GTK, and miniaturize the window on Mac OS X. */ minimize(): void; /** * Restore window to previous state after the window is minimized. */ restore(): void; /** * Make the window fullscreen. */ enterFullscreen(): void; /** * Leave the fullscreen mode. */ leaveFullscreen(): void; /** * Toggle the fullscreen mode. */ toggleFullscreen(): void; /** * Enter the Kiosk mode. */ enterKioskMode(): void; /** * Leave the Kiosk mode. */ leaveKioskMode(): void; /** * Toggle the kiosk mode. */ toggleKioskMode(): void; /** * Open the devtools to inspect the window. * * @param iframe {Integer} (Optional) the id or the element of the