Skip to content

Commit 55babea

Browse files
committed
📝 Update tutorials to ES6 [ci skip]
1 parent 3271492 commit 55babea

File tree

7 files changed

+66
-63
lines changed

7 files changed

+66
-63
lines changed

docs/tutorial/application-packaging.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ require('/path/to/example.asar/dir/module.js');
7171
You can also display a web page in an `asar` archive with `BrowserWindow`:
7272

7373
```javascript
74-
const BrowserWindow = require('electron').BrowserWindow;
75-
var win = new BrowserWindow({width: 800, height: 600});
74+
const { BrowserWindow } = require('electron');
75+
let win = new BrowserWindow({width: 800, height: 600});
7676
win.loadURL('file:///path/to/example.asar/static/index.html');
7777
```
7878

@@ -86,7 +86,7 @@ For example, to get a file with `$.get`:
8686
```html
8787
<script>
8888
var $ = require('./jquery.min.js');
89-
$.get('file:///path/to/example.asar/file.txt', function(data) {
89+
$.get('file:///path/to/example.asar/file.txt', (data) => {
9090
console.log(data);
9191
});
9292
</script>
@@ -99,7 +99,7 @@ content of `asar` archive as file. For this purpose you can use the built-in
9999
`original-fs` module which provides original `fs` APIs without `asar` support:
100100

101101
```javascript
102-
var originalFs = require('original-fs');
102+
const originalFs = require('original-fs');
103103
originalFs.readFileSync('/path/to/example.asar');
104104
```
105105

docs/tutorial/desktop-environment-integration.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the currently running operating system's native notification APIs to display it.
1818
**Note:** Since this is an HTML5 API it is only available in the renderer process.
1919

2020
```javascript
21-
var myNotification = new Notification('Title', {
21+
let myNotification = new Notification('Title', {
2222
body: 'Lorem Ipsum Dolor Sit Amet'
2323
});
2424

@@ -117,8 +117,8 @@ const electron = require('electron');
117117
const app = electron.app;
118118
const Menu = electron.Menu;
119119

120-
var dockMenu = Menu.buildFromTemplate([
121-
{ label: 'New Window', click: function() { console.log('New Window'); } },
120+
const dockMenu = Menu.buildFromTemplate([
121+
{ label: 'New Window', click: () => { console.log('New Window'); } },
122122
{ label: 'New Window with Settings', submenu: [
123123
{ label: 'Basic' },
124124
{ label: 'Pro'}
@@ -209,24 +209,25 @@ You can use [BrowserWindow.setThumbarButtons][setthumbarbuttons] to set
209209
thumbnail toolbar in your application:
210210

211211
```javascript
212-
const BrowserWindow = require('electron').BrowserWindow;
212+
const { BrowserWindow } = require('electron');
213213
const path = require('path');
214214

215-
var win = new BrowserWindow({
215+
let win = new BrowserWindow({
216216
width: 800,
217217
height: 600
218218
});
219+
219220
win.setThumbarButtons([
220221
{
221222
tooltip: "button1",
222223
icon: path.join(__dirname, 'button1.png'),
223-
click: function() { console.log("button2 clicked"); }
224+
click: () => { console.log("button2 clicked"); }
224225
},
225226
{
226227
tooltip: "button2",
227228
icon: path.join(__dirname, 'button2.png'),
228229
flags:['enabled', 'dismissonclick'],
229-
click: function() { console.log("button2 clicked."); }
230+
click: () => { console.log("button2 clicked."); }
230231
}
231232
]);
232233
```
@@ -266,7 +267,7 @@ To set the progress bar for a Window, you can use the
266267
[BrowserWindow.setProgressBar][setprogressbar] API:
267268

268269
```javascript
269-
var window = new BrowserWindow({...});
270+
let window = new BrowserWindow({...});
270271
window.setProgressBar(0.5);
271272
```
272273

@@ -293,7 +294,7 @@ To set the overlay icon for a window, you can use the
293294
[BrowserWindow.setOverlayIcon][setoverlayicon] API:
294295

295296
```javascript
296-
var window = new BrowserWindow({...});
297+
let window = new BrowserWindow({...});
297298
window.setOverlayIcon('path/to/overlay.png', 'Description for overlay');
298299
```
299300

@@ -315,7 +316,7 @@ To set the represented file of window, you can use the
315316
[BrowserWindow.setDocumentEdited][setdocumentedited] APIs:
316317

317318
```javascript
318-
var window = new BrowserWindow({...});
319+
let window = new BrowserWindow({...});
319320
window.setRepresentedFilename('/etc/passwd');
320321
window.setDocumentEdited(true);
321322
```

docs/tutorial/online-offline-events.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ const electron = require('electron');
1010
const app = electron.app;
1111
const BrowserWindow = electron.BrowserWindow;
1212

13-
var onlineStatusWindow;
14-
app.on('ready', function() {
13+
let onlineStatusWindow;
14+
15+
app.on('ready', () => {
1516
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
16-
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html');
17+
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`);
1718
});
1819
```
1920

@@ -24,7 +25,7 @@ _online-status.html_
2425
<html>
2526
<body>
2627
<script>
27-
var alertOnlineStatus = function() {
28+
const alertOnlineStatus = () => {
2829
window.alert(navigator.onLine ? 'online' : 'offline');
2930
};
3031
@@ -51,13 +52,14 @@ const app = electron.app;
5152
const ipcMain = electron.ipcMain;
5253
const BrowserWindow = electron.BrowserWindow;
5354

54-
var onlineStatusWindow;
55-
app.on('ready', function() {
55+
let onlineStatusWindow;
56+
57+
app.on('ready', () => {
5658
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
57-
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html');
59+
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`);
5860
});
5961

60-
ipcMain.on('online-status-changed', function(event, status) {
62+
ipcMain.on('online-status-changed', (event, status) => {
6163
console.log(status);
6264
});
6365
```
@@ -69,8 +71,8 @@ _online-status.html_
6971
<html>
7072
<body>
7173
<script>
72-
const ipcRenderer = require('electron').ipcRenderer;
73-
var updateOnlineStatus = function() {
74+
const { ipcRenderer } = require('electron');
75+
const updateOnlineStatus = () => {
7476
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
7577
};
7678

docs/tutorial/quick-start.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,54 +82,54 @@ example being:
8282
```javascript
8383
const electron = require('electron')
8484
// Module to control application life.
85-
const app = electron.app
85+
const app = electron.app;
8686
// Module to create native browser window.
87-
const BrowserWindow = electron.BrowserWindow
87+
const BrowserWindow = electron.BrowserWindow;
8888

8989
// Keep a global reference of the window object, if you don't, the window will
9090
// be closed automatically when the JavaScript object is garbage collected.
91-
let mainWindow
91+
let mainWindow;
9292

9393
function createWindow () {
9494
// Create the browser window.
95-
mainWindow = new BrowserWindow({width: 800, height: 600})
95+
mainWindow = new BrowserWindow({width: 800, height: 600});
9696

9797
// and load the index.html of the app.
98-
mainWindow.loadURL('file://' + __dirname + '/index.html')
98+
mainWindow.loadURL(`file://${__dirname}/index.html`);
9999

100100
// Open the DevTools.
101-
mainWindow.webContents.openDevTools()
101+
mainWindow.webContents.openDevTools();
102102

103103
// Emitted when the window is closed.
104-
mainWindow.on('closed', function () {
104+
mainWindow.on('closed', () => {
105105
// Dereference the window object, usually you would store windows
106106
// in an array if your app supports multi windows, this is the time
107107
// when you should delete the corresponding element.
108-
mainWindow = null
109-
})
108+
mainWindow = null;
109+
});
110110
}
111111

112112
// This method will be called when Electron has finished
113113
// initialization and is ready to create browser windows.
114114
// Some APIs can only be used after this event occurs.
115-
app.on('ready', createWindow)
115+
app.on('ready', createWindow);
116116

117117
// Quit when all windows are closed.
118-
app.on('window-all-closed', function () {
118+
app.on('window-all-closed', () => {
119119
// On OS X it is common for applications and their menu bar
120120
// to stay active until the user quits explicitly with Cmd + Q
121121
if (process.platform !== 'darwin') {
122-
app.quit()
122+
app.quit();
123123
}
124-
})
124+
});
125125

126-
app.on('activate', function () {
126+
app.on('activate', () => {
127127
// On OS X it's common to re-create a window in the app when the
128128
// dock icon is clicked and there are no other windows open.
129129
if (mainWindow === null) {
130-
createWindow()
130+
createWindow();
131131
}
132-
})
132+
});
133133

134134
// In this file you can include the rest of your app's specific main process
135135
// code. You can also put them in separate files and require them here.

docs/tutorial/using-pepper-flash-plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ app.commandLine.appendSwitch('ppapi-flash-path', '/path/to/libpepflashplayer.so'
2828
// Optional: Specify flash version, for example, v17.0.0.169
2929
app.commandLine.appendSwitch('ppapi-flash-version', '17.0.0.169');
3030

31-
app.on('ready', function() {
31+
app.on('ready', () => {
3232
mainWindow = new BrowserWindow({
3333
width: 800,
3434
height: 600,
3535
webPreferences: {
3636
plugins: true
3737
}
3838
});
39-
mainWindow.loadURL('file://' + __dirname + '/index.html');
39+
mainWindow.loadURL(`file://${__dirname}/index.html`);
4040
// Something else
4141
});
4242
```

docs/tutorial/using-selenium-and-webdriver.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ and where to find Electron's binary:
4343
```javascript
4444
const webdriver = require('selenium-webdriver');
4545

46-
var driver = new webdriver.Builder()
46+
const driver = new webdriver.Builder()
4747
// The "9515" is the port opened by chrome driver.
4848
.usingServer('http://localhost:9515')
4949
.withCapabilities({
@@ -58,7 +58,7 @@ var driver = new webdriver.Builder()
5858
driver.get('http://www.google.com');
5959
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
6060
driver.findElement(webdriver.By.name('btnG')).click();
61-
driver.wait(function() {
61+
driver.wait(() => {
6262
return driver.getTitle().then(function(title) {
6363
return title === 'webdriver - Google Search';
6464
});
@@ -94,29 +94,29 @@ $ npm install webdriverio
9494

9595
```javascript
9696
const webdriverio = require('webdriverio');
97-
var options = {
98-
host: "localhost", // Use localhost as chrome driver server
99-
port: 9515, // "9515" is the port opened by chrome driver.
100-
desiredCapabilities: {
101-
browserName: 'chrome',
102-
chromeOptions: {
103-
binary: '/Path-to-Your-App/electron', // Path to your Electron binary.
104-
args: [/* cli arguments */] // Optional, perhaps 'app=' + /path/to/your/app/
105-
}
97+
const options = {
98+
host: 'localhost', // Use localhost as chrome driver server
99+
port: 9515, // "9515" is the port opened by chrome driver.
100+
desiredCapabilities: {
101+
browserName: 'chrome',
102+
chromeOptions: {
103+
binary: '/Path-to-Your-App/electron', // Path to your Electron binary.
104+
args: [/* cli arguments */] // Optional, perhaps 'app=' + /path/to/your/app/
106105
}
106+
}
107107
};
108108

109109
var client = webdriverio.remote(options);
110110

111111
client
112-
.init()
113-
.url('http://google.com')
114-
.setValue('#q', 'webdriverio')
115-
.click('#btnG')
116-
.getTitle().then(function(title) {
117-
console.log('Title was: ' + title);
118-
})
119-
.end();
112+
.init()
113+
.url('http://google.com')
114+
.setValue('#q', 'webdriverio')
115+
.click('#btnG')
116+
.getTitle().then((title) => {
117+
console.log('Title was: ' + title);
118+
})
119+
.end();
120120
```
121121

122122
## Workflow

docs/tutorial/using-widevine-cdm-plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.p
5959
// The version of plugin can be got from `chrome://plugins` page in Chrome.
6060
app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866');
6161

62-
var mainWindow = null;
63-
app.on('ready', function() {
62+
let mainWindow = null;
63+
app.on('ready', () => {
6464
mainWindow = new BrowserWindow({
6565
webPreferences: {
6666
// The `plugins` have to be enabled.

0 commit comments

Comments
 (0)