build: update to standard 14 (#24479)
This commit is contained in:
parent
9bd0fc5348
commit
eb6616e4e9
37 changed files with 495 additions and 665 deletions
|
@ -15,7 +15,7 @@ can open them programmatically by calling the `openDevTools()` API on the
|
|||
```javascript
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow()
|
||||
const win = new BrowserWindow()
|
||||
win.webContents.openDevTools()
|
||||
```
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ fs.readdirSync('/path/to/example.asar')
|
|||
Use a module from the archive:
|
||||
|
||||
```javascript
|
||||
require('/path/to/example.asar/dir/module.js')
|
||||
require('./path/to/example.asar/dir/module.js')
|
||||
```
|
||||
|
||||
You can also display a web page in an `asar` archive with `BrowserWindow`:
|
||||
|
|
|
@ -9,9 +9,9 @@ const childProcess = require('child_process')
|
|||
const electronPath = require('electron')
|
||||
|
||||
// spawn the process
|
||||
let env = { /* ... */ }
|
||||
let stdio = ['inherit', 'inherit', 'inherit', 'ipc']
|
||||
let appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env })
|
||||
const env = { /* ... */ }
|
||||
const stdio = ['inherit', 'inherit', 'inherit', 'ipc']
|
||||
const appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env })
|
||||
|
||||
// listen for IPC messages from the app
|
||||
appProcess.on('message', (msg) => {
|
||||
|
@ -50,7 +50,7 @@ class TestDriver {
|
|||
// handle rpc responses
|
||||
this.process.on('message', (message) => {
|
||||
// pop the handler
|
||||
let rpcCall = this.rpcCalls[message.msgId]
|
||||
const rpcCall = this.rpcCalls[message.msgId]
|
||||
if (!rpcCall) return
|
||||
this.rpcCalls[message.msgId] = null
|
||||
// reject/resolve
|
||||
|
@ -70,7 +70,7 @@ class TestDriver {
|
|||
// to use: driver.rpc('method', 1, 2, 3).then(...)
|
||||
async rpc (cmd, ...args) {
|
||||
// send rpc request
|
||||
let msgId = this.rpcCalls.length
|
||||
const msgId = this.rpcCalls.length
|
||||
this.process.send({ msgId, cmd, args })
|
||||
return new Promise((resolve, reject) => this.rpcCalls.push({ resolve, reject }))
|
||||
}
|
||||
|
@ -92,10 +92,10 @@ async function onMessage ({ msgId, cmd, args }) {
|
|||
let method = METHODS[cmd]
|
||||
if (!method) method = () => new Error('Invalid method: ' + cmd)
|
||||
try {
|
||||
let resolve = await method(...args)
|
||||
const resolve = await method(...args)
|
||||
process.send({ msgId, resolve })
|
||||
} catch (err) {
|
||||
let reject = {
|
||||
const reject = {
|
||||
message: err.message,
|
||||
stack: err.stack,
|
||||
name: err.name
|
||||
|
@ -119,7 +119,7 @@ Then, in your test suite, you can use your test-driver as follows:
|
|||
const test = require('ava')
|
||||
const electronPath = require('electron')
|
||||
|
||||
let app = new TestDriver({
|
||||
const app = new TestDriver({
|
||||
path: electronPath,
|
||||
args: ['./app'],
|
||||
env: {
|
||||
|
|
|
@ -96,7 +96,7 @@ const { app, BrowserWindow } = require('electron')
|
|||
|
||||
function createWindow () {
|
||||
// Create the browser window.
|
||||
let win = new BrowserWindow({
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
|
|
|
@ -37,18 +37,18 @@ inAppPurchase.on('transactions-updated', (event, transactions) => {
|
|||
|
||||
// Check each transaction.
|
||||
transactions.forEach(function (transaction) {
|
||||
let payment = transaction.payment
|
||||
const payment = transaction.payment
|
||||
|
||||
switch (transaction.transactionState) {
|
||||
case 'purchasing':
|
||||
console.log(`Purchasing ${payment.productIdentifier}...`)
|
||||
break
|
||||
case 'purchased':
|
||||
|
||||
case 'purchased': {
|
||||
console.log(`${payment.productIdentifier} purchased.`)
|
||||
|
||||
// Get the receipt url.
|
||||
let receiptURL = inAppPurchase.getReceiptURL()
|
||||
const receiptURL = inAppPurchase.getReceiptURL()
|
||||
|
||||
console.log(`Receipt URL: ${receiptURL}`)
|
||||
|
||||
|
@ -62,6 +62,8 @@ inAppPurchase.on('transactions-updated', (event, transactions) => {
|
|||
inAppPurchase.finishTransactionByDate(transaction.transactionDate)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case 'failed':
|
||||
|
||||
console.log(`Failed to purchase ${payment.productIdentifier}.`)
|
||||
|
@ -105,8 +107,8 @@ inAppPurchase.getProducts(PRODUCT_IDS).then(products => {
|
|||
})
|
||||
|
||||
// Ask the user which product he/she wants to purchase.
|
||||
let selectedProduct = products[0]
|
||||
let selectedQuantity = 1
|
||||
const selectedProduct = products[0]
|
||||
const selectedQuantity = 1
|
||||
|
||||
// Purchase the selected product.
|
||||
inAppPurchase.purchaseProduct(selectedProduct.productIdentifier, selectedQuantity).then(isProductValid => {
|
||||
|
|
|
@ -10,7 +10,7 @@ so the `nodeIntegrationInWorker` option should be set to `true` in
|
|||
`webPreferences`.
|
||||
|
||||
```javascript
|
||||
let win = new BrowserWindow({
|
||||
const win = new BrowserWindow({
|
||||
webPreferences: {
|
||||
nodeIntegrationInWorker: true
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ loads no native modules after the Web Workers get started.
|
|||
process.dlopen = () => {
|
||||
throw new Error('Load native module is not safe')
|
||||
}
|
||||
let worker = new Worker('script.js')
|
||||
const worker = new Worker('script.js')
|
||||
```
|
||||
|
||||
[web-workers]: https://developer.mozilla.org/en/docs/Web/API/Web_Workers_API/Using_web_workers
|
||||
|
|
|
@ -10,7 +10,7 @@ you want to show Notifications in the main process please check out the
|
|||
[Notification](../api/notification.md) module.
|
||||
|
||||
```javascript
|
||||
let myNotification = new Notification('Title', {
|
||||
const myNotification = new Notification('Title', {
|
||||
body: 'Lorem Ipsum Dolor Sit Amet'
|
||||
})
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ app.commandLine.appendSwitch('ppapi-flash-path', path.join(__dirname, pluginName
|
|||
app.commandLine.appendSwitch('ppapi-flash-version', '17.0.0.169')
|
||||
|
||||
app.whenReady().then(() => {
|
||||
let win = new BrowserWindow({
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
|
|
|
@ -146,7 +146,7 @@ const options = {
|
|||
}
|
||||
}
|
||||
|
||||
let client = webdriverio.remote(options)
|
||||
const client = webdriverio.remote(options)
|
||||
|
||||
client
|
||||
.init()
|
||||
|
|
|
@ -149,7 +149,7 @@ To set the overlay icon for a window, you can use the
|
|||
|
||||
```javascript
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
const win = new BrowserWindow()
|
||||
win.setOverlayIcon('path/to/overlay.png', 'Description for overlay')
|
||||
```
|
||||
|
||||
|
@ -168,7 +168,7 @@ To flash the BrowserWindow taskbar button, you can use the
|
|||
|
||||
```javascript
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
const win = new BrowserWindow()
|
||||
win.once('focus', () => win.flashFrame(false))
|
||||
win.flashFrame(true)
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue