📝 Fix code style issue
* Change `var` to `let`. * Change `function() {}` to `() => {}`. * Use shorthand function syntax on object notation. * Remove spaces between object notation brackets. * Small fixes.
This commit is contained in:
parent
139a4f984a
commit
f1b184ef78
23 changed files with 64 additions and 67 deletions
|
@ -176,7 +176,7 @@ certificate you should prevent the default behavior with
|
||||||
`event.preventDefault()` and call `callback(true)`.
|
`event.preventDefault()` and call `callback(true)`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
|
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||||
if (url === 'https://github.com') {
|
if (url === 'https://github.com') {
|
||||||
// Verification logic.
|
// Verification logic.
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -207,7 +207,7 @@ and `callback` needs to be called with an entry filtered from the list. Using
|
||||||
certificate from the store.
|
certificate from the store.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('select-client-certificate', function(event, webContents, url, list, callback) {
|
app.on('select-client-certificate', (event, webContents, url, list, callback) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
callback(list[0]);
|
callback(list[0]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -220,7 +220,7 @@ reloaded. In Electron, returning an empty string or `false` would cancel the
|
||||||
close. For example:
|
close. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
window.onbeforeunload = function(e) {
|
window.onbeforeunload = (e) => {
|
||||||
console.log('I do not want to be closed');
|
console.log('I do not want to be closed');
|
||||||
|
|
||||||
// Unlike usual browsers, in which a string should be returned and the user is
|
// 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
|
```javascript
|
||||||
// In this example `win` is our instance
|
// 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`
|
### `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:
|
a HTML-rendered toolbar. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var toolbarRect = document.getElementById('toolbar').getBoundingClientRect();
|
let toolbarRect = document.getElementById('toolbar').getBoundingClientRect();
|
||||||
win.setSheetOffset(toolbarRect.height);
|
win.setSheetOffset(toolbarRect.height);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ const options = {
|
||||||
traceOptions: 'record-until-full,enable-sampling'
|
traceOptions: 'record-until-full,enable-sampling'
|
||||||
};
|
};
|
||||||
|
|
||||||
contentTracing.startRecording(options, function() {
|
contentTracing.startRecording(options, () => {
|
||||||
console.log('Tracing started');
|
console.log('Tracing started');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
@ -9,7 +9,7 @@ const {desktopCapturer} = require('electron');
|
||||||
|
|
||||||
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
for (var i = 0; i < sources.length; ++i) {
|
for (let i = 0; i < sources.length; ++i) {
|
||||||
if (sources[i].name === 'Electron') {
|
if (sources[i].name === 'Electron') {
|
||||||
navigator.webkitGetUserMedia({
|
navigator.webkitGetUserMedia({
|
||||||
audio: false,
|
audio: false,
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
An example of showing a dialog to select multiple files and directories:
|
An example of showing a dialog to select multiple files and directories:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = ...; // BrowserWindow in which to show the dialog
|
let win = ...; // BrowserWindow in which to show the dialog
|
||||||
const {dialog} = require('electron');
|
const {dialog} = require('electron');
|
||||||
|
|
||||||
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}));
|
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}));
|
||||||
|
|
|
@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions.
|
||||||
You can do so by specifying the new `titleBarStyle` option:
|
You can do so by specifying the new `titleBarStyle` option:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
|
let win = new BrowserWindow({titleBarStyle: 'hidden'});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Transparent window
|
## Transparent window
|
||||||
|
|
|
@ -15,7 +15,7 @@ const {app, globalShortcut} = require('electron');
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
// Register a 'CommandOrControl+X' shortcut listener.
|
// 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');
|
console.log('CommandOrControl+X is pressed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ the user right clicks the page:
|
||||||
const {Menu, MenuItem} = require('electron').remote;
|
const {Menu, MenuItem} = require('electron').remote;
|
||||||
|
|
||||||
const menu = new Menu();
|
const menu = new Menu();
|
||||||
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
menu.append(new MenuItem({label: 'MenuItem1', click() { console.log('item 1 clicked'); }}));
|
||||||
menu.append(new MenuItem({type: 'separator'}));
|
menu.append(new MenuItem({type: 'separator'}));
|
||||||
menu.append(new MenuItem({label: 'MenuItem2', type: 'checkbox', checked: true}));
|
menu.append(new MenuItem({label: 'MenuItem2', type: 'checkbox', checked: true}));
|
||||||
|
|
||||||
|
@ -78,14 +78,14 @@ const template = [
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: (item, focusedWindow) => {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.reload();
|
if (focusedWindow) focusedWindow.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: process.platform === 'darwin' ? 'Ctrl+Command+F' : 'F11',
|
accelerator: process.platform === 'darwin' ? 'Ctrl+Command+F' : 'F11',
|
||||||
click: (item, focusedWindow) => {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow)
|
||||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ const template = [
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||||
click: (item, focusedWindow) => {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow)
|
||||||
focusedWindow.webContents.toggleDevTools();
|
focusedWindow.webContents.toggleDevTools();
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ const template = [
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click: () => { require('electron').shell.openExternal('http://electron.atom.io') }
|
click() { require('electron').shell.openExternal('http://electron.atom.io'); }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -168,7 +168,7 @@ if (process.platform === 'darwin') {
|
||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
accelerator: 'Command+Q',
|
accelerator: 'Command+Q',
|
||||||
click: () => { app.quit(); }
|
click() { app.quit(); }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
|
@ -49,7 +49,7 @@ images/
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var appIcon = new Tray('/Users/somebody/images/icon.png');
|
let appIcon = new Tray('/Users/somebody/images/icon.png');
|
||||||
```
|
```
|
||||||
|
|
||||||
Following suffixes for DPI are also supported:
|
Following suffixes for DPI are also supported:
|
||||||
|
@ -118,7 +118,7 @@ The following methods are available on instances of `nativeImage`:
|
||||||
```javascript
|
```javascript
|
||||||
const nativeImage = require('electron').nativeImage;
|
const nativeImage = require('electron').nativeImage;
|
||||||
|
|
||||||
var image = nativeImage.createFromPath('/Users/somebody/images/icon.png');
|
let image = nativeImage.createFromPath('/Users/somebody/images/icon.png');
|
||||||
```
|
```
|
||||||
|
|
||||||
### `image.toPng()`
|
### `image.toPng()`
|
||||||
|
|
|
@ -32,7 +32,7 @@ the global scope when node integration is turned off:
|
||||||
// preload.js
|
// preload.js
|
||||||
const _setImmediate = setImmediate;
|
const _setImmediate = setImmediate;
|
||||||
const _clearImmediate = clearImmediate;
|
const _clearImmediate = clearImmediate;
|
||||||
process.once('loaded', function() {
|
process.once('loaded', () => {
|
||||||
global.setImmediate = _setImmediate;
|
global.setImmediate = _setImmediate;
|
||||||
global.clearImmediate = _clearImmediate;
|
global.clearImmediate = _clearImmediate;
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,11 +9,11 @@ An example of implementing a protocol that has the same effect as the
|
||||||
const {app, protocol} = require('electron');
|
const {app, protocol} = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', () => {
|
||||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
protocol.registerFileProtocol('atom', (request, callback) => {
|
||||||
const url = request.url.substr(7);
|
const url = request.url.substr(7);
|
||||||
callback({path: path.normalize(__dirname + '/' + url)});
|
callback({path: path.normalize(__dirname + '/' + url)});
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
console.error('Failed to register protocol');
|
console.error('Failed to register protocol');
|
||||||
});
|
});
|
||||||
|
@ -53,7 +53,7 @@ have to register it as standard scheme:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
protocol.registerStandardSchemes(['atom']);
|
protocol.registerStandardSchemes(['atom']);
|
||||||
app.on('ready', function () {
|
app.on('ready', () => {
|
||||||
protocol.registerHttpProtocol('atom', ...);
|
protocol.registerHttpProtocol('atom', ...);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -16,7 +16,7 @@ renderer process:
|
||||||
```javascript
|
```javascript
|
||||||
const {BrowserWindow} = require('electron').remote;
|
const {BrowserWindow} = require('electron').remote;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
let win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadURL('https://github.com');
|
win.loadURL('https://github.com');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ emitted (by invoking or requiring it).
|
||||||
`screen` is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter).
|
`screen` is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter).
|
||||||
|
|
||||||
**Note:** In the renderer / DevTools, `window.screen` is a reserved DOM
|
**Note:** In the renderer / DevTools, `window.screen` is a reserved DOM
|
||||||
property, so writing `var screen = require('electron').screen` will not work.
|
property, so writing `let {screen} = require('electron')` will not work.
|
||||||
In our examples below, we use `electronScreen` as the variable name instead.
|
In our examples below, we use `electronScreen` as the variable name instead.
|
||||||
An example of creating a window that fills the whole screen:
|
An example of creating a window that fills the whole screen:
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ const {app, BrowserWindow, screen: electronScreen} = require('electron');
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
var displays = electronScreen.getAllDisplays();
|
let displays = electronScreen.getAllDisplays();
|
||||||
var externalDisplay = null;
|
let externalDisplay = null;
|
||||||
for (let i in displays) {
|
for (let i in displays) {
|
||||||
if (displays[i].bounds.x !== 0 || displays[i].bounds.y !== 0) {
|
if (displays[i].bounds.x !== 0 || displays[i].bounds.y !== 0) {
|
||||||
externalDisplay = displays[i];
|
externalDisplay = displays[i];
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
> Add icons and context menus to the system's notification area.
|
> Add icons and context menus to the system's notification area.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const {app, Menu, Tray} = require('electron');
|
||||||
const app = electron.app;
|
|
||||||
const Menu = electron.Menu;
|
|
||||||
const Tray = electron.Tray;
|
|
||||||
|
|
||||||
let appIcon = null;
|
let appIcon = null;
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
|
|
|
@ -603,7 +603,7 @@ the request can be obtained by subscribing to
|
||||||
Stops any `findInPage` request for the `webContents` with the provided `action`.
|
Stops any `findInPage` request for the `webContents` with the provided `action`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webContents.on('found-in-page', function(event, result) {
|
webContents.on('found-in-page', (event, result) => {
|
||||||
if (result.finalUpdate)
|
if (result.finalUpdate)
|
||||||
webContents.stopFindInPage('clearSelection');
|
webContents.stopFindInPage('clearSelection');
|
||||||
});
|
});
|
||||||
|
@ -700,7 +700,7 @@ Adds the specified path to DevTools workspace. Must be used after DevTools
|
||||||
creation:
|
creation:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
mainWindow.webContents.on('devtools-opened', function() {
|
mainWindow.webContents.on('devtools-opened', () => {
|
||||||
mainWindow.webContents.addWorkSpace(__dirname);
|
mainWindow.webContents.addWorkSpace(__dirname);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -887,7 +887,7 @@ End subscribing for frame presentation events.
|
||||||
* `HTMLOnly` - Save only the HTML of the page.
|
* `HTMLOnly` - Save only the HTML of the page.
|
||||||
* `HTMLComplete` - Save complete-html page.
|
* `HTMLComplete` - Save complete-html page.
|
||||||
* `MHTML` - Save complete-html page as MHTML.
|
* `MHTML` - Save complete-html page as MHTML.
|
||||||
* `callback` Function - `function(error) {}`.
|
* `callback` Function - `(error) => {}`.
|
||||||
* `error` Error
|
* `error` Error
|
||||||
|
|
||||||
Returns true if the process of saving page has been initiated successfully.
|
Returns true if the process of saving page has been initiated successfully.
|
||||||
|
|
|
@ -59,7 +59,7 @@ An example of using [node-spellchecker][spellchecker] as provider:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webFrame.setSpellCheckProvider('en-US', true, {
|
webFrame.setSpellCheckProvider('en-US', true, {
|
||||||
spellCheck: function(text) {
|
spellCheck(text) {
|
||||||
return !(require('spellchecker').isMisspelled(text));
|
return !(require('spellchecker').isMisspelled(text));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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.
|
without regard for log level or other properties.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('console-message', function(e) {
|
webview.addEventListener('console-message', (e) => {
|
||||||
console.log('Guest page logged a message:', e.message);
|
console.log('Guest page logged a message:', e.message);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -620,7 +620,7 @@ Fired when a result is available for
|
||||||
[`webview.findInPage`](web-view-tag.md#webviewtagfindinpage) request.
|
[`webview.findInPage`](web-view-tag.md#webviewtagfindinpage) request.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('found-in-page', function(e) {
|
webview.addEventListener('found-in-page', (e) => {
|
||||||
if (e.result.finalUpdate)
|
if (e.result.finalUpdate)
|
||||||
webview.stopFindInPage('keepSelection');
|
webview.stopFindInPage('keepSelection');
|
||||||
});
|
});
|
||||||
|
|
|
@ -85,7 +85,7 @@ For example, to get a file with `$.get`:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
var $ = require('./jquery.min.js');
|
let $ = require('./jquery.min.js');
|
||||||
$.get('file:///path/to/example.asar/file.txt', (data) => {
|
$.get('file:///path/to/example.asar/file.txt', (data) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,7 @@ let myNotification = new Notification('Title', {
|
||||||
body: 'Lorem Ipsum Dolor Sit Amet'
|
body: 'Lorem Ipsum Dolor Sit Amet'
|
||||||
});
|
});
|
||||||
|
|
||||||
myNotification.onclick = function () {
|
myNotification.onclick = () => {
|
||||||
console.log('Notification clicked');
|
console.log('Notification clicked');
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -118,7 +118,7 @@ const app = electron.app;
|
||||||
const Menu = electron.Menu;
|
const Menu = electron.Menu;
|
||||||
|
|
||||||
const dockMenu = Menu.buildFromTemplate([
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click: () => { console.log('New Window'); } },
|
{ label: 'New Window', click() { console.log('New Window'); } },
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{ label: 'New Window with Settings', submenu: [
|
||||||
{ label: 'Basic' },
|
{ label: 'Basic' },
|
||||||
{ label: 'Pro'}
|
{ label: 'Pro'}
|
||||||
|
@ -221,13 +221,13 @@ win.setThumbarButtons([
|
||||||
{
|
{
|
||||||
tooltip: 'button1',
|
tooltip: 'button1',
|
||||||
icon: path.join(__dirname, 'button1.png'),
|
icon: path.join(__dirname, 'button1.png'),
|
||||||
click: () => { console.log('button2 clicked'); }
|
click() { console.log('button2 clicked'); }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tooltip: 'button2',
|
tooltip: 'button2',
|
||||||
icon: path.join(__dirname, 'button2.png'),
|
icon: path.join(__dirname, 'button2.png'),
|
||||||
flags: ['enabled', 'dismissonclick'],
|
flags: ['enabled', 'dismissonclick'],
|
||||||
click: () => { console.log('button2 clicked.'); }
|
click() { console.log('button2 clicked.'); }
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
|
|
|
@ -82,9 +82,9 @@ example being:
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
// Module to control application life.
|
// Module to control application life.
|
||||||
const app = electron.app;
|
const {app} = electron;
|
||||||
// Module to create native browser window.
|
// Module to create native browser window.
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
const {BrowserWindow} = electron;
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
|
|
|
@ -59,7 +59,7 @@ driver.get('http://www.google.com');
|
||||||
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
|
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
|
||||||
driver.findElement(webdriver.By.name('btnG')).click();
|
driver.findElement(webdriver.By.name('btnG')).click();
|
||||||
driver.wait(() => {
|
driver.wait(() => {
|
||||||
return driver.getTitle().then(function(title) {
|
return driver.getTitle().then((title) => {
|
||||||
return title === 'webdriver - Google Search';
|
return title === 'webdriver - Google Search';
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -106,7 +106,7 @@ const options = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var client = webdriverio.remote(options);
|
let client = webdriverio.remote(options);
|
||||||
|
|
||||||
client
|
client
|
||||||
.init()
|
.init()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue