diff --git a/docs/api/app.md b/docs/api/app.md index cb19b49b7c18..36ebab21bedf 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -6,7 +6,7 @@ The following example shows how to quit the application when the last window is closed: ```javascript -const { app } = require('electron'); +const {app} = require('electron'); app.on('window-all-closed', () => { app.quit(); }); @@ -175,8 +175,8 @@ certificate you should prevent the default behavior with `event.preventDefault()` and call `callback(true)`. ```javascript -app.on('certificate-error', function(event, webContents, url, error, certificate, callback) { - if (url == "https://github.com") { +app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { + if (url === 'https://github.com') { // Verification logic. event.preventDefault(); callback(true); @@ -206,10 +206,10 @@ and `callback` needs to be called with an entry filtered from the list. Using certificate from the store. ```javascript -app.on('select-client-certificate', function(event, webContents, url, list, callback) { +app.on('select-client-certificate', (event, webContents, url, list, callback) => { event.preventDefault(); callback(list[0]); -}) +}); ``` ### Event: 'login' @@ -240,7 +240,7 @@ should prevent the default behavior with `event.preventDefault()` and call app.on('login', (event, webContents, request, authInfo, callback) => { event.preventDefault(); callback('username', 'secret'); -}) +}); ``` ### Event: 'gpu-process-crashed' diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index d4ed6c03322c..143c0179428b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -4,12 +4,12 @@ ```javascript // In the main process. -const { BrowserWindow } = require('electron'); +const {BrowserWindow} = require('electron'); // Or in the renderer process. -const { BrowserWindow } = require('electron').remote; +const {BrowserWindow} = require('electron').remote; -let win = new BrowserWindow({ width: 800, height: 600, show: false }); +let win = new BrowserWindow({width: 800, height: 600, show: false}); win.on('closed', () => { win = null; }); @@ -220,7 +220,7 @@ reloaded. In Electron, returning an empty string or `false` would cancel the close. For example: ```javascript -window.onbeforeunload = function(e) { +window.onbeforeunload = (e) => { console.log('I do not want to be closed'); // Unlike usual browsers, in which a string should be returned and the user is @@ -392,7 +392,7 @@ Objects created with `new BrowserWindow` have the following properties: ```javascript // In this example `win` is our instance -var win = new BrowserWindow({ width: 800, height: 600 }); +let win = new BrowserWindow({width: 800, height: 600}); ``` ### `win.webContents` @@ -689,7 +689,7 @@ attached just below the window frame, but you may want to display them beneath a HTML-rendered toolbar. For example: ```javascript -var toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); +let toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); win.setSheetOffset(toolbarRect.height); ``` diff --git a/docs/api/chrome-command-line-switches.md b/docs/api/chrome-command-line-switches.md index e51ffe5e2eb4..751d9295614f 100644 --- a/docs/api/chrome-command-line-switches.md +++ b/docs/api/chrome-command-line-switches.md @@ -7,7 +7,7 @@ your app's main script before the [ready][ready] event of the [app][app] module is emitted: ```javascript -const { app } = require('electron'); +const {app} = require('electron'); app.commandLine.appendSwitch('remote-debugging-port', '8315'); app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1'); @@ -109,7 +109,7 @@ Enables net log events to be saved and writes them to `path`. ## --ssl-version-fallback-min=`version` -Sets the minimum SSL/TLS version ("tls1", "tls1.1" or "tls1.2") that TLS +Sets the minimum SSL/TLS version (`tls1`, `tls1.1` or `tls1.2`) that TLS fallback will accept. ## --cipher-suite-blacklist=`cipher_suites` diff --git a/docs/api/clipboard.md b/docs/api/clipboard.md index 38bd86594221..9a8c73043233 100644 --- a/docs/api/clipboard.md +++ b/docs/api/clipboard.md @@ -5,7 +5,7 @@ The following example shows how to write a string to the clipboard: ```javascript -const { clipboard } = require('electron'); +const {clipboard} = require('electron'); clipboard.writeText('Example String'); ``` diff --git a/docs/api/content-tracing.md b/docs/api/content-tracing.md index e6f6b7a0d2d8..d269d602ef59 100644 --- a/docs/api/content-tracing.md +++ b/docs/api/content-tracing.md @@ -8,14 +8,14 @@ This module does not include a web interface so you need to open result. ```javascript -const { contentTracing } = require('electron'); +const {contentTracing} = require('electron'); const options = { categoryFilter: '*', traceOptions: 'record-until-full,enable-sampling' -} +}; -contentTracing.startRecording(options, function() { +contentTracing.startRecording(options, () => { console.log('Tracing started'); setTimeout(() => { diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index 4e4b49df0f7e..6575bbea7656 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -6,7 +6,7 @@ The following is an example of automatically submitting a crash report to a remote server: ```javascript -const { crashReporter } = require('electron'); +const {crashReporter} = require('electron'); crashReporter.start({ productName: 'YourName', diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 9c6d220112b5..a72539a7a283 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -5,12 +5,12 @@ microphone, camera, or screen. ```javascript // In the renderer process. -var { desktopCapturer } = require('electron'); +const {desktopCapturer} = require('electron'); desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => { if (error) throw error; - for (var i = 0; i < sources.length; ++i) { - if (sources[i].name == "Electron") { + for (let i = 0; i < sources.length; ++i) { + if (sources[i].name === 'Electron') { navigator.webkitGetUserMedia({ audio: false, video: { diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 84aac7c63bf2..0ba41df96adf 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -5,16 +5,17 @@ An example of showing a dialog to select multiple files and directories: ```javascript -var win = ...; // BrowserWindow in which to show the dialog -const { dialog } = require('electron'); -console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]})); +let win = ...; // BrowserWindow in which to show the dialog +const {dialog} = require('electron'); + +console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']})); ``` The Dialog is opened from Electron's main thread. If you want to use the dialog object from a renderer process, remember to access it using the remote: ```javascript -const { dialog } = require('electron').remote; +const {dialog} = require('electron').remote; ``` ## Methods @@ -42,10 +43,10 @@ selected when you want to limit the user to a specific type. For example: ```javascript { filters: [ - { name: 'Images', extensions: ['jpg', 'png', 'gif'] }, - { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] }, - { name: 'Custom File Type', extensions: ['as'] }, - { name: 'All Files', extensions: ['*'] } + {name: 'Images', extensions: ['jpg', 'png', 'gif']}, + {name: 'Movies', extensions: ['mkv', 'avi', 'mp4']}, + {name: 'Custom File Type', extensions: ['as']}, + {name: 'All Files', extensions: ['*']} ] } ``` diff --git a/docs/api/download-item.md b/docs/api/download-item.md index 6d15176aa09c..14d1931e4468 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -18,10 +18,10 @@ win.webContents.session.on('will-download', (event, item, webContents) => { console.log('Received bytes: ' + item.getReceivedBytes()); }); item.on('done', (e, state) => { - if (state === "completed") { - console.log("Download successfully"); + if (state === 'completed') { + console.log('Download successfully'); } else { - console.log("Download is cancelled or interrupted that can't be resumed"); + console.log('Download is cancelled or interrupted that can\'t be resumed'); } }); }); diff --git a/docs/api/frameless-window.md b/docs/api/frameless-window.md index 733baa5c902b..f3017037210d 100644 --- a/docs/api/frameless-window.md +++ b/docs/api/frameless-window.md @@ -14,8 +14,8 @@ To create a frameless window, you need to set `frame` to `false` in ```javascript -const { BrowserWindow } = require('electron'); -let win = new BrowserWindow({ width: 800, height: 600, frame: false }); +const {BrowserWindow} = require('electron'); +let win = new BrowserWindow({width: 800, height: 600, frame: false}); ``` ### Alternatives on OS X @@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions. You can do so by specifying the new `titleBarStyle` option: ```javascript -let win = new BrowserWindow({ 'titleBarStyle': 'hidden' }); +let win = new BrowserWindow({titleBarStyle: 'hidden'}); ``` ## Transparent window @@ -37,7 +37,7 @@ By setting the `transparent` option to `true`, you can also make the frameless window transparent: ```javascript -let win = new BrowserWindow({ transparent: true, frame: false }); +let win = new BrowserWindow({transparent: true, frame: false}); ``` ### Limitations diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 6acb5201066f..d9488a7b7fd9 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -11,12 +11,11 @@ not have the keyboard focus. You should not use this module until the `ready` event of the app module is emitted. ```javascript -const electron = require('electron'); -const { app, globalShortcut } = electron; +const {app, globalShortcut} = require('electron'); app.on('ready', () => { // Register a 'CommandOrControl+X' shortcut listener. - const ret = globalShortcut.register('CommandOrControl+X', function() { + const ret = globalShortcut.register('CommandOrControl+X', () => { console.log('CommandOrControl+X is pressed'); }); diff --git a/docs/api/ipc-main.md b/docs/api/ipc-main.md index e40e4408c077..0b7acbfefa0c 100644 --- a/docs/api/ipc-main.md +++ b/docs/api/ipc-main.md @@ -23,7 +23,7 @@ processes: ```javascript // In main process. -const { ipcMain } = require('electron'); +const {ipcMain} = require('electron'); ipcMain.on('asynchronous-message', (event, arg) => { console.log(arg); // prints "ping" event.sender.send('asynchronous-reply', 'pong'); @@ -37,7 +37,7 @@ ipcMain.on('synchronous-message', (event, arg) => { ```javascript // In renderer process (web page). -const { ipcRenderer } = require('electron'); +const {ipcRenderer} = require('electron'); console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong" ipcRenderer.on('asynchronous-reply', (event, arg) => { diff --git a/docs/api/menu.md b/docs/api/menu.md index a80ea8723129..2b555fd83d60 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -15,13 +15,13 @@ the user right clicks the page: ```html @@ -53,7 +53,7 @@ As of 0.37, you can use built-in modules. ```javascript -const { app, BrowserWindow } = require('electron'); +const {app, BrowserWindow} = require('electron'); ``` If you need the entire `electron` module, you can require it and then using @@ -61,7 +61,7 @@ destructuring to access the individual modules from `electron`. ```javascript const electron = require('electron'); -const { app, BrowserWindow } = electron; +const {app, BrowserWindow} = electron; ``` This is equivalent to the following code: @@ -88,7 +88,7 @@ process.env.ELECTRON_HIDE_INTERNAL_MODULES = 'true' Or call the `hideInternalModules` API: ```javascript -require('electron').hideInternalModules() +require('electron').hideInternalModules(); ``` [gui]: https://en.wikipedia.org/wiki/Graphical_user_interface diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index cafb1d3745f3..df7ef89e65c4 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -56,7 +56,7 @@ An example of using it to determine if you should create a transparent window or not (transparent windows won't work correctly when DWM composition is disabled): ```javascript -let browserOptions = { width: 1000, height: 800 }; +let browserOptions = {width: 1000, height: 800}; // Make the window transparent only if the platform supports it. if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) { diff --git a/docs/api/tray.md b/docs/api/tray.md index eaf3f6c42bbd..3fa6f606e90a 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -3,19 +3,16 @@ > Add icons and context menus to the system's notification area. ```javascript -const electron = require('electron'); -const app = electron.app; -const Menu = electron.Menu; -const Tray = electron.Tray; +const {app, Menu, Tray} = require('electron'); let appIcon = null; app.on('ready', () => { appIcon = new Tray('/path/to/my/icon'); const contextMenu = Menu.buildFromTemplate([ - { label: 'Item1', type: 'radio' }, - { label: 'Item2', type: 'radio' }, - { label: 'Item3', type: 'radio', checked: true }, - { label: 'Item4', type: 'radio' } + {label: 'Item1', type: 'radio'}, + {label: 'Item2', type: 'radio'}, + {label: 'Item3', type: 'radio', checked: true}, + {label: 'Item4', type: 'radio'} ]); appIcon.setToolTip('This is my application.'); appIcon.setContextMenu(contextMenu); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 3800388b56e3..47e2e4c34911 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -9,10 +9,10 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the `webContents` object: ```javascript -const { BrowserWindow } = require('electron'); +const {BrowserWindow} = require('electron'); let win = new BrowserWindow({width: 800, height: 1500}); -win.loadURL("http://github.com"); +win.loadURL('http://github.com'); let webContents = win.webContents; ``` @@ -384,8 +384,8 @@ e.g. the `http://` or `file://`. If the load should bypass http cache then use the `pragma` header to achieve it. ```javascript -const options = {"extraHeaders" : "pragma: no-cache\n"} -webContents.loadURL(url, options) +const options = {extraHeaders: 'pragma: no-cache\n'}; +webContents.loadURL(url, options); ``` ### `webContents.downloadURL(url)` @@ -401,7 +401,7 @@ Returns URL of the current web page. ```javascript let win = new BrowserWindow({width: 800, height: 600}); -win.loadURL("http://github.com"); +win.loadURL('http://github.com'); let currentURL = win.webContents.getURL(); ``` @@ -603,12 +603,12 @@ the request can be obtained by subscribing to Stops any `findInPage` request for the `webContents` with the provided `action`. ```javascript -webContents.on('found-in-page', function(event, result) { +webContents.on('found-in-page', (event, result) => { if (result.finalUpdate) - webContents.stopFindInPage("clearSelection"); + webContents.stopFindInPage('clearSelection'); }); -const requestId = webContents.findInPage("api"); +const requestId = webContents.findInPage('api'); ``` ### `webContents.hasServiceWorker(callback)` @@ -673,7 +673,7 @@ By default, an empty `options` will be regarded as: ``` ```javascript -const { BrowserWindow } = require('electron'); +const {BrowserWindow} = require('electron'); const fs = require('fs'); let win = new BrowserWindow({width: 800, height: 600}); @@ -700,8 +700,8 @@ Adds the specified path to DevTools workspace. Must be used after DevTools creation: ```javascript -mainWindow.webContents.on('devtools-opened', function() { - mainWindow.webContents.addWorkSpace(__dirname); +win.webContents.on('devtools-opened', () => { + win.webContents.addWorkSpace(__dirname); }); ``` @@ -763,13 +763,13 @@ An example of sending messages from the main process to the renderer process: ```javascript // In the main process. -let mainWindow = null; +let win = null; app.on('ready', () => { - mainWindow = new BrowserWindow({width: 800, height: 600}); - mainWindow.loadURL(`file://${__dirname}/index.html`); - mainWindow.webContents.on('did-finish-load', () => { - mainWindow.webContents.send('ping', 'whoooooooh!'); + win = new BrowserWindow({width: 800, height: 600}); + win.loadURL(`file://${__dirname}/index.html`); + win.webContents.on('did-finish-load', () => { + win.webContents.send('ping', 'whoooooooh!'); }); }); ``` @@ -887,7 +887,7 @@ End subscribing for frame presentation events. * `HTMLOnly` - Save only the HTML of the page. * `HTMLComplete` - Save complete-html page. * `MHTML` - Save complete-html page as MHTML. -* `callback` Function - `function(error) {}`. +* `callback` Function - `(error) => {}`. * `error` Error Returns true if the process of saving page has been initiated successfully. @@ -898,7 +898,7 @@ win.loadURL('https://github.com'); win.webContents.on('did-finish-load', () => { win.webContents.savePage('/tmp/test.html', 'HTMLComplete', (error) => { if (!error) - console.log("Save page successfully"); + console.log('Save page successfully'); }); }); ``` @@ -928,23 +928,23 @@ Debugger API serves as an alternate transport for [remote debugging protocol][rd ```javascript try { - win.webContents.debugger.attach("1.1"); + win.webContents.debugger.attach('1.1'); } catch(err) { - console.log("Debugger attach failed : ", err); + console.log('Debugger attach failed : ', err); }; win.webContents.debugger.on('detach', (event, reason) => { - console.log("Debugger detached due to : ", reason); + console.log('Debugger detached due to : ', reason); }); win.webContents.debugger.on('message', (event, method, params) => { - if (method === "Network.requestWillBeSent") { - if (params.request.url === "https://www.github.com") + if (method === 'Network.requestWillBeSent') { + if (params.request.url === 'https://www.github.com') win.webContents.debugger.detach(); } -}) +}); -win.webContents.debugger.sendCommand("Network.enable"); +win.webContents.debugger.sendCommand('Network.enable'); ``` #### `webContents.debugger.attach([protocolVersion])` diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index dcd595d3d973..de5a21db3db9 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -5,7 +5,7 @@ An example of zooming current page to 200%. ```javascript -const { webFrame } = require('electron'); +const {webFrame} = require('electron'); webFrame.setZoomFactor(2); ``` @@ -58,8 +58,8 @@ whether the word passed is correctly spelled. An example of using [node-spellchecker][spellchecker] as provider: ```javascript -webFrame.setSpellCheckProvider("en-US", true, { - spellCheck: function(text) { +webFrame.setSpellCheckProvider('en-US', true, { + spellCheck(text) { return !(require('spellchecker').isMisspelled(text)); } }); diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index a7410e146ae7..aa564b79e1fc 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -37,15 +37,15 @@ and displays a "loading..." message during the load time: const loadstart = () => { indicator.innerText = 'loading...'; - } + }; const loadstop = () => { indicator.innerText = ''; - } + }; webview.addEventListener('did-start-loading', loadstart); webview.addEventListener('did-stop-loading', loadstop); - } + }; ``` @@ -213,7 +213,7 @@ The `webview` tag has the following methods: **Example** ```javascript -webview.addEventListener("dom-ready", () => { +webview.addEventListener('dom-ready', () => { webview.openDevTools(); }); ``` @@ -600,7 +600,7 @@ The following example code forwards all log messages to the embedder's console without regard for log level or other properties. ```javascript -webview.addEventListener('console-message', function(e) { +webview.addEventListener('console-message', (e) => { console.log('Guest page logged a message:', e.message); }); ``` @@ -620,12 +620,12 @@ Fired when a result is available for [`webview.findInPage`](web-view-tag.md#webviewtagfindinpage) request. ```javascript -webview.addEventListener('found-in-page', function(e) { +webview.addEventListener('found-in-page', (e) => { if (e.result.finalUpdate) - webview.stopFindInPage("keepSelection"); + webview.stopFindInPage('keepSelection'); }); -const rquestId = webview.findInPage("test"); +const rquestId = webview.findInPage('test'); ``` ### Event: 'new-window' @@ -644,7 +644,7 @@ Fired when the guest page attempts to open a new browser window. The following example code opens the new url in system's default browser. ```javascript -const { shell } = require('electron'); +const {shell} = require('electron'); webview.addEventListener('new-window', (e) => { const protocol = require('url').parse(e.url).protocol; @@ -732,7 +732,7 @@ webview.send('ping'); ```javascript // In guest page. -var { ipcRenderer } = require('electron'); +const {ipcRenderer} = require('electron'); ipcRenderer.on('ping', () => { ipcRenderer.sendToHost('pong'); }); diff --git a/docs/faq/electron-faq.md b/docs/faq/electron-faq.md index 68714d69ada7..239b4411d42e 100644 --- a/docs/faq/electron-faq.md +++ b/docs/faq/electron-faq.md @@ -65,7 +65,7 @@ code from this: ```javascript app.on('ready', () => { const tray = new Tray('/path/to/icon.png'); -}) +}); ``` to this: @@ -74,7 +74,7 @@ to this: let tray = null; app.on('ready', () => { tray = new Tray('/path/to/icon.png'); -}) +}); ``` ## I can not use jQuery/RequireJS/Meteor/AngularJS in Electron. @@ -87,7 +87,7 @@ To solve this, you can turn off node integration in Electron: ```javascript // In the main process. -let mainWindow = new BrowserWindow({ +let win = new BrowserWindow({ webPreferences: { nodeIntegration: false } diff --git a/docs/styleguide.md b/docs/styleguide.md index cd68414ac240..a34889d2ca34 100644 --- a/docs/styleguide.md +++ b/docs/styleguide.md @@ -93,6 +93,6 @@ this event it might look something like this: ```javascript Alarm.on('wake-up', (time) => { - console.log(time) -}) + console.log(time); +}); ``` diff --git a/docs/tutorial/application-packaging.md b/docs/tutorial/application-packaging.md index 257119a573a6..de61e8bd5e97 100644 --- a/docs/tutorial/application-packaging.md +++ b/docs/tutorial/application-packaging.md @@ -71,7 +71,7 @@ require('/path/to/example.asar/dir/module.js'); You can also display a web page in an `asar` archive with `BrowserWindow`: ```javascript -const { BrowserWindow } = require('electron'); +const {BrowserWindow} = require('electron'); let win = new BrowserWindow({width: 800, height: 600}); win.loadURL('file:///path/to/example.asar/static/index.html'); ``` @@ -85,7 +85,7 @@ For example, to get a file with `$.get`: ```html