diff --git a/github-electron/github-electron-main-tests.ts b/github-electron/github-electron-main-tests.ts index a60e326111..ef9c21e52f 100644 --- a/github-electron/github-electron-main-tests.ts +++ b/github-electron/github-electron-main-tests.ts @@ -1,21 +1,23 @@ -/// -import app = require('app'); -import AutoUpdater = require('auto-updater'); -import BrowserWindow = require('browser-window'); -import ContentTracing = require('content-tracing'); -import Dialog = require('dialog'); -import GlobalShortcut = require('global-shortcut'); -import ipc = require('ipc'); -import Menu = require('menu'); -import MenuItem = require('menu-item'); -import PowerMonitor = require('power-monitor'); -import Protocol = require('protocol'); -import Tray = require('tray'); -import Clipboard = require('clipboard'); -import CrashReporter = require('crash-reporter'); -import NativeImage = require('native-image'); -import Screen = require('screen'); -import Shell = require('shell'); +/// +import { + app, + autoUpdater, + BrowserWindow, + contentTracing, + dialog, + globalShortcut, + ipcMain, + Menu, + MenuItem, + powerMonitor, + protocol, + Tray, + clipboard, + crashReporter, + nativeImage, + screen, + shell +} from 'electron'; import path = require('path'); @@ -39,8 +41,8 @@ app.on('window-all-closed', () => { var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { // Someone tried to run a second instance, we should focus our window if (mainWindow) { - if (mainWindow.isMinimized()) mainWindow.restore(); - mainWindow.focus(); + if (mainWindow.isMinimized()) mainWindow.restore(); + mainWindow.focus(); } return true; }); @@ -189,7 +191,7 @@ app.on('ready', () => { onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`); }); -ipc.on('online-status-changed', (event: any, status: any) => { +ipcMain.on('online-status-changed', (event: any, status: any) => { console.log(status); }); @@ -200,7 +202,7 @@ app.on('ready', () => { window = new BrowserWindow({ width: 800, height: 600, - 'title-bar-style': 'hidden-inset', + titleBarStyle: 'hidden-inset', }); window.loadURL('https://github.com'); }); @@ -216,7 +218,7 @@ app.commandLine.appendSwitch('vmodule', 'console=0'); // auto-updater // https://github.com/atom/electron/blob/master/docs/api/auto-updater.md -AutoUpdater.setFeedURL('http://mycompany.com/myapp/latest?version=' + app.getVersion()); +autoUpdater.setFeedURL('http://mycompany.com/myapp/latest?version=' + app.getVersion()); // browser-window // https://github.com/atom/electron/blob/master/docs/api/browser-window.md @@ -232,11 +234,11 @@ win.show(); // content-tracing // https://github.com/atom/electron/blob/master/docs/api/content-tracing.md -ContentTracing.startRecording('*', ContentTracing.DEFAULT_OPTIONS, () => { +contentTracing.startRecording('*', contentTracing.DEFAULT_OPTIONS, () => { console.log('Tracing started'); setTimeout(() => { - ContentTracing.stopRecording('', path => { + contentTracing.stopRecording('', path => { console.log('Tracing data recorded to ' + path); }); }, 5000); @@ -245,7 +247,7 @@ ContentTracing.startRecording('*', ContentTracing.DEFAULT_OPTIONS, () => { // dialog // https://github.com/atom/electron/blob/master/docs/api/dialog.md -console.log(Dialog.showOpenDialog({ +console.log(dialog.showOpenDialog({ properties: ['openFile', 'openDirectory', 'multiSelections'] })); @@ -253,30 +255,30 @@ console.log(Dialog.showOpenDialog({ // https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md // Register a 'ctrl+x' shortcut listener. -var ret = GlobalShortcut.register('ctrl+x', () => { +var ret = globalShortcut.register('ctrl+x', () => { console.log('ctrl+x is pressed'); }); if (!ret) console.log('registerion fails'); // Check whether a shortcut is registered. -console.log(GlobalShortcut.isRegistered('ctrl+x')); +console.log(globalShortcut.isRegistered('ctrl+x')); // Unregister a shortcut. -GlobalShortcut.unregister('ctrl+x'); +globalShortcut.unregister('ctrl+x'); // Unregister all shortcuts. -GlobalShortcut.unregisterAll(); +globalShortcut.unregisterAll(); -// ipc +// ipcMain // https://github.com/atom/electron/blob/master/docs/api/ipc-main-process.md -ipc.on('asynchronous-message', (event: any, arg: any) => { +ipcMain.on('asynchronous-message', (event: any, arg: any) => { console.log(arg); // prints "ping" event.sender.send('asynchronous-reply', 'pong'); }); -ipc.on('synchronous-message', (event: any, arg: any) => { +ipcMain.on('synchronous-message', (event: any, arg: any) => { console.log(arg); // prints "ping" event.returnValue = 'pong'; }); @@ -438,7 +440,7 @@ Menu.buildFromTemplate([ // https://github.com/atom/electron/blob/master/docs/api/power-monitor.md app.on('ready', () => { - PowerMonitor.on('suspend', () => { + powerMonitor.on('suspend', () => { console.log('The system is going to sleep'); }); }); @@ -447,9 +449,9 @@ app.on('ready', () => { // https://github.com/atom/electron/blob/master/docs/api/protocol.md app.on('ready', () => { - Protocol.registerProtocol('atom', (request: any) => { + protocol.registerProtocol('atom', (request: any) => { var url = request.url.substr(7); - return new Protocol.RequestFileJob(path.normalize(`${__dirname}/${url}`)); + return new protocol.RequestFileJob(path.normalize(`${__dirname}/${url}`)); }); }); @@ -473,26 +475,26 @@ app.on('ready', () => { // clipboard // https://github.com/atom/electron/blob/master/docs/api/clipboard.md -Clipboard.writeText('Example String'); -Clipboard.writeText('Example String', 'selection'); -console.log(Clipboard.readText('selection')); +clipboard.writeText('Example String'); +clipboard.writeText('Example String', 'selection'); +console.log(clipboard.readText('selection')); // crash-reporter // https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md -CrashReporter.start({ +crashReporter.start({ productName: 'YourName', companyName: 'YourCompany', submitURL: 'https://your-domain.com/url-to-submit', autoSubmit: true }); -// NativeImage +// nativeImage // https://github.com/atom/electron/blob/master/docs/api/native-image.md var appIcon2 = new Tray('/Users/somebody/images/icon.png'); var window2 = new BrowserWindow({ icon: '/Users/somebody/images/window.png' }); -var image = Clipboard.readImage(); +var image = clipboard.readImage(); var appIcon3 = new Tray(image); var appIcon4 = new Tray('/Users/somebody/images/icon.png'); @@ -500,12 +502,12 @@ var appIcon4 = new Tray('/Users/somebody/images/icon.png'); // https://github.com/atom/electron/blob/master/docs/api/screen.md app.on('ready', () => { - var size = Screen.getPrimaryDisplay().workAreaSize; + var size = screen.getPrimaryDisplay().workAreaSize; mainWindow = new BrowserWindow({ width: size.width, height: size.height }); }); app.on('ready', () => { - var displays = Screen.getAllDisplays(); + var displays = screen.getAllDisplays(); var externalDisplay: any = null; for (var i in displays) { if (displays[i].bounds.x > 0 || displays[i].bounds.y > 0) { @@ -525,4 +527,4 @@ app.on('ready', () => { // shell // https://github.com/atom/electron/blob/master/docs/api/shell.md -Shell.openExternal('https://github.com'); +shell.openExternal('https://github.com'); diff --git a/github-electron/github-electron-main.d.ts b/github-electron/github-electron-main.d.ts deleted file mode 100644 index a133155a93..0000000000 --- a/github-electron/github-electron-main.d.ts +++ /dev/null @@ -1,270 +0,0 @@ -// Type definitions for the Electron 0.25.2 main process -// Project: http://electron.atom.io/ -// Definitions by: jedmao -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -/// - -declare module GitHubElectron { - interface ContentTracing { - /** - * Get a set of category groups. The category groups can change as new code paths are reached. - * @param callback Called once all child processes have acked to the getCategories request. - */ - getCategories(callback: (categoryGroups: any[]) => void): void; - /** - * Start recording on all processes. Recording begins immediately locally, and asynchronously - * on child processes as soon as they receive the EnableRecording request. - * @param categoryFilter A filter to control what category groups should be traced. - * A filter can have an optional "-" prefix to exclude category groups that contain - * a matching category. Having both included and excluded category patterns in the - * same list would not be supported. - * @param options controls what kind of tracing is enabled, it could be a OR-ed - * combination of tracing.DEFAULT_OPTIONS, tracing.ENABLE_SYSTRACE, tracing.ENABLE_SAMPLING - * and tracing.RECORD_CONTINUOUSLY. - * @param callback Called once all child processes have acked to the startRecording request. - */ - startRecording(categoryFilter: string, options: number, callback: Function): void; - /** - * Stop recording on all processes. Child processes typically are caching trace data and - * only rarely flush and send trace data back to the main process. That is because it may - * be an expensive operation to send the trace data over IPC, and we would like to avoid - * much runtime overhead of tracing. So, to end tracing, we must asynchronously ask all - * child processes to flush any pending trace data. - * @param resultFilePath Trace data will be written into this file if it is not empty, - * or into a temporary file. - * @param callback Called once all child processes have acked to the stopRecording request. - */ - stopRecording(resultFilePath: string, callback: - /** - * @param filePath A file that contains the traced data. - */ - (filePath: string) => void - ): void; - /** - * Start monitoring on all processes. Monitoring begins immediately locally, and asynchronously - * on child processes as soon as they receive the startMonitoring request. - * @param callback Called once all child processes have acked to the startMonitoring request. - */ - startMonitoring(categoryFilter: string, options: number, callback: Function): void; - /** - * Stop monitoring on all processes. - * @param callback Called once all child processes have acked to the stopMonitoring request. - */ - stopMonitoring(callback: Function): void; - /** - * Get the current monitoring traced data. Child processes typically are caching trace data - * and only rarely flush and send trace data back to the main process. That is because it may - * be an expensive operation to send the trace data over IPC, and we would like to avoid much - * runtime overhead of tracing. So, to end tracing, we must asynchronously ask all child - * processes to flush any pending trace data. - * @param callback Called once all child processes have acked to the captureMonitoringSnapshot request. - */ - captureMonitoringSnapshot(resultFilePath: string, callback: - /** - * @param filePath A file that contains the traced data - * @returns {} - */ - (filePath: string) => void - ): void; - /** - * Get the maximum across processes of trace buffer percent full state. - * @param callback Called when the TraceBufferUsage value is determined. - */ - getTraceBufferUsage(callback: Function): void; - /** - * @param callback Called every time the given event occurs on any process. - */ - setWatchEvent(categoryName: string, eventName: string, callback: Function): void; - /** - * Cancel the watch event. If tracing is enabled, this may race with the watch event callback. - */ - cancelWatchEvent(): void; - DEFAULT_OPTIONS: number; - ENABLE_SYSTRACE: number; - ENABLE_SAMPLING: number; - RECORD_CONTINUOUSLY: number; - } - - interface Dialog { - /** - * @param callback If supplied, the API call will be asynchronous. - * @returns On success, returns an array of file paths chosen by the user, - * otherwise returns undefined. - */ - showOpenDialog: typeof GitHubElectron.Dialog.showOpenDialog; - /** - * @param callback If supplied, the API call will be asynchronous. - * @returns On success, returns the path of file chosen by the user, otherwise - * returns undefined. - */ - showSaveDialog: typeof GitHubElectron.Dialog.showSaveDialog; - /** - * Shows a message box. It will block until the message box is closed. It returns . - * @param callback If supplied, the API call will be asynchronous. - * @returns The index of the clicked button. - */ - showMessageBox: typeof GitHubElectron.Dialog.showMessageBox; - - /** - * Runs a modal dialog that shows an error message. This API can be called safely - * before the ready event of app module emits, it is usually used to report errors - * in early stage of startup. - */ - showErrorBox(title: string, content: string): void; - } - - interface GlobalShortcut { - /** - * Registers a global shortcut of accelerator. - * @param accelerator Represents a keyboard shortcut. It can contain modifiers - * and key codes, combined by the "+" character. - * @param callback Called when the registered shortcut is pressed by the user. - * @returns {} - */ - register(accelerator: string, callback: Function): void; - /** - * @param accelerator Represents a keyboard shortcut. It can contain modifiers - * and key codes, combined by the "+" character. - * @returns Whether the accelerator is registered. - */ - isRegistered(accelerator: string): boolean; - /** - * Unregisters the global shortcut of keycode. - * @param accelerator Represents a keyboard shortcut. It can contain modifiers - * and key codes, combined by the "+" character. - */ - unregister(accelerator: string): void; - /** - * Unregisters all the global shortcuts. - */ - unregisterAll(): void; - } - - class RequestFileJob { - /** - * Create a request job which would query a file of path and set corresponding mime types. - */ - constructor(path: string); - } - - class RequestStringJob { - /** - * Create a request job which sends a string as response. - */ - constructor(options?: { - /** - * Default is "text/plain". - */ - mimeType?: string; - /** - * Default is "UTF-8". - */ - charset?: string; - data?: string; - }); - } - - class RequestBufferJob { - /** - * Create a request job which accepts a buffer and sends a string as response. - */ - constructor(options?: { - /** - * Default is "application/octet-stream". - */ - mimeType?: string; - /** - * Default is "UTF-8". - */ - encoding?: string; - data?: Buffer; - }); - } - - interface Protocol { - registerProtocol(scheme: string, handler: (request: any) => void): void; - unregisterProtocol(scheme: string): void; - isHandledProtocol(scheme: string): boolean; - interceptProtocol(scheme: string, handler: (request: any) => void): void; - uninterceptProtocol(scheme: string): void; - RequestFileJob: typeof RequestFileJob; - RequestStringJob: typeof RequestStringJob; - RequestBufferJob: typeof RequestBufferJob; - } -} - -declare module 'app' { - var _app: GitHubElectron.App; - export = _app; -} - -declare module 'auto-updater' { - var _autoUpdater: GitHubElectron.AutoUpdater; - export = _autoUpdater; -} - -declare module 'browser-window' { - var BrowserWindow: typeof GitHubElectron.BrowserWindow; - export = BrowserWindow; -} - -declare module 'content-tracing' { - var contentTracing: GitHubElectron.ContentTracing - export = contentTracing; -} - -declare module 'dialog' { - var dialog: GitHubElectron.Dialog - export = dialog; -} - -declare module 'global-shortcut' { - var globalShortcut: GitHubElectron.GlobalShortcut; - export = globalShortcut; -} - -declare module 'ipc' { - var ipc: NodeJS.EventEmitter; - export = ipc; -} - -declare module 'menu' { - var Menu: typeof GitHubElectron.Menu; - export = Menu; -} - -declare module 'menu-item' { - var MenuItem: typeof GitHubElectron.MenuItem; - export = MenuItem; -} - -declare module 'power-monitor' { - var powerMonitor: NodeJS.EventEmitter; - export = powerMonitor; -} - -declare module 'protocol' { - var protocol: GitHubElectron.Protocol; - export = protocol; -} - -declare module 'tray' { - var Tray: typeof GitHubElectron.Tray; - export = Tray; -} - -interface NodeRequireFunction { - (id: 'app'): GitHubElectron.App - (id: 'auto-updater'): GitHubElectron.AutoUpdater - (id: 'browser-window'): typeof GitHubElectron.BrowserWindow - (id: 'content-tracing'): GitHubElectron.ContentTracing - (id: 'dialog'): GitHubElectron.Dialog - (id: 'global-shortcut'): GitHubElectron.GlobalShortcut - (id: 'ipc'): NodeJS.EventEmitter - (id: 'menu'): typeof GitHubElectron.Menu - (id: 'menu-item'): typeof GitHubElectron.MenuItem - (id: 'power-monitor'): NodeJS.EventEmitter - (id: 'protocol'): GitHubElectron.Protocol - (id: 'tray'): typeof GitHubElectron.Tray -} diff --git a/github-electron/github-electron-renderer-tests.ts b/github-electron/github-electron-renderer-tests.ts index 86680600fc..cf610718ce 100644 --- a/github-electron/github-electron-renderer-tests.ts +++ b/github-electron/github-electron-renderer-tests.ts @@ -1,23 +1,25 @@ -/// -import ipc = require('ipc'); -import remote = require('remote'); -import WebFrame = require('web-frame'); -import Clipboard = require('clipboard'); -import CrashReporter = require('crash-reporter'); -import NativeImage = require('native-image'); -import Screen = require('screen'); -import Shell = require('shell'); +/// +import { + ipcRenderer, + remote, + webFrame, + clipboard, + crashReporter, + nativeImage, + screen, + shell +} from 'electron'; import fs = require('fs'); // In renderer process (web page). // https://github.com/atom/electron/blob/master/docs/api/ipc-renderer.md -console.log(ipc.sendSync('synchronous-message', 'ping')); // prints "pong" +console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong" -ipc.on('asynchronous-reply', (arg: any) => { +ipcRenderer.on('asynchronous-reply', (arg: any) => { console.log(arg); // prints "pong" }); -ipc.send('asynchronous-message', 'ping'); +ipcRenderer.send('asynchronous-message', 'ping'); // remote // https://github.com/atom/electron/blob/master/docs/api/remote.md @@ -45,9 +47,9 @@ remote.getCurrentWindow().capturePage(buf => { // web-frame // https://github.com/atom/electron/blob/master/docs/api/web-frame.md -WebFrame.setZoomFactor(2); +webFrame.setZoomFactor(2); -WebFrame.setSpellCheckProvider('en-US', true, { +webFrame.setSpellCheckProvider('en-US', true, { spellCheck: text => { return !(require('spellchecker').isMisspelled(text)); } @@ -56,27 +58,27 @@ WebFrame.setSpellCheckProvider('en-US', true, { // clipboard // https://github.com/atom/electron/blob/master/docs/api/clipboard.md -Clipboard.writeText('Example String'); -Clipboard.writeText('Example String', 'selection'); -console.log(Clipboard.readText('selection')); +clipboard.writeText('Example String'); +clipboard.writeText('Example String', 'selection'); +console.log(clipboard.readText('selection')); // crash-reporter // https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md -CrashReporter.start({ +crashReporter.start({ productName: 'YourName', companyName: 'YourCompany', submitURL: 'https://your-domain.com/url-to-submit', autoSubmit: true }); -// NativeImage +// nativeImage // https://github.com/atom/electron/blob/master/docs/api/native-image.md var Tray: typeof GitHubElectron.Tray = remote.require('Tray'); var appIcon2 = new Tray('/Users/somebody/images/icon.png'); var window2 = new BrowserWindow({ icon: '/Users/somebody/images/window.png' }); -var image = Clipboard.readImage(); +var image = clipboard.readImage(); var appIcon3 = new Tray(image); var appIcon4 = new Tray('/Users/somebody/images/icon.png'); @@ -88,12 +90,12 @@ var app: GitHubElectron.App = remote.require('app'); var mainWindow: GitHubElectron.BrowserWindow = null; app.on('ready', () => { - var size = Screen.getPrimaryDisplay().workAreaSize; + var size = screen.getPrimaryDisplay().workAreaSize; mainWindow = new BrowserWindow({ width: size.width, height: size.height }); }); app.on('ready', () => { - var displays = Screen.getAllDisplays(); + var displays = screen.getAllDisplays(); var externalDisplay: any = null; for (var i in displays) { if (displays[i].bounds.x > 0 || displays[i].bounds.y > 0) { @@ -113,4 +115,4 @@ app.on('ready', () => { // shell // https://github.com/atom/electron/blob/master/docs/api/shell.md -Shell.openExternal('https://github.com'); +shell.openExternal('https://github.com'); diff --git a/github-electron/github-electron-renderer.d.ts b/github-electron/github-electron-renderer.d.ts deleted file mode 100644 index 62b29d9cd6..0000000000 --- a/github-electron/github-electron-renderer.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -// Type definitions for the Electron 0.25.2 renderer process (web page) -// Project: http://electron.atom.io/ -// Definitions by: jedmao -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -/// - -declare module GitHubElectron { - export class InProcess implements NodeJS.EventEmitter { - addListener(event: string, listener: Function): InProcess; - on(event: string, listener: Function): InProcess; - once(event: string, listener: Function): InProcess; - removeListener(event: string, listener: Function): InProcess; - removeAllListeners(event?: string): InProcess; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - /** - * Send ...args to the renderer via channel in asynchronous message, the main - * process can handle it by listening to the channel event of ipc module. - */ - send(channel: string, ...args: any[]): void; - /** - * Send ...args to the renderer via channel in synchronous message, and returns - * the result sent from main process. The main process can handle it by listening - * to the channel event of ipc module, and returns by setting event.returnValue. - * Note: Usually developers should never use this API, since sending synchronous - * message would block the whole renderer process. - * @returns The result sent from the main process. - */ - sendSync(channel: string, ...args: any[]): string; - /** - * Like ipc.send but the message will be sent to the host page instead of the main process. - * This is mainly used by the page in to communicate with host page. - */ - sendToHost(channel: string, ...args: any[]): void; - } - - interface Remote { - /** - * @returns The object returned by require(module) in the main process. - */ - require(module: string): any; - /** - * @returns The BrowserWindow object which this web page belongs to. - */ - getCurrentWindow(): BrowserWindow - /** - * @returns The global variable of name (e.g. global[name]) in the main process. - */ - getGlobal(name: string): any; - /** - * Returns the process object in the main process. This is the same as - * remote.getGlobal('process'), but gets cached. - */ - process: any; - } - - interface WebFrame { - /** - * Changes the zoom factor to the specified factor, zoom factor is - * zoom percent / 100, so 300% = 3.0. - */ - setZoomFactor(factor: number): void; - /** - * @returns The current zoom factor. - */ - getZoomFactor(): number; - /** - * Changes the zoom level to the specified level, 0 is "original size", and each - * increment above or below represents zooming 20% larger or smaller to default - * limits of 300% and 50% of original size, respectively. - */ - setZoomLevel(level: number): void; - /** - * @returns The current zoom level. - */ - getZoomLevel(): number; - /** - * Sets a provider for spell checking in input fields and text areas. - */ - setSpellCheckProvider(language: string, autoCorrectWord: boolean, provider: { - /** - * @returns Whether the word passed is correctly spelled. - */ - spellCheck: (text: string) => boolean; - }): void; - /** - * Sets the scheme as secure scheme. Secure schemes do not trigger mixed content - * warnings. For example, https and data are secure schemes because they cannot be - * corrupted by active network attackers. - */ - registerURLSchemeAsSecure(scheme: string): void; - } -} - -declare module 'ipc' { - var inProcess: GitHubElectron.InProcess; - export = inProcess; -} - -declare module 'remote' { - var remote: GitHubElectron.Remote; - export = remote; -} - -declare module 'web-frame' { - var webframe: GitHubElectron.WebFrame; - export = webframe; -} - -interface NodeRequireFunction { - (id: 'ipc'): GitHubElectron.InProcess - (id: 'remote'): GitHubElectron.Remote - (id: 'web-frame'): GitHubElectron.WebFrame -} diff --git a/github-electron/github-electron.d.ts b/github-electron/github-electron.d.ts index 679cc6700d..7c5fa8b4d6 100644 --- a/github-electron/github-electron.d.ts +++ b/github-electron/github-electron.d.ts @@ -1,7 +1,7 @@ -// Type definitions for Electron 0.25.2 (shared between main and rederer processes) +// Type definitions for Electron v0.35.0 // Project: http://electron.atom.io/ -// Definitions by: jedmao -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: jedmao , rhysd +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -447,54 +447,63 @@ declare module GitHubElectron { isVisibleOnAllWorkspaces(): boolean; } + interface WebPreferences { + nodeIntegration?: boolean; + preload?: string; + partition: string; + zoomFactor: number; + javascript: boolean; + webSecurity: boolean; + allowDisplayingInsecureContent: boolean; + allowRunningInsecureContent: boolean; + images: boolean; + textAreasAreResizable: boolean; + webgl?: boolean; + webaudio?: boolean; + plugins?: boolean; + experimentalFeatures?: boolean; + experimentalCanvasFeatures?: boolean; + overlayScrollbars?: boolean; + sharedWorker?: boolean; + directWrite?: boolean; + pageVisibility?: boolean; + } + // Includes all options BrowserWindow can take as of this writing // http://electron.atom.io/docs/v0.29.0/api/browser-window/ interface BrowserWindowOptions extends Rectangle { show?: boolean; - 'use-content-size'?: boolean; + useContentSize?: boolean; center?: boolean; - 'min-width'?: number; - 'min-height'?: number; - 'max-width'?: number; - 'max-height'?: number; + minWidth?: number; + minHeight?: number; + maxWidth?: number; + maxHeight?: number; resizable?: boolean; - 'always-on-top'?: boolean; + alwaysOnTop?: boolean; fullscreen?: boolean; - 'skip-taskbar'?: boolean; - 'zoom-factor'?: number; + skipTaskbar?: boolean; + zoomFactor?: number; kiosk?: boolean; title?: string; icon?: NativeImage|string; frame?: boolean; - 'node-integration'?: boolean; - 'accept-first-mouse'?: boolean; - 'disable-auto-hide-cursor'?: boolean; - 'auto-hide-menu-bar'?: boolean; - 'enable-larger-than-screen'?: boolean; - 'dark-theme'?: boolean; + acceptFirstMouse?: boolean; + disableAutoHideCursor?: boolean; + autoHideMenuBar?: boolean; + enableLargerThanScreen?: boolean; + darkTheme?: boolean; preload?: string; transparent?: boolean; type?: string; - 'standard-window'?: boolean; - 'web-preferences'?: any; // Object - javascript?: boolean; - 'web-security'?: boolean; - images?: boolean; + standardWindow?: boolean; + webPreferences?: WebPreferences; java?: boolean; - 'text-areas-are-resizable'?: boolean; - webgl?: boolean; - webaudio?: boolean; - plugins?: boolean; - 'extra-plugin-dirs'?: string[]; - 'experimental-features'?: boolean; - 'experimental-canvas-features'?: boolean; - 'subpixel-font-scaling'?: boolean; - 'overlay-scrollbars'?: boolean; - 'overlay-fullscreen-video'?: boolean; - 'shared-worker'?: boolean; - 'direct-write'?: boolean; - 'page-visibility'?: boolean; - 'title-bar-style'?: string; + textAreasAreResizable?: boolean; + extraPluginDirs?: string[]; + subpixelFontScaling?: boolean; + overlayFullscreenVideo?: boolean; + titleBarStyle?: string; } interface Rectangle { @@ -1408,31 +1417,308 @@ declare module GitHubElectron { */ beep(): void; } -} -declare module 'clipboard' { - var clipboard: GitHubElectron.Clipboard - export = clipboard; -} + // Type definitions for renderer process -declare module 'crash-reporter' { - var crashReporter: GitHubElectron.CrashReporter - export = crashReporter; -} + export class IpcRenderer implements NodeJS.EventEmitter { + addListener(event: string, listener: Function): IpcRenderer; + on(event: string, listener: Function): IpcRenderer; + once(event: string, listener: Function): IpcRenderer; + removeListener(event: string, listener: Function): IpcRenderer; + removeAllListeners(event?: string): IpcRenderer; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + /** + * Send ...args to the renderer via channel in asynchronous message, the main + * process can handle it by listening to the channel event of ipc module. + */ + send(channel: string, ...args: any[]): void; + /** + * Send ...args to the renderer via channel in synchronous message, and returns + * the result sent from main process. The main process can handle it by listening + * to the channel event of ipc module, and returns by setting event.returnValue. + * Note: Usually developers should never use this API, since sending synchronous + * message would block the whole renderer process. + * @returns The result sent from the main process. + */ + sendSync(channel: string, ...args: any[]): string; + /** + * Like ipc.send but the message will be sent to the host page instead of the main process. + * This is mainly used by the page in to communicate with host page. + */ + sendToHost(channel: string, ...args: any[]): void; + } -declare module 'native-image' { - var nativeImage: typeof GitHubElectron.NativeImage; - export = nativeImage; -} + interface Remote { + /** + * @returns The object returned by require(module) in the main process. + */ + require(module: string): any; + /** + * @returns The BrowserWindow object which this web page belongs to. + */ + getCurrentWindow(): BrowserWindow + /** + * @returns The global variable of name (e.g. global[name]) in the main process. + */ + getGlobal(name: string): any; + /** + * Returns the process object in the main process. This is the same as + * remote.getGlobal('process'), but gets cached. + */ + process: any; + } + + interface WebFrame { + /** + * Changes the zoom factor to the specified factor, zoom factor is + * zoom percent / 100, so 300% = 3.0. + */ + setZoomFactor(factor: number): void; + /** + * @returns The current zoom factor. + */ + getZoomFactor(): number; + /** + * Changes the zoom level to the specified level, 0 is "original size", and each + * increment above or below represents zooming 20% larger or smaller to default + * limits of 300% and 50% of original size, respectively. + */ + setZoomLevel(level: number): void; + /** + * @returns The current zoom level. + */ + getZoomLevel(): number; + /** + * Sets a provider for spell checking in input fields and text areas. + */ + setSpellCheckProvider(language: string, autoCorrectWord: boolean, provider: { + /** + * @returns Whether the word passed is correctly spelled. + */ + spellCheck: (text: string) => boolean; + }): void; + /** + * Sets the scheme as secure scheme. Secure schemes do not trigger mixed content + * warnings. For example, https and data are secure schemes because they cannot be + * corrupted by active network attackers. + */ + registerURLSchemeAsSecure(scheme: string): void; + } -declare module 'screen' { - var screen: GitHubElectron.Screen; - export = screen; -} + // Type definitions for main process -declare module 'shell' { - var shell: GitHubElectron.Shell; - export = shell; + interface ContentTracing { + /** + * Get a set of category groups. The category groups can change as new code paths are reached. + * @param callback Called once all child processes have acked to the getCategories request. + */ + getCategories(callback: (categoryGroups: any[]) => void): void; + /** + * Start recording on all processes. Recording begins immediately locally, and asynchronously + * on child processes as soon as they receive the EnableRecording request. + * @param categoryFilter A filter to control what category groups should be traced. + * A filter can have an optional "-" prefix to exclude category groups that contain + * a matching category. Having both included and excluded category patterns in the + * same list would not be supported. + * @param options controls what kind of tracing is enabled, it could be a OR-ed + * combination of tracing.DEFAULT_OPTIONS, tracing.ENABLE_SYSTRACE, tracing.ENABLE_SAMPLING + * and tracing.RECORD_CONTINUOUSLY. + * @param callback Called once all child processes have acked to the startRecording request. + */ + startRecording(categoryFilter: string, options: number, callback: Function): void; + /** + * Stop recording on all processes. Child processes typically are caching trace data and + * only rarely flush and send trace data back to the main process. That is because it may + * be an expensive operation to send the trace data over IPC, and we would like to avoid + * much runtime overhead of tracing. So, to end tracing, we must asynchronously ask all + * child processes to flush any pending trace data. + * @param resultFilePath Trace data will be written into this file if it is not empty, + * or into a temporary file. + * @param callback Called once all child processes have acked to the stopRecording request. + */ + stopRecording(resultFilePath: string, callback: + /** + * @param filePath A file that contains the traced data. + */ + (filePath: string) => void + ): void; + /** + * Start monitoring on all processes. Monitoring begins immediately locally, and asynchronously + * on child processes as soon as they receive the startMonitoring request. + * @param callback Called once all child processes have acked to the startMonitoring request. + */ + startMonitoring(categoryFilter: string, options: number, callback: Function): void; + /** + * Stop monitoring on all processes. + * @param callback Called once all child processes have acked to the stopMonitoring request. + */ + stopMonitoring(callback: Function): void; + /** + * Get the current monitoring traced data. Child processes typically are caching trace data + * and only rarely flush and send trace data back to the main process. That is because it may + * be an expensive operation to send the trace data over IPC, and we would like to avoid much + * runtime overhead of tracing. So, to end tracing, we must asynchronously ask all child + * processes to flush any pending trace data. + * @param callback Called once all child processes have acked to the captureMonitoringSnapshot request. + */ + captureMonitoringSnapshot(resultFilePath: string, callback: + /** + * @param filePath A file that contains the traced data + * @returns {} + */ + (filePath: string) => void + ): void; + /** + * Get the maximum across processes of trace buffer percent full state. + * @param callback Called when the TraceBufferUsage value is determined. + */ + getTraceBufferUsage(callback: Function): void; + /** + * @param callback Called every time the given event occurs on any process. + */ + setWatchEvent(categoryName: string, eventName: string, callback: Function): void; + /** + * Cancel the watch event. If tracing is enabled, this may race with the watch event callback. + */ + cancelWatchEvent(): void; + DEFAULT_OPTIONS: number; + ENABLE_SYSTRACE: number; + ENABLE_SAMPLING: number; + RECORD_CONTINUOUSLY: number; + } + + interface Dialog { + /** + * @param callback If supplied, the API call will be asynchronous. + * @returns On success, returns an array of file paths chosen by the user, + * otherwise returns undefined. + */ + showOpenDialog: typeof GitHubElectron.Dialog.showOpenDialog; + /** + * @param callback If supplied, the API call will be asynchronous. + * @returns On success, returns the path of file chosen by the user, otherwise + * returns undefined. + */ + showSaveDialog: typeof GitHubElectron.Dialog.showSaveDialog; + /** + * Shows a message box. It will block until the message box is closed. It returns . + * @param callback If supplied, the API call will be asynchronous. + * @returns The index of the clicked button. + */ + showMessageBox: typeof GitHubElectron.Dialog.showMessageBox; + + /** + * Runs a modal dialog that shows an error message. This API can be called safely + * before the ready event of app module emits, it is usually used to report errors + * in early stage of startup. + */ + showErrorBox(title: string, content: string): void; + } + + interface GlobalShortcut { + /** + * Registers a global shortcut of accelerator. + * @param accelerator Represents a keyboard shortcut. It can contain modifiers + * and key codes, combined by the "+" character. + * @param callback Called when the registered shortcut is pressed by the user. + * @returns {} + */ + register(accelerator: string, callback: Function): void; + /** + * @param accelerator Represents a keyboard shortcut. It can contain modifiers + * and key codes, combined by the "+" character. + * @returns Whether the accelerator is registered. + */ + isRegistered(accelerator: string): boolean; + /** + * Unregisters the global shortcut of keycode. + * @param accelerator Represents a keyboard shortcut. It can contain modifiers + * and key codes, combined by the "+" character. + */ + unregister(accelerator: string): void; + /** + * Unregisters all the global shortcuts. + */ + unregisterAll(): void; + } + + class RequestFileJob { + /** + * Create a request job which would query a file of path and set corresponding mime types. + */ + constructor(path: string); + } + + class RequestStringJob { + /** + * Create a request job which sends a string as response. + */ + constructor(options?: { + /** + * Default is "text/plain". + */ + mimeType?: string; + /** + * Default is "UTF-8". + */ + charset?: string; + data?: string; + }); + } + + class RequestBufferJob { + /** + * Create a request job which accepts a buffer and sends a string as response. + */ + constructor(options?: { + /** + * Default is "application/octet-stream". + */ + mimeType?: string; + /** + * Default is "UTF-8". + */ + encoding?: string; + data?: Buffer; + }); + } + + interface Protocol { + registerProtocol(scheme: string, handler: (request: any) => void): void; + unregisterProtocol(scheme: string): void; + isHandledProtocol(scheme: string): boolean; + interceptProtocol(scheme: string, handler: (request: any) => void): void; + uninterceptProtocol(scheme: string): void; + RequestFileJob: typeof RequestFileJob; + RequestStringJob: typeof RequestStringJob; + RequestBufferJob: typeof RequestBufferJob; + } + + + interface Electron { + clipboard: GitHubElectron.Clipboard; + crashReporter: GitHubElectron.CrashReporter; + nativeImage: GitHubElectron.NativeImage; + screen: GitHubElectron.Screen; + shell: GitHubElectron.Shell; + remote: GitHubElectron.Remote; + ipcRenderer: GitHubElectron.IpcRenderer; + webFrame: GitHubElectron.WebFrame; + app: GitHubElectron.App; + autoUpdater: GitHubElectron.AutoUpdater; + BrowserWindow: typeof GitHubElectron.BrowserWindow; + contentTracing: GitHubElectron.ContentTracing; + dialog: GitHubElectron.Dialog; + globalShortcut: GitHubElectron.GlobalShortcut; + ipcMain: NodeJS.EventEmitter; + Menu: typeof GitHubElectron.Menu; + MenuItem: typeof GitHubElectron.MenuItem; + powerMonitor: NodeJS.EventEmitter; + protocol: GitHubElectron.Protocol; + Tray: typeof GitHubElectron.Tray; + } } interface Window { @@ -1450,10 +1736,11 @@ interface File { path: string; } +declare module 'electron' { + var electron: GitHubElectron.Electron; + export = electron; +} + interface NodeRequireFunction { - (id: 'clipboard'): GitHubElectron.Clipboard - (id: 'crash-reporter'): GitHubElectron.CrashReporter - (id: 'native-image'): typeof GitHubElectron.NativeImage - (id: 'screen'): GitHubElectron.Screen - (id: 'shell'): GitHubElectron.Shell + (id: 'electron'): GitHubElectron.Electron; }