chore: update to standard 12

This commit is contained in:
Samuel Attard 2018-09-14 02:10:51 +10:00
parent 9e85bdb02c
commit 558fff69e7
No known key found for this signature in database
GPG key ID: E89DDE5742D58C4E
198 changed files with 4455 additions and 2940 deletions

View file

@ -11,7 +11,7 @@ var electronPath = require('electron')
// spawn the process
var env = { /* ... */ }
var stdio = ['inherit', 'inherit', 'inherit', 'ipc']
var appProcess = childProcess.spawn(electronPath, ['./app'], {stdio, env})
var appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env })
// listen for IPC messages from the app
appProcess.on('message', (msg) => {
@ -19,7 +19,7 @@ appProcess.on('message', (msg) => {
})
// send an IPC message to the app
appProcess.send({my: 'message'})
appProcess.send({ my: 'message' })
```
From within the Electron app, you can listen for messages and send replies using the nodejs [process](https://nodejs.org/api/process.html) API:
@ -31,7 +31,7 @@ process.on('message', (msg) => {
})
// send an IPC message to the test suite
process.send({my: 'message'})
process.send({ my: 'message' })
```
We can now communicate from the test suite to the Electron app using the `appProcess` object.
@ -40,12 +40,12 @@ For convenience, you may want to wrap `appProcess` in a driver object that provi
```js
class TestDriver {
constructor ({path, args, env}) {
constructor ({ path, args, env }) {
this.rpcCalls = []
// start child process
env.APP_TEST_DRIVER = 1 // let the app know it should listen for messages
this.process = childProcess.spawn(path, args, {stdio: ['inherit', 'inherit', 'inherit', 'ipc'], env})
this.process = childProcess.spawn(path, args, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], env })
// handle rpc responses
this.process.on('message', (message) => {
@ -71,8 +71,8 @@ class TestDriver {
async rpc (cmd, ...args) {
// send rpc request
var msgId = this.rpcCalls.length
this.process.send({msgId, cmd, args})
return new Promise((resolve, reject) => this.rpcCalls.push({resolve, reject}))
this.process.send({ msgId, cmd, args })
return new Promise((resolve, reject) => this.rpcCalls.push({ resolve, reject }))
}
stop () {
@ -88,19 +88,19 @@ if (process.env.APP_TEST_DRIVER) {
process.on('message', onMessage)
}
async function onMessage ({msgId, cmd, args}) {
async function onMessage ({ msgId, cmd, args }) {
var method = METHODS[cmd]
if (!method) method = () => new Error('Invalid method: ' + cmd)
try {
var resolve = await method(...args)
process.send({msgId, resolve})
process.send({ msgId, resolve })
} catch (err) {
var reject = {
message: err.message,
stack: err.stack,
name: err.name
}
process.send({msgId, reject})
process.send({ msgId, reject })
}
}

View file

@ -105,11 +105,11 @@ using the `electron.BrowserWindow` class. A simple `main.js` file might wait
for the application to be ready and open a window:
```javascript
const {app, BrowserWindow} = require('electron')
const { app, BrowserWindow } = require('electron')
function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})
win = new BrowserWindow({ width: 800, height: 600 })
// and load the index.html of the app.
win.loadFile('index.html')
@ -124,7 +124,7 @@ might open developer tools, handle the window being closed, or re-create
windows on macOS if the user clicks on the app's icon in the dock.
```javascript
const {app, BrowserWindow} = require('electron')
const { app, BrowserWindow } = require('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.
@ -132,7 +132,7 @@ let win
function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})
win = new BrowserWindow({ width: 800, height: 600 })
// and load the index.html of the app.
win.loadFile('index.html')

View file

@ -9,7 +9,7 @@ be triggered only when the app is focused. To do so, specify an
[`accelerator`] property when creating a [MenuItem].
```js
const {Menu, MenuItem} = require('electron')
const { Menu, MenuItem } = require('electron')
const menu = new Menu()
menu.append(new MenuItem({
@ -33,7 +33,7 @@ You can use the [globalShortcut] module to detect keyboard events even when
the application does not have keyboard focus.
```js
const {app, globalShortcut} = require('electron')
const { app, globalShortcut } = require('electron')
app.on('ready', () => {
globalShortcut.register('CommandOrControl+X', () => {

View file

@ -11,7 +11,7 @@ Example:
_main.js_
```javascript
const {app, BrowserWindow} = require('electron')
const { app, BrowserWindow } = require('electron')
let onlineStatusWindow
@ -50,7 +50,7 @@ to the main process and handled as needed, as shown in the following example.
_main.js_
```javascript
const {app, BrowserWindow, ipcMain} = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron')
let onlineStatusWindow
app.on('ready', () => {
@ -70,7 +70,7 @@ _online-status.html_
<html>
<body>
<script>
const {ipcRenderer} = require('electron')
const { ipcRenderer } = require('electron')
const updateOnlineStatus = () => {
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline')
}

View file

@ -361,10 +361,10 @@ which can be set using Electron's
handler:
```javascript
const {session} = require('electron')
const { session } = require('electron')
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({responseHeaders: `default-src 'none'`})
callback({ responseHeaders: `default-src 'none'` })
})
```

View file

@ -34,7 +34,7 @@ passed before the `ready` event of `app` module gets emitted.
Example code:
```javascript
const {app, BrowserWindow} = require('electron')
const { app, BrowserWindow } = require('electron')
// You have to pass the directory that contains widevine library here, it is
// * `libwidevinecdm.dylib` on macOS,

View file

@ -20,7 +20,7 @@ before the app ready event. Also, turn on `plugins` option of `BrowserWindow`.
For example:
```javascript
const {app, BrowserWindow} = require('electron')
const { app, BrowserWindow } = require('electron')
const path = require('path')
// Specify flash path, supposing it is placed in the same directory with main.js.

View file

@ -32,13 +32,13 @@ app.start().then(function () {
return app.browserWindow.isVisible()
}).then(function (isVisible) {
// Verify the window is visible
assert.equal(isVisible, true)
assert.strictEqual(isVisible, true)
}).then(function () {
// Get the window's title
return app.client.getTitle()
}).then(function (title) {
// Verify the window's title
assert.equal(title, 'My App')
assert.strictEqual(title, 'My App')
}).catch(function (error) {
// Log any failures
console.error('Test failed', error.message)
@ -135,12 +135,12 @@ $ npm install webdriverio
const webdriverio = require('webdriverio')
const options = {
host: 'localhost', // Use localhost as chrome driver server
port: 9515, // "9515" is the port opened by chrome driver.
port: 9515, // "9515" is the port opened by chrome driver.
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
binary: '/Path-to-Your-App/electron', // Path to your Electron binary.
args: [/* cli arguments */] // Optional, perhaps 'app=' + /path/to/your/app/
args: [/* cli arguments */] // Optional, perhaps 'app=' + /path/to/your/app/
}
}
}

View file

@ -148,7 +148,7 @@ To set the overlay icon for a window, you can use the
[BrowserWindow.setOverlayIcon][setoverlayicon] API:
```javascript
const {BrowserWindow} = require('electron')
const { BrowserWindow } = require('electron')
let win = new BrowserWindow()
win.setOverlayIcon('path/to/overlay.png', 'Description for overlay')
```
@ -167,7 +167,7 @@ To flash the BrowserWindow taskbar button, you can use the
[BrowserWindow.flashFrame][flashframe] API:
```javascript
const {BrowserWindow} = require('electron')
const { BrowserWindow } = require('electron')
let win = new BrowserWindow()
win.once('focus', () => win.flashFrame(false))
win.flashFrame(true)