From 08fa9d6083918e7e0687f51e1e42f65cfe516c71 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 23 Nov 2016 23:28:13 +0900 Subject: [PATCH 1/4] electron: add missing APIs added in 1.4.5 --- electron/github-electron-main-tests.ts | 33 +++++++++++-------- electron/github-electron-renderer-tests.ts | 4 +++ electron/index.d.ts | 38 ++++++++++++++++++++-- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/electron/github-electron-main-tests.ts b/electron/github-electron-main-tests.ts index f333e86ec7..e5e0795025 100644 --- a/electron/github-electron-main-tests.ts +++ b/electron/github-electron-main-tests.ts @@ -313,6 +313,8 @@ var window = new BrowserWindow(); window.setProgressBar(0.5); window.setRepresentedFilename('/etc/passwd'); window.setDocumentEdited(true); +window.previewFile('/path/to/file'); +window.previewFile('/path/to/file', 'Displayed Name'); // Online/Offline Event Detection // https://github.com/atom/electron/blob/master/docs/tutorial/online-offline-events.md @@ -869,20 +871,25 @@ app.on('ready', () => { // clipboard // https://github.com/atom/electron/blob/master/docs/api/clipboard.md -clipboard.writeText('Example String'); -clipboard.writeText('Example String', 'selection'); -clipboard.writeBookmark('foo', 'http://example.com'); -clipboard.writeBookmark('foo', 'http://example.com', 'selection'); -console.log(clipboard.readText('selection')); -console.log(clipboard.availableFormats()); -console.log(clipboard.readBookmark().title); -clipboard.clear(); +{ + let str: string; + clipboard.writeText('Example String'); + clipboard.writeText('Example String', 'selection'); + clipboard.writeBookmark('foo', 'http://example.com'); + clipboard.writeBookmark('foo', 'http://example.com', 'selection'); + clipboard.writeFindText('foo'); + str = clipboard.readText('selection'); + str = clipboard.readFindText(); + console.log(clipboard.availableFormats()); + console.log(clipboard.readBookmark().title); + clipboard.clear(); -clipboard.write({ - html: '', - text: 'Hello World!', - image: clipboard.readImage() -}); + clipboard.write({ + html: '', + text: 'Hello World!', + image: clipboard.readImage() + }); +} // crash-reporter // https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md diff --git a/electron/github-electron-renderer-tests.ts b/electron/github-electron-renderer-tests.ts index 87d9a4abf7..9de01360ea 100644 --- a/electron/github-electron-renderer-tests.ts +++ b/electron/github-electron-renderer-tests.ts @@ -68,6 +68,10 @@ webFrame.setSpellCheckProvider('en-US', true, { webFrame.registerURLSchemeAsSecure('app'); webFrame.registerURLSchemeAsBypassingCSP('app'); webFrame.registerURLSchemeAsPrivileged('app'); +webFrame.registerURLSchemeAsPrivileged('app', { + secure: true, + supportFetchAPI: true, +}); webFrame.insertText('text'); diff --git a/electron/index.d.ts b/electron/index.d.ts index d55b47df4c..d6c9848137 100644 --- a/electron/index.d.ts +++ b/electron/index.d.ts @@ -1023,6 +1023,14 @@ declare namespace Electron { * Note: This API is available only on macOS. */ setAspectRatio(aspectRatio: number, extraSize?: Size): void; + /** + * Uses Quick Look to preview a file at a given path. + * + * @param path The absolute path to the file to preview with QuickLook. + * @param displayName The name of the file to display on the Quick Look modal view. + * Note: This API is available only on macOS. + */ + previewFile(path: string, displayName?: string): void; /** * Resizes and moves the window to width, height, x, y. */ @@ -1861,6 +1869,20 @@ declare namespace Electron { * Note: This API is available on macOS and Windows. */ writeBookmark(title: string, url: string, type?: ClipboardType): void; + /** + * The text on the find pasteboard. This method uses synchronous IPC when called from the renderer process. + * The cached value is reread from the find pasteboard whenever the application is activated. + * + * Note: This API is available on macOS. + */ + readFindText(): string; + /** + * Writes the text into the find pasteboard as plain text. + * This method uses synchronous IPC when called from the renderer process. + * + * Note: This API is available on macOS. + */ + writeFindText(text: string): void; } type ClipboardType = '' | 'selection'; @@ -5144,7 +5166,7 @@ declare namespace Electron { * Registers the scheme as secure, bypasses content security policy for resources, * allows registering ServiceWorker and supports fetch API. */ - registerURLSchemeAsPrivileged(scheme: string): void; + registerURLSchemeAsPrivileged(scheme: string, options?: RegisterURLSchemeOptions): void; /** * Inserts text to the focused element. */ @@ -5184,6 +5206,14 @@ declare namespace Electron { size: number; } + interface RegisterURLSchemeOptions { + secure?: boolean; + bypassCSP?: boolean; + allowServiceWorkers?: boolean; + supportFetchAPI?: boolean; + corsEnabled?: boolean; + } + // https://github.com/electron/electron/blob/master/docs/api/web-view-tag.md /** @@ -5257,6 +5287,10 @@ declare namespace Electron { * If "on", the guest page will be allowed to open new windows. */ allowpopups: string; + /** + * A list of strings which specifies the web preferences to be set on the webview, separated by ,. + */ + webpreferences: string; /** * A list of strings which specifies the blink features to be enabled separated by ,. */ @@ -5377,7 +5411,7 @@ declare namespace Electron { closeDevTools(): void; /** * @returns Whether guest page has a DevTools window attached. - */ + isDevToolsOpened(): boolean; /** * @returns Whether DevTools window of guest page is focused. From 099a2b6dedd850c281c97c30a02cfe63f08cbfa7 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 23 Nov 2016 23:34:40 +0900 Subject: [PATCH 2/4] electron: Support Electron 1.4.6 --- electron/github-electron-main-tests.ts | 2 +- electron/github-electron-renderer-tests.ts | 2 +- electron/index.d.ts | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/electron/github-electron-main-tests.ts b/electron/github-electron-main-tests.ts index e5e0795025..40cb34501c 100644 --- a/electron/github-electron-main-tests.ts +++ b/electron/github-electron-main-tests.ts @@ -93,7 +93,7 @@ app.on('ready', () => { mainWindow.webContents.printToPDF({}, (err, data) => {}); - mainWindow.webContents.executeJavaScript('return true;'); + mainWindow.webContents.executeJavaScript('return true;').then((v: boolean) => console.log(v)); mainWindow.webContents.executeJavaScript('return true;', true); mainWindow.webContents.executeJavaScript('return true;', true, (result: boolean) => console.log(result)); mainWindow.webContents.insertText('blah, blah, blah'); diff --git a/electron/github-electron-renderer-tests.ts b/electron/github-electron-renderer-tests.ts index 9de01360ea..a7e3be9836 100644 --- a/electron/github-electron-renderer-tests.ts +++ b/electron/github-electron-renderer-tests.ts @@ -77,7 +77,7 @@ webFrame.insertText('text'); webFrame.executeJavaScript('JSON.stringify({})', false, (result) => { console.log(result); -}); +}).then((result: string) => console.log('OK:' + result)); console.log(webFrame.getResourceUsage()); webFrame.clearCache(); diff --git a/electron/index.d.ts b/electron/index.d.ts index d6c9848137..0cfcd50636 100644 --- a/electron/index.d.ts +++ b/electron/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Electron v1.4.5 +// Type definitions for Electron v1.4.6 // Project: http://electron.atom.io/ // Definitions by: jedmao , rhysd , Milan Burda , aliib // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -4415,8 +4415,10 @@ declare namespace Electron { /** * Evaluates code in page. * @param code Code to evaluate. + * + * @returns Promise */ - executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): void; + executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): Promise; /** * Mute the audio on the current web page. */ @@ -5176,8 +5178,10 @@ declare namespace Electron { * In the browser window some HTML APIs like `requestFullScreen` can only be * invoked by a gesture from the user. Setting `userGesture` to `true` will remove * this limitation. + * + * @returns Promise */ - executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): void; + executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): Promise; /** * @returns Object describing usage information of Blink’s internal memory caches. */ @@ -5399,8 +5403,10 @@ declare namespace Electron { /** * Evaluates code in page. If userGesture is set, it will create the user gesture context in the page. * HTML APIs like requestFullScreen, which require user action, can take advantage of this option for automation. + * + * @returns Promise */ - executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): void; + executeJavaScript(code: string, userGesture?: boolean, callback?: (result: any) => void): Promise; /** * Opens a DevTools window for guest page. */ From e8b9c59a518b6294f6308f469e1b8a425f7124e4 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 23 Nov 2016 23:56:19 +0900 Subject: [PATCH 3/4] support Electron 1.4.7 --- electron/github-electron-main-tests.ts | 6 +- electron/index.d.ts | 105 ++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/electron/github-electron-main-tests.ts b/electron/github-electron-main-tests.ts index 40cb34501c..c62a931203 100644 --- a/electron/github-electron-main-tests.ts +++ b/electron/github-electron-main-tests.ts @@ -63,6 +63,7 @@ app.on('ready', () => { mainWindow.loadURL(`file://${__dirname}/index.html`); mainWindow.loadURL('file://foo/bar', {userAgent: 'cool-agent', httpReferrer: 'greateRefferer'}); mainWindow.webContents.loadURL('file://foo/bar', {userAgent: 'cool-agent', httpReferrer: 'greateRefferer'}); + mainWindow.webContents.loadURL('file://foo/bar', {userAgent: 'cool-agent', httpReferrer: 'greateRefferer', postData: [{type: 'blob', blobUUID: 'hogefuga'}]}); mainWindow.webContents.openDevTools(); mainWindow.webContents.toggleDevTools(); @@ -315,6 +316,8 @@ window.setRepresentedFilename('/etc/passwd'); window.setDocumentEdited(true); window.previewFile('/path/to/file'); window.previewFile('/path/to/file', 'Displayed Name'); +window.setVibrancy('light'); +window.setVibrancy('titlebar'); // Online/Offline Event Detection // https://github.com/atom/electron/blob/master/docs/tutorial/online-offline-events.md @@ -322,7 +325,7 @@ window.previewFile('/path/to/file', 'Displayed Name'); var onlineStatusWindow: Electron.BrowserWindow; app.on('ready', () => { - onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false }); + onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false, vibrancy: 'sidebar' }); onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`); }); app.on('accessibility-support-changed', (_, enabled) => console.log('accessibility: ' + enabled)); @@ -1058,6 +1061,7 @@ session.defaultSession.enableNetworkEmulation({ session.defaultSession.setCertificateVerifyProc((hostname, cert, callback) => { callback((hostname === 'github.com') ? true : false); + console.log(cert.issuer.commonName); }); session.defaultSession.setPermissionRequestHandler(function(webContents, permission, callback) { diff --git a/electron/index.d.ts b/electron/index.d.ts index 0cfcd50636..723a597983 100644 --- a/electron/index.d.ts +++ b/electron/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Electron v1.4.6 +// Type definitions for Electron v1.4.7 // Project: http://electron.atom.io/ // Definitions by: jedmao , rhysd , Milan Burda , aliib // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -42,6 +42,8 @@ declare namespace Electron { // https://github.com/electron/electron/blob/master/docs/api/app.md + type VibrancyType = 'appearance-based' | 'light' | 'dark' | 'titlebar' | 'selection' | 'menu' | 'popover' | 'sidebar' | 'medium-light' | 'ultra-dark'; + /** * The app module is responsible for controlling the application's lifecycle. */ @@ -1391,6 +1393,13 @@ declare namespace Electron { * @returns All child windows. */ getChildWindows(): BrowserWindow[]; + /** + * Adds a vibrancy effect to the browser window. Passing null or + * an empty string will remove the vibrancy effect on the window. + * + * Note: This API is available only on macOS. + */ + setVibrancy(type: VibrancyType): void; } type WindowLevel = 'normal' | 'floating' | 'torn-off-menu' | 'modal-panel' | 'main-menu' | 'status' | 'pop-up-menu' | 'screen-saver' | 'dock'; @@ -1780,6 +1789,10 @@ declare namespace Electron { * Use WS_THICKFRAME style for frameless windows on Windows */ thickFrame?: boolean; + /** + * Add a type of vibrancy effect to the window, only on macOS + */ + vibrancy?: VibrancyType; /** * Settings of web page’s features. */ @@ -3304,7 +3317,7 @@ declare namespace Electron { * * Calling setCertificateVerifyProc(null) will revert back to default certificate verify proc. */ - setCertificateVerifyProc(proc: (hostname: string, cert: Certificate, callback: (accepted: boolean) => void) => void): void; + setCertificateVerifyProc(proc: ((hostname: string, cert: Certificate, callback: (accepted: boolean) => void) => void) | null): void; /** * Sets the handler which can be used to respond to permission requests for the session. */ @@ -4871,6 +4884,55 @@ declare namespace Electron { * Extra headers separated by "\n" */ extraHeaders?: string; + /** + * POST data + */ + postData?: (UploadRawData | UploadFileSystem | UploadBlob)[]; + } + + interface UploadRawData { + /** + * rawData + */ + type: 'rawData'; + /** + * Data to be uploaded. + */ + bytes: Buffer; + } + + interface UploadFileSystem { + /** + * fileSystem + */ + type: 'fileSystem'; + /** + * FileSystem url to read data for upload. + */ + fileSystemURL: string; + /** + * Defaults to 0. + */ + offset: number; + /** + * Number of bytes to read from offset. Defaults to 0. + */ + length: number; + /** + * Last Modification time in number of seconds sine the UNIX epoch. + */ + modificationTime: number; + } + + interface UploadBlob { + /** + * blob + */ + type: 'blob'; + /** + * UUID of blob data to upload. + */ + blobUUID: string; } interface PrintOptions { @@ -4922,10 +4984,22 @@ declare namespace Electron { * PEM encoded data. */ data: string; + /** + * Issuer principal + */ + issuer: CertificatePrincipal; /** * Issuer's Common Name. */ issuerName: string; + /** + * Issuer certificate (if not self-signed) + */ + issuerCert: Certificate; + /** + * Subject principal + */ + subject: CertificatePrincipal; /** * Subject's Common Name. */ @@ -4948,6 +5022,33 @@ declare namespace Electron { fingerprint: string; } + interface CertificatePrincipal { + /** + * Common Name + */ + commonName: string; + /** + * Organization names + */ + organizations: string[]; + /** + * Organization Unit names + */ + organizationUnits: string[]; + /** + * Locality + */ + locality: string; + /** + * State or province + */ + state: string; + /** + * Country or region + */ + country: string; + } + interface LoginRequest { method: string; url: string; From f6b3c4d5ba937de04df9cac3b95ed1515d09c2f9 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 24 Nov 2016 00:05:43 +0900 Subject: [PATCH 4/4] electron: support Electron 1.4.8 --- electron/github-electron-main-tests.ts | 3 +++ electron/github-electron-renderer-tests.ts | 3 ++- electron/index.d.ts | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/electron/github-electron-main-tests.ts b/electron/github-electron-main-tests.ts index c62a931203..ce5bbf8e2e 100644 --- a/electron/github-electron-main-tests.ts +++ b/electron/github-electron-main-tests.ts @@ -81,6 +81,9 @@ app.on('ready', () => { mainWindow = null; }); + mainWindow.webContents.setVisualZoomLevelLimits(50, 200); + mainWindow.webContents.setLayoutZoomLevelLimits(50, 200); + mainWindow.webContents.print({silent: true, printBackground: false}); mainWindow.webContents.print(); diff --git a/electron/github-electron-renderer-tests.ts b/electron/github-electron-renderer-tests.ts index a7e3be9836..20dca2d07e 100644 --- a/electron/github-electron-renderer-tests.ts +++ b/electron/github-electron-renderer-tests.ts @@ -57,7 +57,8 @@ console.log(webFrame.getZoomFactor()); webFrame.setZoomLevel(200); console.log(webFrame.getZoomLevel()); -webFrame.setZoomLevelLimits(50, 200); +webFrame.setVisualZoomLevelLimits(50, 200); +webFrame.setLayoutZoomLevelLimits(50, 200); webFrame.setSpellCheckProvider('en-US', true, { spellCheck: text => { diff --git a/electron/index.d.ts b/electron/index.d.ts index 723a597983..00a098ef67 100644 --- a/electron/index.d.ts +++ b/electron/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Electron v1.4.7 +// Type definitions for Electron v1.4.8 // Project: http://electron.atom.io/ // Definitions by: jedmao , rhysd , Milan Burda , aliib // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -2490,7 +2490,7 @@ declare namespace Electron { } type MenuItemType = 'normal' | 'separator' | 'submenu' | 'checkbox' | 'radio'; - type MenuItemRole = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'pasteandmatchstyle' | 'selectall' | 'delete' | 'minimize' | 'close' | 'quit' | 'togglefullscreen' | 'resetzoom' | 'zoomin' | 'zoomout'; + type MenuItemRole = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'pasteandmatchstyle' | 'selectall' | 'delete' | 'minimize' | 'close' | 'quit' | 'togglefullscreen' | 'resetzoom' | 'zoomin' | 'zoomout' | 'reload' | 'toggledevtools'; type MenuItemRoleMac = 'about' | 'hide' | 'hideothers' | 'unhide' | 'startspeaking' | 'stopspeaking' | 'front' | 'zoom' | 'window' | 'help' | 'services'; interface MenuItemOptions { @@ -4462,7 +4462,11 @@ declare namespace Electron { /** * Sets the maximum and minimum zoom level. */ - setZoomLevelLimits(minimumLevel: number, maximumLevel: number): void; + setVisualZoomLevelLimits(minimumLevel: number, maximumLevel: number): void; + /** + * Sets the maximum and minimum layout-based (i.e. non-visual) zoom level. + */ + setLayoutZoomLevelLimits(minimumLevel: number, maximumLevel: number): void; /** * Executes the editing command undo in web page. */ @@ -5245,7 +5249,11 @@ declare namespace Electron { /** * Sets the maximum and minimum zoom level. */ - setZoomLevelLimits(minimumLevel: number, maximumLevel: number): void; + setVisualZoomLevelLimits(minimumLevel: number, maximumLevel: number): void; + /** + * Sets the maximum and minimum layout-based (i.e. non-visual) zoom level. + */ + setLayoutZoomLevelLimits(minimumLevel: number, maximumLevel: number): void; /** * Sets a provider for spell checking in input fields and text areas. */