📝 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)`.
|
||||
|
||||
```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') {
|
||||
// Verification logic.
|
||||
event.preventDefault();
|
||||
|
@ -207,7 +207,7 @@ 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]);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ const {BrowserWindow} = require('electron');
|
|||
// Or in the renderer process.
|
||||
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);
|
||||
```
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ const options = {
|
|||
traceOptions: 'record-until-full,enable-sampling'
|
||||
};
|
||||
|
||||
contentTracing.startRecording(options, function() {
|
||||
contentTracing.startRecording(options, () => {
|
||||
console.log('Tracing started');
|
||||
|
||||
setTimeout(() => {
|
||||
|
|
|
@ -9,7 +9,7 @@ const {desktopCapturer} = require('electron');
|
|||
|
||||
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
||||
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') {
|
||||
navigator.webkitGetUserMedia({
|
||||
audio: false,
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
An example of showing a dialog to select multiple files and directories:
|
||||
|
||||
```javascript
|
||||
var win = ...; // BrowserWindow in which to show the dialog
|
||||
let win = ...; // BrowserWindow in which to show the dialog
|
||||
const {dialog} = require('electron');
|
||||
|
||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}));
|
||||
```
|
||||
|
||||
The Dialog is opened from Electron's main thread. If you want to use the dialog
|
||||
|
@ -43,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: ['*']}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
|
|
@ -15,7 +15,7 @@ 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 });
|
||||
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
|
||||
|
|
|
@ -15,7 +15,7 @@ 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');
|
||||
});
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ the user right clicks the page:
|
|||
const {Menu, MenuItem} = require('electron').remote;
|
||||
|
||||
const menu = new Menu();
|
||||
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
||||
menu.append(new MenuItem({ type: 'separator' }));
|
||||
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
|
||||
menu.append(new MenuItem({label: 'MenuItem1', click() { console.log('item 1 clicked'); }}));
|
||||
menu.append(new MenuItem({type: 'separator'}));
|
||||
menu.append(new MenuItem({label: 'MenuItem2', type: 'checkbox', checked: true}));
|
||||
|
||||
window.addEventListener('contextmenu', (e) => {
|
||||
e.preventDefault();
|
||||
|
@ -78,14 +78,14 @@ const template = [
|
|||
{
|
||||
label: 'Reload',
|
||||
accelerator: 'CmdOrCtrl+R',
|
||||
click: (item, focusedWindow) => {
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) focusedWindow.reload();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Full Screen',
|
||||
accelerator: process.platform === 'darwin' ? 'Ctrl+Command+F' : 'F11',
|
||||
click: (item, focusedWindow) => {
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ const template = [
|
|||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||
click: (item, focusedWindow) => {
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.webContents.toggleDevTools();
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ const template = [
|
|||
submenu: [
|
||||
{
|
||||
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',
|
||||
accelerator: 'Command+Q',
|
||||
click: () => { app.quit(); }
|
||||
click() { app.quit(); }
|
||||
},
|
||||
]
|
||||
});
|
||||
|
|
|
@ -49,7 +49,7 @@ images/
|
|||
|
||||
|
||||
```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:
|
||||
|
@ -118,7 +118,7 @@ The following methods are available on instances of `nativeImage`:
|
|||
```javascript
|
||||
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()`
|
||||
|
|
|
@ -32,7 +32,7 @@ the global scope when node integration is turned off:
|
|||
// preload.js
|
||||
const _setImmediate = setImmediate;
|
||||
const _clearImmediate = clearImmediate;
|
||||
process.once('loaded', function() {
|
||||
process.once('loaded', () => {
|
||||
global.setImmediate = _setImmediate;
|
||||
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 path = require('path');
|
||||
|
||||
app.on('ready', function () {
|
||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
||||
app.on('ready', () => {
|
||||
protocol.registerFileProtocol('atom', (request, callback) => {
|
||||
const url = request.url.substr(7);
|
||||
callback({path: path.normalize(__dirname + '/' + url)});
|
||||
}, function (error) {
|
||||
}, (error) => {
|
||||
if (error)
|
||||
console.error('Failed to register protocol');
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ have to register it as standard scheme:
|
|||
|
||||
```javascript
|
||||
protocol.registerStandardSchemes(['atom']);
|
||||
app.on('ready', function () {
|
||||
app.on('ready', () => {
|
||||
protocol.registerHttpProtocol('atom', ...);
|
||||
});
|
||||
```
|
||||
|
|
|
@ -16,7 +16,7 @@ renderer process:
|
|||
```javascript
|
||||
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');
|
||||
```
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ emitted (by invoking or requiring it).
|
|||
`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
|
||||
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.
|
||||
An example of creating a window that fills the whole screen:
|
||||
|
||||
|
@ -19,7 +19,7 @@ let mainWindow;
|
|||
|
||||
app.on('ready', () => {
|
||||
const {width, height} = electronScreen.getPrimaryDisplay().workAreaSize;
|
||||
mainWindow = new BrowserWindow({ width, height });
|
||||
mainWindow = new BrowserWindow({width, height});
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -31,8 +31,8 @@ const {app, BrowserWindow, screen: electronScreen} = require('electron');
|
|||
let mainWindow;
|
||||
|
||||
app.on('ready', () => {
|
||||
var displays = electronScreen.getAllDisplays();
|
||||
var externalDisplay = null;
|
||||
let displays = electronScreen.getAllDisplays();
|
||||
let externalDisplay = null;
|
||||
for (let i in displays) {
|
||||
if (displays[i].bounds.x !== 0 || displays[i].bounds.y !== 0) {
|
||||
externalDisplay = displays[i];
|
||||
|
|
|
@ -11,7 +11,7 @@ property of [`webContents`](web-contents.md) which is a property of
|
|||
```javascript
|
||||
const {BrowserWindow} = require('electron');
|
||||
|
||||
let win = new BrowserWindow({ width: 800, height: 600 });
|
||||
let win = new BrowserWindow({width: 800, height: 600});
|
||||
win.loadURL('http://github.com');
|
||||
|
||||
const ses = win.webContents.session;
|
||||
|
@ -89,13 +89,13 @@ session.defaultSession.cookies.get({}, (error, cookies) => {
|
|||
});
|
||||
|
||||
// Query all cookies associated with a specific url.
|
||||
session.defaultSession.cookies.get({ url : 'http://www.github.com' }, (error, cookies) => {
|
||||
session.defaultSession.cookies.get({url : 'http://www.github.com'}, (error, cookies) => {
|
||||
console.log(cookies);
|
||||
});
|
||||
|
||||
// Set a cookie with the given cookie data;
|
||||
// may overwrite equivalent cookies if they exist.
|
||||
const cookie = { url : 'http://www.github.com', name : 'dummy_name', value : 'dummy' };
|
||||
const cookie = {url : 'http://www.github.com', name : 'dummy_name', value : 'dummy'};
|
||||
session.defaultSession.cookies.set(cookie, (error) => {
|
||||
if (error)
|
||||
console.error(error);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -603,7 +603,7 @@ 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');
|
||||
});
|
||||
|
@ -700,7 +700,7 @@ Adds the specified path to DevTools workspace. Must be used after DevTools
|
|||
creation:
|
||||
|
||||
```javascript
|
||||
mainWindow.webContents.on('devtools-opened', function() {
|
||||
mainWindow.webContents.on('devtools-opened', () => {
|
||||
mainWindow.webContents.addWorkSpace(__dirname);
|
||||
});
|
||||
```
|
||||
|
@ -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.
|
||||
|
|
|
@ -59,7 +59,7 @@ An example of using [node-spellchecker][spellchecker] as provider:
|
|||
|
||||
```javascript
|
||||
webFrame.setSpellCheckProvider('en-US', true, {
|
||||
spellCheck: function(text) {
|
||||
spellCheck(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.
|
||||
|
||||
```javascript
|
||||
webview.addEventListener('console-message', function(e) {
|
||||
webview.addEventListener('console-message', (e) => {
|
||||
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.
|
||||
|
||||
```javascript
|
||||
webview.addEventListener('found-in-page', function(e) {
|
||||
webview.addEventListener('found-in-page', (e) => {
|
||||
if (e.result.finalUpdate)
|
||||
webview.stopFindInPage('keepSelection');
|
||||
});
|
||||
|
|
|
@ -85,7 +85,7 @@ For example, to get a file with `$.get`:
|
|||
|
||||
```html
|
||||
<script>
|
||||
var $ = require('./jquery.min.js');
|
||||
let $ = require('./jquery.min.js');
|
||||
$.get('file:///path/to/example.asar/file.txt', (data) => {
|
||||
console.log(data);
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ let myNotification = new Notification('Title', {
|
|||
body: 'Lorem Ipsum Dolor Sit Amet'
|
||||
});
|
||||
|
||||
myNotification.onclick = function () {
|
||||
myNotification.onclick = () => {
|
||||
console.log('Notification clicked');
|
||||
};
|
||||
```
|
||||
|
@ -118,7 +118,7 @@ const app = electron.app;
|
|||
const Menu = electron.Menu;
|
||||
|
||||
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: 'Basic' },
|
||||
{ label: 'Pro'}
|
||||
|
@ -221,13 +221,13 @@ win.setThumbarButtons([
|
|||
{
|
||||
tooltip: 'button1',
|
||||
icon: path.join(__dirname, 'button1.png'),
|
||||
click: () => { console.log('button2 clicked'); }
|
||||
click() { console.log('button2 clicked'); }
|
||||
},
|
||||
{
|
||||
tooltip: 'button2',
|
||||
icon: path.join(__dirname, 'button2.png'),
|
||||
flags:['enabled', 'dismissonclick'],
|
||||
click: () => { console.log('button2 clicked.'); }
|
||||
flags: ['enabled', 'dismissonclick'],
|
||||
click() { console.log('button2 clicked.'); }
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
|
|
@ -82,15 +82,15 @@ example being:
|
|||
```javascript
|
||||
const electron = require('electron');
|
||||
// Module to control application life.
|
||||
const app = electron.app;
|
||||
const {app} = electron;
|
||||
// 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
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
function createWindow () {
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ driver.get('http://www.google.com');
|
|||
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
|
||||
driver.findElement(webdriver.By.name('btnG')).click();
|
||||
driver.wait(() => {
|
||||
return driver.getTitle().then(function(title) {
|
||||
return driver.getTitle().then((title) => {
|
||||
return title === 'webdriver - Google Search';
|
||||
});
|
||||
}, 1000);
|
||||
|
@ -106,7 +106,7 @@ const options = {
|
|||
}
|
||||
};
|
||||
|
||||
var client = webdriverio.remote(options);
|
||||
let client = webdriverio.remote(options);
|
||||
|
||||
client
|
||||
.init()
|
||||
|
|
Loading…
Reference in a new issue