declarations
Version:
[](https://www.npmjs.com/package/declarations)
1,440 lines (1,412 loc) • 180 kB
TypeScript
// Type definitions for Electron v1.3.5
// Project: http://electron.atom.io/
// Definitions by: jedmao <https://github.com/jedmao/>, rhysd <https://rhysd.github.io>, Milan Burda <https://github.com/miniak/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare namespace Electron {
class EventEmitter extends NodeJS.EventEmitter {
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;
}
interface Event {
preventDefault: Function;
sender: EventEmitter;
}
type Point = {
x: number;
y: number;
}
type Size = {
width: number;
height: number;
}
type Rectangle = {
x: number;
y: number;
width: number;
height: number;
}
// https://github.com/electron/electron/blob/master/docs/api/app.md
/**
* The app module is responsible for controlling the application's lifecycle.
*/
interface App extends NodeJS.EventEmitter {
/**
* Emitted when the application has finished basic startup.
* On Windows and Linux, the will-finish-launching event
* is the same as the ready event; on macOS, this event represents
* the applicationWillFinishLaunching notification of NSApplication.
* You would usually set up listeners for the open-file and open-url events here,
* and start the crash reporter and auto updater.
*
* In most cases, you should just do everything in the ready event handler.
*/
on(event: 'will-finish-launching', listener: Function): this;
/**
* Emitted when Electron has finished initialization.
*/
on(event: 'ready', listener: Function): this;
/**
* Emitted when all windows have been closed.
*
* If you do not subscribe to this event and all windows are closed,
* the default behavior is to quit the app; however, if you subscribe,
* you control whether the app quits or not.
* If the user pressed Cmd + Q, or the developer called app.quit(),
* Electron will first try to close all the windows and then emit the will-quit event,
* and in this case the window-all-closed event would not be emitted.
*/
on(event: 'window-all-closed', listener: Function): this;
/**
* Emitted before the application starts closing its windows.
* Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
*/
on(event: 'before-quit', listener: (event: Event) => void): this;
/**
* Emitted when all windows have been closed and the application will quit.
* Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
*/
on(event: 'will-quit', listener: (event: Event) => void): this;
/**
* Emitted when the application is quitting.
*/
on(event: 'quit', listener: (event: Event, exitCode: number) => void): this;
/**
* Emitted when the user wants to open a file with the application.
* The open-file event is usually emitted when the application is already open
* and the OS wants to reuse the application to open the file.
* open-file is also emitted when a file is dropped onto the dock and the application
* is not yet running. Make sure to listen for the open-file event very early
* in your application startup to handle this case (even before the ready event is emitted).
*
* You should call event.preventDefault() if you want to handle this event.
*
* Note: This is only implemented on macOS.
*/
on(event: 'open-file', listener: (event: Event, url: string) => void): this;
/**
* Emitted when the user wants to open a URL with the application.
* The URL scheme must be registered to be opened by your application.
*
* You should call event.preventDefault() if you want to handle this event.
*
* Note: This is only implemented on macOS.
*/
on(event: 'open-url', listener: (event: Event, url: string) => void): this;
/**
* Emitted when the application is activated, which usually happens when clicks on the applications’s dock icon.
* Note: This is only implemented on macOS.
*/
on(event: 'activate', listener: Function): this;
/**
* Emitted during Handoff when an activity from a different device wants to be resumed.
* You should call event.preventDefault() if you want to handle this event.
*/
on(event: 'continue-activity', listener: (event: Event, type: string, userInfo: Object) => void): this;
/**
* Emitted when a browserWindow gets blurred.
*/
on(event: 'browser-window-blur', listener: (event: Event, browserWindow: BrowserWindow) => void): this;
/**
* Emitted when a browserWindow gets focused.
*/
on(event: 'browser-window-focus', listener: (event: Event, browserWindow: BrowserWindow) => void): this;
/**
* Emitted when a new browserWindow is created.
*/
on(event: 'browser-window-created', listener: (event: Event, browserWindow: BrowserWindow) => void): this;
/**
* Emitted when a new webContents is created.
*/
on(event: 'web-contents-created', listener: (event: Event, webContents: WebContents) => void): this;
/**
* Emitted when failed to verify the certificate for url, to trust the certificate
* you should prevent the default behavior with event.preventDefault() and call callback(true).
*/
on(event: 'certificate-error', listener: (event: Event,
webContents: WebContents,
url: string,
error: string,
certificate: Certificate,
callback: (trust: boolean) => void
) => void): this;
/**
* Emitted when a client certificate is requested.
*
* The url corresponds to the navigation entry requesting the client certificate
* and callback needs to be called with an entry filtered from the list.
* Using event.preventDefault() prevents the application from using the first certificate from the store.
*/
on(event: 'select-client-certificate', listener: (event: Event,
webContents: WebContents,
url: string,
certificateList: Certificate[],
callback: (certificate: Certificate) => void
) => void): this;
/**
* Emitted when webContents wants to do basic auth.
*
* The default behavior is to cancel all authentications, to override this
* you should prevent the default behavior with event.preventDefault()
* and call callback(username, password) with the credentials.
*/
on(event: 'login', listener: (event: Event,
webContents: WebContents,
request: LoginRequest,
authInfo: LoginAuthInfo,
callback: (username: string, password: string) => void
) => void): this;
/**
* Emitted when the gpu process crashes.
*/
on(event: 'gpu-process-crashed', listener: Function): this;
/**
* Emitted when Chrome's accessibility support changes.
*
* Note: This API is only available on macOS and Windows.
*/
on(event: 'accessibility-support-changed', listener: (event: Event, accessibilitySupportEnabled: boolean) => void): this;
on(event: string, listener: Function): this;
/**
* Try to close all windows. The before-quit event will first be emitted.
* If all windows are successfully closed, the will-quit event will be emitted
* and by default the application would be terminated.
*
* This method guarantees all beforeunload and unload handlers are correctly
* executed. It is possible that a window cancels the quitting by returning
* false in beforeunload handler.
*/
quit(): void;
/**
* Exits immediately with exitCode.
* All windows will be closed immediately without asking user
* and the before-quit and will-quit events will not be emitted.
*/
exit(exitCode?: number): void;
/**
* Relaunches the app when current instance exits.
*
* By default the new instance will use the same working directory
* and command line arguments with current instance.
* When args is specified, the args will be passed as command line arguments instead.
* When execPath is specified, the execPath will be executed for relaunch instead of current app.
*
* Note that this method does not quit the app when executed, you have to call app.quit
* or app.exit after calling app.relaunch to make the app restart.
*
* When app.relaunch is called for multiple times, multiple instances
* will be started after current instance exited.
*/
relaunch(options?: {
args?: string[],
execPath?: string
}): void;
/**
* On Linux, focuses on the first visible window.
* On macOS, makes the application the active app.
* On Windows, focuses on the application’s first window.
*/
focus(): void;
/**
* Hides all application windows without minimizing them.
* Note: This is only implemented on macOS.
*/
hide(): void;
/**
* Shows application windows after they were hidden. Does not automatically focus them.
* Note: This is only implemented on macOS.
*/
show(): void;
/**
* Returns the current application directory.
*/
getAppPath(): string;
/**
* @returns The path to a special directory or file associated with name.
* On failure an Error would throw.
*/
getPath(name: AppPathName): string;
/**
* Overrides the path to a special directory or file associated with name.
* If the path specifies a directory that does not exist, the directory will
* be created by this method. On failure an Error would throw.
*
* You can only override paths of names defined in app.getPath.
*
* By default web pages' cookies and caches will be stored under userData
* directory, if you want to change this location, you have to override the
* userData path before the ready event of app module gets emitted.
*/
setPath(name: AppPathName, path: string): void;
/**
* @returns The version of loaded application, if no version is found in
* application's package.json, the version of current bundle or executable.
*/
getVersion(): string;
/**
* @returns The current application's name, the name in package.json would be used.
* Usually the name field of package.json is a short lowercased name, according to
* the spec of npm modules. So usually you should also specify a productName field,
* which is your application's full capitalized name, and it will be preferred over
* name by Electron.
*/
getName(): string;
/**
* Overrides the current application's name.
*/
setName(name: string): void;
/**
* @returns The current application locale.
*/
getLocale(): string;
/**
* Adds path to recent documents list.
*
* This list is managed by the system, on Windows you can visit the list from
* task bar, and on macOS you can visit it from dock menu.
*
* Note: This is only implemented on macOS and Windows.
*/
addRecentDocument(path: string): void;
/**
* Clears the recent documents list.
*
* Note: This is only implemented on macOS and Windows.
*/
clearRecentDocuments(): void;
/**
* Sets the current executable as the default handler for a protocol (aka URI scheme).
* Once registered, all links with your-protocol:// will be opened with the current executable.
* The whole link, including protocol, will be passed to your application as a parameter.
*
* On Windows you can provide optional parameters path, the path to your executable,
* and args, an array of arguments to be passed to your executable when it launches.
*
* @param protocol The name of your protocol, without ://.
* @param path Defaults to process.execPath.
* @param args Defaults to an empty array.
*
* Note: This is only implemented on macOS and Windows.
* On macOS, you can only register protocols that have been added to your app's info.plist.
*/
setAsDefaultProtocolClient(protocol: string, path?: string, args?: string[]): boolean;
/**
* Removes the current executable as the default handler for a protocol (aka URI scheme).
*
* @param protocol The name of your protocol, without ://.
* @param path Defaults to process.execPath.
* @param args Defaults to an empty array.
*
* Note: This is only implemented on macOS and Windows.
*/
removeAsDefaultProtocolClient(protocol: string, path?: string, args?: string[]): boolean;
/**
* @param protocol The name of your protocol, without ://.
* @param path Defaults to process.execPath.
* @param args Defaults to an empty array.
*
* @returns Whether the current executable is the default handler for a protocol (aka URI scheme).
*
* Note: This is only implemented on macOS and Windows.
*/
isDefaultProtocolClient(protocol: string, path?: string, args?: string[]): boolean;
/**
* Adds tasks to the Tasks category of JumpList on Windows.
*
* Note: This API is only available on Windows.
*/
setUserTasks(tasks: Task[]): boolean;
/**
* Note: This API is only available on Windows.
*/
getJumpListSettings(): JumpListSettings;
/**
* Sets or removes a custom Jump List for the application.
*
* If categories is null the previously set custom Jump List (if any) will be replaced
* by the standard Jump List for the app (managed by Windows).
*
* Note: This API is only available on Windows.
*/
setJumpList(categories: JumpListCategory[]): SetJumpListResult;
/**
* This method makes your application a Single Instance Application instead of allowing
* multiple instances of your app to run, this will ensure that only a single instance
* of your app is running, and other instances signal this instance and exit.
*/
makeSingleInstance(callback: (args: string[], workingDirectory: string) => void): boolean;
/**
* Releases all locks that were created by makeSingleInstance. This will allow
* multiple instances of the application to once again run side by side.
*/
releaseSingleInstance(): void;
/**
* Creates an NSUserActivity and sets it as the current activity.
* The activity is eligible for Handoff to another device afterward.
*
* @param type Uniquely identifies the activity. Maps to NSUserActivity.activityType.
* @param userInfo App-specific state to store for use by another device.
* @param webpageURL The webpage to load in a browser if no suitable app is
* installed on the resuming device. The scheme must be http or https.
*
* Note: This API is only available on macOS.
*/
setUserActivity(type: string, userInfo: Object, webpageURL?: string): void;
/**
* @returns The type of the currently running activity.
*
* Note: This API is only available on macOS.
*/
getCurrentActivityType(): string;
/**
* Changes the Application User Model ID to id.
*
* Note: This is only implemented on Windows.
*/
setAppUserModelId(id: string): void;
/**
* Imports the certificate in pkcs12 format into the platform certificate store.
* @param callback Called with the result of import operation, a value of 0 indicates success
* while any other value indicates failure according to chromium net_error_list.
*
* Note: This API is only available on Linux.
*/
importCertificate(options: ImportCertificateOptions, callback: (result: number) => void): void;
/**
* Disables hardware acceleration for current app.
* This method can only be called before app is ready.
*/
disableHardwareAcceleration(): void;
/**
* @returns whether current desktop environment is Unity launcher. (Linux)
*
* Note: This API is only available on Linux.
*/
isUnityRunning(): boolean;
/**
* Returns a Boolean, true if Chrome's accessibility support is enabled, false otherwise.
* This API will return true if the use of assistive technologies, such as screen readers,
* has been detected.
* See https://www.chromium.org/developers/design-documents/accessibility for more details.
*
* Note: This API is only available on macOS and Windows.
*/
isAccessibilitySupportEnabled(): boolean;
/**
* @returns an Object with the login item settings of the app.
*
* Note: This API is only available on macOS and Windows.
*/
getLoginItemSettings(): LoginItemSettings;
/**
* Set the app's login item settings.
*
* Note: This API is only available on macOS and Windows.
*/
setLoginItemSettings(settings: LoginItemSettings): void;
commandLine: CommandLine;
/**
* Note: This API is only available on macOS.
*/
dock: Dock;
}
type AppPathName = 'home'|'appData'|'userData'|'temp'|'exe'|'module'|'desktop'|'documents'|'downloads'|'music'|'pictures'|'videos'|'pepperFlashSystemPlugin';
interface ImportCertificateOptions {
/**
* Path for the pkcs12 file.
*/
certificate: string;
/**
* Passphrase for the certificate.
*/
password: string;
}
interface CommandLine {
/**
* Append a switch [with optional value] to Chromium's command line.
*
* Note: This will not affect process.argv, and is mainly used by developers
* to control some low-level Chromium behaviors.
*/
appendSwitch(_switch: string, value?: string): void;
/**
* Append an argument to Chromium's command line. The argument will quoted properly.
*
* Note: This will not affect process.argv.
*/
appendArgument(value: string): void;
}
interface Dock {
/**
* When critical is passed, the dock icon will bounce until either the
* application becomes active or the request is canceled.
*
* When informational is passed, the dock icon will bounce for one second.
* However, the request remains active until either the application becomes
* active or the request is canceled.
*
* @param type The default is informational.
* @returns An ID representing the request.
*/
bounce(type?: 'critical' | 'informational'): number;
/**
* Cancel the bounce of id.
*
* Note: This API is only available on macOS.
*/
cancelBounce(id: number): void;
/**
* Bounces the Downloads stack if the filePath is inside the Downloads folder.
*
* Note: This API is only available on macOS.
*/
downloadFinished(filePath: string): void;
/**
* Sets the string to be displayed in the dock’s badging area.
*
* Note: This API is only available on macOS.
*/
setBadge(text: string): void;
/**
* Returns the badge string of the dock.
*
* Note: This API is only available on macOS.
*/
getBadge(): string;
/**
* Sets the counter badge for current app. Setting the count to 0 will hide the badge.
*
* @returns True when the call succeeded, otherwise returns false.
*
* Note: This API is only available on macOS and Linux.
*/
setBadgeCount(count: number): boolean;
/**
* @returns The current value displayed in the counter badge.
*
* Note: This API is only available on macOS and Linux.
*/
getBadgeCount(): number;
/**
* Hides the dock icon.
*
* Note: This API is only available on macOS.
*/
hide(): void;
/**
* Shows the dock icon.
*
* Note: This API is only available on macOS.
*/
show(): void;
/**
* @returns Whether the dock icon is visible.
* The app.dock.show() call is asynchronous so this method might not return true immediately after that call.
*
* Note: This API is only available on macOS.
*/
isVisible(): boolean;
/**
* Sets the application dock menu.
*
* Note: This API is only available on macOS.
*/
setMenu(menu: Menu): void;
/**
* Sets the image associated with this dock icon.
*
* Note: This API is only available on macOS.
*/
setIcon(icon: NativeImage | string): void;
}
interface Task {
/**
* Path of the program to execute, usually you should specify process.execPath
* which opens current program.
*/
program: string;
/**
* The arguments of command line when program is executed.
*/
arguments: string;
/**
* The string to be displayed in a JumpList.
*/
title: string;
/**
* Description of this task.
*/
description?: string;
/**
* The absolute path to an icon to be displayed in a JumpList, it can be
* arbitrary resource file that contains an icon, usually you can specify
* process.execPath to show the icon of the program.
*/
iconPath: string;
/**
* The icon index in the icon file. If an icon file consists of two or more
* icons, set this value to identify the icon. If an icon file consists of
* one icon, this value is 0.
*/
iconIndex?: number;
}
/**
* ok - Nothing went wrong.
* error - One or more errors occured, enable runtime logging to figure out the likely cause.
* invalidSeparatorError - An attempt was made to add a separator to a custom category in the Jump List.
* Separators are only allowed in the standard Tasks category.
* fileTypeRegistrationError - An attempt was made to add a file link to the Jump List
* for a file type the app isn't registered to handle.
* customCategoryAccessDeniedError - Custom categories can't be added to the Jump List
* due to user privacy or group policy settings.
*/
type SetJumpListResult = 'ok' | 'error' | 'invalidSeparatorError' | 'fileTypeRegistrationError' | 'customCategoryAccessDeniedError';
interface JumpListSettings {
/**
* The minimum number of items that will be shown in the Jump List.
*/
minItems: number;
/**
* Items that the user has explicitly removed from custom categories in the Jump List.
*/
removedItems: JumpListItem[];
}
interface JumpListCategory {
/**
* tasks - Items in this category will be placed into the standard Tasks category.
* frequent - Displays a list of files frequently opened by the app, the name of the category and its items are set by Windows.
* recent - Displays a list of files recently opened by the app, the name of the category and its items are set by Windows.
* custom - Displays tasks or file links, name must be set by the app.
*/
type?: 'tasks' | 'frequent' | 'recent' | 'custom';
/**
* Must be set if type is custom, otherwise it should be omitted.
*/
name?: string;
/**
* Array of JumpListItem objects if type is tasks or custom, otherwise it should be omitted.
*/
items?: JumpListItem[];
}
interface JumpListItem {
/**
* task - A task will launch an app with specific arguments.
* separator - Can be used to separate items in the standard Tasks category.
* file - A file link will open a file using the app that created the Jump List.
*/
type: 'task' | 'separator' | 'file';
/**
* Path of the file to open, should only be set if type is file.
*/
path?: string;
/**
* Path of the program to execute, usually you should specify process.execPath which opens the current program.
* Should only be set if type is task.
*/
program?: string;
/**
* The command line arguments when program is executed. Should only be set if type is task.
*/
args?: string;
/**
* The text to be displayed for the item in the Jump List. Should only be set if type is task.
*/
title?: string;
/**
* Description of the task (displayed in a tooltip). Should only be set if type is task.
*/
description?: string;
/**
* The absolute path to an icon to be displayed in a Jump List, which can be an arbitrary
* resource file that contains an icon (e.g. .ico, .exe, .dll).
* You can usually specify process.execPath to show the program icon.
*/
iconPath?: string;
/**
* The index of the icon in the resource file. If a resource file contains multiple icons
* this value can be used to specify the zero-based index of the icon that should be displayed
* for this task. If a resource file contains only one icon, this property should be set to zero.
*/
iconIndex?: number;
}
interface LoginItemSettings {
/**
* True if the app is set to open at login.
*/
openAtLogin: boolean;
/**
* True if the app is set to open as hidden at login. This setting is only supported on macOS.
*/
openAsHidden: boolean;
/**
* True if the app was opened at login automatically. This setting is only supported on macOS.
*/
wasOpenedAtLogin?: boolean;
/**
* True if the app was opened as a hidden login item. This indicates that the app should not
* open any windows at startup. This setting is only supported on macOS.
*/
wasOpenedAsHidden?: boolean;
/**
* True if the app was opened as a login item that should restore the state from the previous session.
* This indicates that the app should restore the windows that were open the last time the app was closed.
* This setting is only supported on macOS.
*/
restoreState?: boolean;
}
// https://github.com/electron/electron/blob/master/docs/api/auto-updater.md
/**
* This module provides an interface for the Squirrel auto-updater framework.
*/
interface AutoUpdater extends NodeJS.EventEmitter {
/**
* Emitted when there is an error while updating.
*/
on(event: 'error', listener: (error: Error) => void): this;
/**
* Emitted when checking if an update has started.
*/
on(event: 'checking-for-update', listener: Function): this;
/**
* Emitted when there is an available update. The update is downloaded automatically.
*/
on(event: 'update-available', listener: Function): this;
/**
* Emitted when there is no available update.
*/
on(event: 'update-not-available', listener: Function): this;
/**
* Emitted when an update has been downloaded.
* Note: On Windows only releaseName is available.
*/
on(event: 'update-downloaded', listener: (event: Event, releaseNotes: string, releaseName: string, releaseDate: Date, updateURL: string) => void): this;
on(event: string, listener: Function): this;
/**
* Set the url and initialize the auto updater.
*/
setFeedURL(url: string, requestHeaders?: Headers): void;
/**
* @returns The current update feed URL.
*/
getFeedURL(): string;
/**
* Ask the server whether there is an update, you have to call setFeedURL
* before using this API
*/
checkForUpdates(): void;
/**
* Restarts the app and installs the update after it has been downloaded.
* It should only be called after update-downloaded has been emitted.
*/
quitAndInstall(): void;
}
// https://github.com/electron/electron/blob/master/docs/api/browser-window.md
/**
* The BrowserWindow class gives you ability to create a browser window.
* 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, title: string) => 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 the web page has been rendered and window can be displayed without visual flash.
*/
on(event: 'ready-to-show', 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 macOS.
*/
on(event: 'scroll-touch-begin', listener: Function): this;
/**
* Emitted when scroll wheel event phase has ended.
* Note: This is only implemented on macOS.
*/
on(event: 'scroll-touch-end', listener: Function): this;
/**
* Emitted on 3-finger swipe.
* Note: This is only implemented on macOS.
*/
on(event: 'swipe', listener: (event: Event, direction: SwipeDirection) => void): this;
on(event: string, listener: Function): this;
/**
* Creates a new BrowserWindow with native properties as set by the options.
*/
constructor(options?: BrowserWindowOptions);
/**
* @returns All opened browser windows.
*/
static getAllWindows(): BrowserWindow[];
/**
* @returns The window that is focused in this application.
*/
static getFocusedWindow(): BrowserWindow;
/**
* Find a window according to the webContents it owns.
*/
static fromWebContents(webContents: WebContents): BrowserWindow;
/**
* Find a window according to its ID.
*/
static fromId(id: number): BrowserWindow;
/**
* Adds devtools extension located at path. The extension will be remembered
* so you only need to call this API once, this API is not for programming use.
* @returns The extension's name.
*
* Note: This API cannot be called before the ready event of the app module is emitted.
*/
static addDevToolsExtension(path: string): string;
/**
* Remove a devtools extension.
* @param name The name of the devtools extension to remove.
*
* Note: This API cannot be called before the ready event of the app module is emitted.
*/
static removeDevToolsExtension(name: string): void;
/**
* @returns devtools extensions.
*
* Note: This API cannot be called before the ready event of the app module is emitted.
*/
static getDevToolsExtensions(): DevToolsExtensions;
/**
* The WebContents object this window owns, all web page related events and
* operations would be done via it.
* Note: Users should never store this object because it may become null when
* the renderer process (web page) has crashed.
*/
webContents: WebContents;
/**
* Get the unique ID of this window.
*/
id: number;
/**
* Force closing the window, the unload and beforeunload event won't be emitted
* for the web page, and close event would also not be emitted for this window,
* but it would guarantee the closed event to be emitted.
* You should only use this method when the renderer process (web page) has crashed.
*/
destroy(): void;
/**
* Try to close the window, this has the same effect with user manually clicking
* the close button of the window. The web page may cancel the close though,
* see the close event.
*/
close(): void;
/**
* Focus on the window.
*/
focus(): void;
/**
* Remove focus on the window.
*/
blur(): void;
/**
* @returns Whether the window is focused.
*/
isFocused(): boolean;
/**
* @returns Whether the window is destroyed.
*/
isDestroyed(): boolean;
/**
* Shows and gives focus to the window.
*/
show(): void;
/**
* Shows the window but doesn't focus on it.
*/
showInactive(): void;
/**
* Hides the window.
*/
hide(): void;
/**
* @returns Whether the window is visible to the user.
*/
isVisible(): boolean;
/**
* @returns Whether the window is a modal window.
*/
isModal(): boolean;
/**
* Maximizes the window.
*/
maximize(): void;
/**
* Unmaximizes the window.
*/
unmaximize(): void;
/**
* @returns Whether the window is maximized.
*/
isMaximized(): boolean;
/**
* Minimizes the window. On some platforms the minimized window will be
* shown in the Dock.
*/
minimize(): void;
/**
* Restores the window from minimized state to its previous state.
*/
restore(): void;
/**
* @returns Whether the window is minimized.
*/
isMinimized(): boolean;
/**
* Sets whether the window should be in fullscreen mode.
*/
setFullScreen(flag: boolean): void;
/**
* @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 macOS.
*/
setAspectRatio(aspectRatio: number, extraSize?: Size): void;
/**
* Resizes and moves the window to width, height, x, y.
*/
setBounds(options: Rectangle, animate?: boolean): void;
/**
* @returns The window's width, height, x and y values.
*/
getBounds(): Rectangle;
/**
* Resizes and moves the window's client area (e.g. the web page) to width, height, x, y.
*/
setContentBounds(options: Rectangle, animate?: boolean): void;
/**
* @returns The window's client area (e.g. the web page) width, height, x and y values.
*/
getContentBounds(): Rectangle;
/**
* Resizes the window to width and height.
*/
setSize(width: number, height: number, animate?: boolean): void;
/**
* @returns The window's width and height.
*/
getSize(): number[];
/**
* Resizes the window's client area (e.g. the web page) to width and height.
*/
setContentSize(width: number, height: number, animate?: boolean): void;
/**
* @returns The window's client area's width and height.
*/
getContentSize(): number[];
/**
* Sets the minimum size of window to width and height.
*/
setMinimumSize(width: number, height: number): void;
/**
* @returns The window's minimum width and height.
*/
getMinimumSize(): number[];
/**
* Sets the maximum size of window to width and height.
*/
setMaximumSize(width: number, height: number): void;
/**
* @returns The window's maximum width and height.
*/
getMaximumSize(): number[];
/**
* Sets whether the window can be manually resized by user.
*/
setResizable(resizable: boolean): void;
/**
* @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 macOS and Windows.
*/
setMovable(movable: boolean): void;
/**
* Note: This API is available only on macOS 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 macOS and Windows.
*/
setMinimizable(minimizable: boolean): void;
/**
* Note: This API is available only on macOS 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 macOS and Windows.
*/
setMaximizable(maximizable: boolean): void;
/**
* Note: This API is available only on macOS 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 macOS and Windows.
*/
setClosable(closable: boolean): void;
/**
* Note: This API is available only on macOS 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
* which can not be focused on.
*/
setAlwaysOnTop(flag: boolean): void;
/**
* @returns Whether the window is always on top of other windows.
*/
isAlwaysOnTop(): boolean;
/**
* Moves window to the center of the screen.
*/
center(): void;
/**
* Moves window to x and y.
*/
setPosition(x: number, y: number, animate?: boolean): void;
/**
* @returns The window's current position.
*/
getPosition(): number[];
/**
* Changes the title of native window to title.
*/
setTitle(title: string): void;
/**
* Note: The title of web page can be different from the title of the native window.
* @returns The title of the native window.
*/
getTitle(): string;
/**
* Changes the attachment point for sheets on macOS.
* Note: This API is available only on macOS.
*/
setSheetOffset(offsetY: number, offsetX?: number): void;
/**
* Starts or stops flashing the window to attract user's attention.
*/
flashFrame(flag: boolean): void;
/**
* Makes the window do not show in Taskbar.
*/
setSkipTaskbar(skip: boolean): void;
/**
* Enters or leaves the kiosk mode.
*/
setKiosk(flag: boolean): void;
/**
* @returns Whether the window is in kiosk mode.
*/
isKiosk(): boolean;
/**
* The native type of the handle is HWND on Windows, NSView* on macOS,
* 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.
* Note: This API is available only on macOS.
*/
setRepresentedFilename(filename: string): void;
/**
* Note: This API is available only on macOS.
* @returns The pathname of the file the window represents.
*/
getRepresentedFilename(): string;
/**
* Specifies whether the window’s document has been edited, and the icon in
* title bar will become grey when set to true.
* Note: This API is available only on macOS.
*/
setDocumentEdited(edited: boolean): void;
/**
* Note: This API is available only on macOS.
* @returns Whether the window's document has been edited.
*/
isDocumentEdited(): boolean;
focusOnWebView(): void;
blurWebView(): void;
/**
* Captures the snapshot of page within rect, upon completion the callback
* will be called. Omitting the rect would capture the whole visible page.
* Note: Be sure to read documents on remote buffer in remote if you are going
* to use this API in renderer process.
* @param callback Supplies the image that stores data of the snapshot.
*/
capturePage(rect: Rectangle, callback: (image: NativeImage) => void): void;
/**
* Captures the snapshot of page within rect, upon completion the callback
* will be called. Omitting the rect would capture the whole visible page.
* Note: Be sure to read documents on remote buffer in remote if you are going
* to use this API in renderer process.
* @param callback Supplies the image that stores data of the snapshot.
*/
capturePage(callback: (image: NativeImage) => void): void;
/**
* Same as webContents.loadURL(url).
*/
loadURL(url: string, options?: LoadURLOptions): void;
/**
* Same as webContents.reload.
*/
reload(): void;
/**
* Sets the menu as the window top menu.
* Note: This API is not available on macOS.
*/
setMenu(menu: Menu): void;
/**
* Sets the progress value in the progress bar.
* On Linux platform, only supports Unity desktop environment, you need to
* specify the *.desktop file name to desktopName field in package.json.
* By default, it will assume app.getName().desktop.
* @param progress Valid range is [0, 1.0]. If < 0, the progress bar is removed.
* If greater than 0, it becomes indeterminate.
*/
setProgressBar(progress: number, options?: {
/**
* Mode for the progress bar.
* Note: This is only implemented on Windows.
*/
mode: 'none' | 'normal' | 'indeterminate' | 'error' | 'paused'
}): void;
/**
* Sets a 16px overlay onto the current Taskbar icon, usually used to convey
* some sort of application status or to passively notify the user.
* Note: This API is only available on Windows 7 or above.
* @param overlay The icon to display on the bottom right corner of the Taskbar
* icon. If this parameter is null, the overlay is cleared
* @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 macOS.
*/
setHasShadow(hasShadow: boolean): void;
/**
* Note: This API is available only on macOS.
* @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.
*
* Note: This API is available only on Windows.
*/
setThumbarButtons(buttons: ThumbarButton[]): boolean;
/**
* Sets the region of the window to show as the thumbnail image displayed when hovering
* over the window in the taskbar. You can reset the thumbnail to be the entire window
* by specifying an empty region: {x: 0, y: 0, width: 0, height: 0}.
*
* Note: This API is available only on Windows.
*/
setThumbnailClip(region: Rectangle): boolean;
/**
* Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar.
* Note: This API is available only on Windows.
*/
setThumbnailToolTip(toolTip: string): boolean;
/**
* Same as webContents.showDefinitionForSelection().
* Note: This API is available only on macOS.
*/
showDefinitionForSelection(): void;
/**
* Changes window icon.
* Note: This API is not available on macOS.
*/
setIcon(icon: NativeImage): void;
/**
* Sets whether the window menu bar should hide itself automatically. Once set
* the menu bar will only show when users press the single Alt key.
* If the menu bar is already visible, calling setAutoHideMenuBar(true) won't
* hide it immediately.
*/
setAutoHideMenuBar(hide: boolean): void;
/**
* @returns Whether menu bar automatically hides itself.
*/
isMenuBarAutoHide(): boolean;
/**
* Sets whether the menu bar should be visible. If the menu bar is auto-hide,
* users can still bring up the menu bar by pressing the single Alt key.
*/
setMenuBarVisibility(visibile: boolean): void;
/**
* @returns Whether the menu bar is visible.
*/
isMenuBarVisible(): boolean;
/**
* Sets whether the window should be visible on all workspaces.
* Note: This API does nothing on Windows.
*/
setVisibleOnAllWorkspaces(visible: boolean): void;
/**
* Note: This API always returns false on Windows.
* @returns Whether the window is visible on all workspaces.
*/
isVisibleOnAllWorkspaces(): boolean;
/**
* Makes the window ignore all mouse events.
*
* All mouse events happened in this window will be passed to the window below this window,
* but if this window has focus, it will still receive keyboard events.
*/
setIgnoreMouseEvents(ignore: boolean): void;
/**
* Prevents the window contents from being captured by other apps.
*
* On macOS it sets the NSWindow's sharingType to NSWindowSharingNone.
* On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR.
*/
setContentProtection(enable: boolean): void;
/**
* Changes whether the window can be focused.
* Note: This API is available only on Windows.
*/
setFocusable(focusable: boolean): void;
/**
* Sets parent as current window's parent window,
* passing null will turn current window into a top-level window.
* Note: This API is not available on Windows.
*/
setParentWindow(parent: BrowserWindow): void;
/**
* @returns The parent window.
*/
getParentWindow(): BrowserWindow;
/**
* @returns All child windows.
*/
getChildWindows(): BrowserWindow[];
}
type SwipeDirection = 'up' | 'right' | 'down' | 'left';
type ThumbarButtonFlags = 'enabled' | 'disabled' | 'dismissonclick' | 'nobackground' | 'hidden' | 'noninteractive';
interface ThumbarButton {
icon: NativeImage | string;
click: Function;
tooltip?: string;
flags?: ThumbarButtonFlags[];
}
interface DevToolsExtensions {
[name: string]: {
name: string;
value: string;
}
}
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.
*/
w