From 0e9b30d821df52555eb2fdc9dfc8807ee21763eb Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 2 Jun 2016 17:56:50 +0200 Subject: [PATCH] Electron (#9445) * Update to Electron 1.1.1 * Update to Electron 1.1.2 * Update to Electron 1.2.0 * Update to Electron 1.2.1 --- github-electron/github-electron-main-tests.ts | 45 +++-- .../github-electron-renderer-tests.ts | 5 +- github-electron/github-electron.d.ts | 177 ++++++++++++++---- 3 files changed, 176 insertions(+), 51 deletions(-) diff --git a/github-electron/github-electron-main-tests.ts b/github-electron/github-electron-main-tests.ts index 00798c382b..fd840b72e4 100644 --- a/github-electron/github-electron-main-tests.ts +++ b/github-electron/github-electron-main-tests.ts @@ -79,19 +79,9 @@ app.on('ready', () => { mainWindow = null; }); - mainWindow.print({silent: true, printBackground: false}); mainWindow.webContents.print({silent: true, printBackground: false}); - mainWindow.print(); mainWindow.webContents.print(); - mainWindow.printToPDF({ - marginsType: 1, - pageSize: 'A3', - printBackground: true, - printSelectionOnly: true, - landscape: true, - }, (error: Error, data: Buffer) => {}); - mainWindow.webContents.printToPDF({ marginsType: 1, pageSize: 'A3', @@ -100,7 +90,6 @@ app.on('ready', () => { landscape: true, }, (error: Error, data: Buffer) => {}); - mainWindow.printToPDF({}, (err, data) => {}); mainWindow.webContents.printToPDF({}, (err, data) => {}); mainWindow.webContents.executeJavaScript('return true;'); @@ -146,6 +135,29 @@ app.on('ready', () => { mainWindow.webContents.debugger.sendCommand("Network.enable"); }); +app.commandLine.appendSwitch('enable-web-bluetooth'); + +app.on('ready', () => { + mainWindow.webContents.on('select-bluetooth-device', (event, deviceList, callback) => { + event.preventDefault(); + + let result = (() => { + for (let device of deviceList) { + if (device.deviceName === 'test') { + return device; + } + } + return null; + })(); + + if (!result) { + callback(''); + } else { + callback(result.deviceId); + } + }); +}); + // Locale app.getLocale(); @@ -287,10 +299,6 @@ if (browserOptions.transparent) { win.loadURL('file://' + __dirname + '/fallback.html'); } -app.on('platform-theme-changed', () => { - console.log(systemPreferences.isDarkMode()); -}); - // app // https://github.com/atom/electron/blob/master/docs/api/app.md @@ -857,6 +865,13 @@ session.defaultSession.setPermissionRequestHandler(function(webContents, permiss callback(true); }); +// consider any url ending with `example.com`, `foobar.com`, `baz` +// for integrated authentication. +session.defaultSession.allowNTLMCredentialsForDomains('*example.com, *foobar.com, *baz') + +// consider all urls for integrated authentication. +session.defaultSession.allowNTLMCredentialsForDomains('*') + // Modify the user agent for all requests to the following urls. var filter = { urls: ["https://*.github.com/*", "*://electron.github.io"] diff --git a/github-electron/github-electron-renderer-tests.ts b/github-electron/github-electron-renderer-tests.ts index 42d034c5c7..eecec65752 100644 --- a/github-electron/github-electron-renderer-tests.ts +++ b/github-electron/github-electron-renderer-tests.ts @@ -75,6 +75,9 @@ webFrame.executeJavaScript('JSON.stringify({})', false, (result) => { console.log(result); }); +console.log(webFrame.getResourceUsage()); +webFrame.clearCache(); + // clipboard // https://github.com/atom/electron/blob/master/docs/api/clipboard.md @@ -232,7 +235,7 @@ webview.addEventListener('found-in-page', function(e) { } }); -var rquestId = webview.findInPage("test"); +var requestId = webview.findInPage("test"); webview.addEventListener('new-window', function(e) { require('electron').shell.openExternal(e.url); diff --git a/github-electron/github-electron.d.ts b/github-electron/github-electron.d.ts index 235e7d55fb..75840aa741 100644 --- a/github-electron/github-electron.d.ts +++ b/github-electron/github-electron.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Electron v1.0.2 +// Type definitions for Electron v1.2.1 // Project: http://electron.atom.io/ // Definitions by: jedmao , rhysd , Milan Burda // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -49,7 +49,9 @@ declare namespace Electron { /** * Emitted when all windows have been closed. * - * This event is only emitted when the application is not going to quit. + * 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. @@ -271,30 +273,29 @@ declare namespace Electron { * Note: This API is only available on Windows. */ setUserTasks(tasks: Task[]): void; - /** - * Dynamically sets whether to always send credentials for HTTP NTLM or Negotiate authentication. - * Normally, Electron will only send NTLM/Kerberos credentials for URLs that fall under - * "Local Intranet" sites (i.e. are in the same domain as you). - * However, this detection often fails when corporate networks are badly configured, - * so this lets you co-opt this behavior and enable it for all URLs. - */ - allowNTLMCredentialsForAllDomains(allow: boolean): void; /** * 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 Mac. */ - setUserActivity(type: string, userInfo: Object): void; + setUserActivity(type: string, userInfo: Object, webpageURL?: string): void; /** * @returns The type of the currently running activity. * @@ -851,7 +852,7 @@ declare namespace Electron { * Changes the attachment point for sheets on Mac OS X. * Note: This API is available only on OS X. */ - setSheetOffset(offset: number): void; + setSheetOffset(offsetY: number, offsetX?: number): void; /** * Starts or stops flashing the window to attract user's attention. */ @@ -925,19 +926,11 @@ declare namespace Electron { capturePage(rect: Rectangle, callback: (image: NativeImage) => void): void; capturePage(callback: (image: NativeImage) => void): void; /** - * Same with webContents.print([options]) - */ - print(options?: PrintOptions): void; - /** - * Same with webContents.printToPDF([options]) - */ - printToPDF(options: PrintToPDFOptions, callback: (error: Error, data: Buffer) => void): void; - /** - * Same with webContents.loadURL(url). + * Same as webContents.loadURL(url). */ loadURL(url: string, options?: LoadURLOptions): void; /** - * Same with webContents.reload. + * Same as webContents.reload. */ reload(): void; /** @@ -984,6 +977,11 @@ declare namespace Electron { * Note: This API is available only on OS X. */ showDefinitionForSelection(): void; + /** + * Changes window icon. + * Note: This API is not available on OS X. + */ + 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. @@ -1275,7 +1273,8 @@ declare namespace Electron { */ fullscreen?: boolean; /** - * Whether the maximize/zoom button on OS X should toggle full screen mode or maximize window. + * Whether the window can be put into fullscreen mode. + * On OS X, also whether the maximize/zoom button should toggle full screen mode or maximize window. * Default: true. */ fullscreenable?: boolean; @@ -1392,11 +1391,11 @@ declare namespace Electron { /** * @returns The contents of the clipboard as markup. */ - readHtml(type?: ClipboardType): string; + readHTML(type?: ClipboardType): string; /** * Writes markup to the clipboard. */ - writeHtml(markup: string, type?: ClipboardType): void; + writeHTML(markup: string, type?: ClipboardType): void; /** * @returns The contents of the clipboard as a NativeImage. */ @@ -1408,11 +1407,11 @@ declare namespace Electron { /** * @returns The contents of the clipboard as RTF. */ - readRtf(type?: ClipboardType): string; + readRTF(type?: ClipboardType): string; /** * Writes the text into the clipboard in RTF. */ - writeRtf(text: string, type?: ClipboardType): void; + writeRTF(text: string, type?: ClipboardType): void; /** * Clears everything in clipboard. */ @@ -1718,6 +1717,10 @@ declare namespace Electron { interface OpenDialogOptions { title?: string; defaultPath?: string; + /** + * Custom label for the confirmation button, when left empty the default label will be used. + */ + buttonLabel?: string; /** * File types that can be displayed or selected. */ @@ -1738,6 +1741,10 @@ declare namespace Electron { interface SaveDialogOptions { title?: string; defaultPath?: string; + /** + * Custom label for the confirmation button, when left empty the default label will be used. + */ + buttonLabel?: string; /** * File types that can be displayed, see dialog.showOpenDialog for an example. */ @@ -2590,6 +2597,11 @@ declare namespace Electron { * Clears the host resolver cache. */ clearHostResolverCache(callback: Function): void; + /** + * Dynamically sets whether to always send credentials for HTTP NTLM or Negotiate authentication. + * @param domains Comma-seperated list of servers for which integrated authentication is enabled. + */ + allowNTLMCredentialsForDomains(domains: string): void; /** * The webRequest API set allows to intercept and modify contents of a request at various stages of its lifetime. */ @@ -2993,7 +3005,7 @@ declare namespace Electron { * * Note: This is only implemented on OS X. */ - subscribeNotification(event: string, callback: Function): number; + subscribeNotification(event: string, callback: (event: Event, userInfo: Object) => void): number; /** * Removes the subscriber with id. * @@ -3320,6 +3332,14 @@ declare namespace Electron { * Emitted when there is a new context menu that needs to be handled. */ on(event: 'context-menu', listener: (event: Event, params: ContextMenuParams) => void): this; + /** + * Emitted when bluetooth device needs to be selected on call to navigator.bluetooth.requestDevice. + * To use navigator.bluetooth api webBluetooth should be enabled. + * If event.preventDefault is not called, first available device will be selected. + * callback should be called with deviceId to be selected, + * passing empty string to callback will cancel the request. + */ + on(event: 'select-bluetooth-device', listener: (event: Event, deviceList: BluetoothDevice[], callback: (deviceId: string) => void) => void): this; on(event: string, listener: Function): this; /** * Loads the url in the window. @@ -3590,6 +3610,10 @@ declare namespace Electron { * @returns If the process of saving page has been initiated successfully. */ savePage(fullPath: string, saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML', callback?: (eror: Error) => void): boolean; + /** + * @returns The unique ID of this WebContents. + */ + id: number; /** * @returns The session object used by this webContents. */ @@ -3748,6 +3772,11 @@ declare namespace Electron { menuSourceType: 'none' | 'mouse' | 'keyboard' | 'touch' | 'touchMenu'; } + interface BluetoothDevice { + deviceName: string; + deviceId: string; + } + interface Headers { [key: string]: string; } @@ -3756,8 +3785,8 @@ declare namespace Electron { /** * Specifies the action to take place when ending webContents.findInPage request. - * 'clearSelection' - Translate the selection into a normal selection. - * 'keepSelection' - Clear the selection. + * 'clearSelection' - Clear the selection. + * 'keepSelection' - Translate the selection into a normal selection. * 'activateSelection' - Focus and click the selection node. */ type StopFindInPageAtion = 'clearSelection' | 'keepSelection' | 'activateSelection'; @@ -3805,7 +3834,7 @@ declare namespace Electron { * Specify page size of the generated PDF. * Default: A4. */ - pageSize?: 'A3' | 'A4' | 'A5' | 'Legal' | 'Letter' | 'Tabloid'; + pageSize?: 'A3' | 'A4' | 'A5' | 'Legal' | 'Letter' | 'Tabloid' | Dimension; /** * Whether to print CSS backgrounds. * Default: false. @@ -4063,6 +4092,32 @@ declare namespace Electron { * this limitation. */ executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): void; + /** + * @returns Object describing usage information of Blink’s internal memory caches. + */ + getResourceUsage(): ResourceUsages; + /** + * Attempts to free memory that is no longer being used (like images from a previous navigation). + */ + clearCache(): void; + } + + interface ResourceUsages { + fonts: ResourceUsage; + images: ResourceUsage; + cssStyleSheets: ResourceUsage; + xslStyleSheets: ResourceUsage; + scripts: ResourceUsage; + other: ResourceUsage; + } + + interface ResourceUsage { + count: number; + decodedSize: number; + liveSize: number; + purgeableSize: number; + purgedSize: number; + size: number; } // https://github.com/electron/electron/blob/master/docs/api/web-view-tag.md @@ -4602,6 +4657,10 @@ declare namespace Electron { * properties and a single method. */ postMessage(message: string, targetOrigin: string): void; + /** + * Invokes the print dialog on the child window. + */ + print(): void; } // https://github.com/electron/electron/blob/master/docs/api/synopsis.md @@ -4669,6 +4728,10 @@ interface File { declare namespace NodeJS { interface Process { + /** + * Setting this to true can disable the support for asar archives in Node's built-in modules. + */ + noAsar?: boolean; /** * Process's type */ @@ -4696,10 +4759,6 @@ declare namespace NodeJS { */ on(event: 'loaded', listener: Function): this; on(event: string, listener: Function): this; - /** - * Setting this to true can disable the support for asar archives in Node's built-in modules. - */ - noAsar?: boolean; /** * Causes the main thread of the current process crash; */ @@ -4715,6 +4774,54 @@ declare namespace NodeJS { * Note: This API is only available on Mac and Linux. */ setFdLimit(maxDescriptors: number): void; + /** + * @returns Object giving memory usage statistics about the current process. + * Note: All statistics are reported in Kilobytes. + */ + getProcessMemoryInfo(): ProcessMemoryInfo; + /** + * @returns Object giving memory usage statistics about the entire system. + * Note: All statistics are reported in Kilobytes. + */ + getSystemMemoryInfo(): SystemMemoryInfo; + } + + interface ProcessMemoryInfo { + /** + * The amount of memory currently pinned to actual physical RAM. + */ + workingSetSize: number; + /** + * The maximum amount of memory that has ever been pinned to actual physical RAM. + */ + peakWorkingSetSize: number; + /** + * The amount of memory not shared by other processes, such as JS heap or HTML content. + */ + privateBytes: number; + /** + * The amount of memory shared between processes, typically memory consumed by the Electron code itself. + */ + sharedBytes: number; + } + + interface SystemMemoryInfo { + /** + * The total amount of physical memory available to the system. + */ + total: number; + /** + * The total amount of memory not being used by applications or disk cache. + */ + free: number; + /** + * The total amount of swap memory available to the system. + */ + swapTotal: number; + /** + * The free amount of swap memory available to the system. + */ + swapFree: number; } }