chore: fix lint:js-in-markdown script (#38260)

This commit is contained in:
David Sanders 2023-05-15 00:58:35 -07:00 committed by GitHub
parent 0149ae72e6
commit eeb1e7d499
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 1078 additions and 586 deletions

View file

@ -1346,7 +1346,7 @@ app.setLoginItemSettings({
path: updateExe, path: updateExe,
args: [ args: [
'--processStart', `"${exeName}"`, '--processStart', `"${exeName}"`,
'--process-start-args', `"--hidden"` '--process-start-args', '"--hidden"'
] ]
}) })
``` ```

View file

@ -65,7 +65,7 @@ strictly follow the Node.js model as described in the
For instance, we could have created the same request to 'github.com' as follows: For instance, we could have created the same request to 'github.com' as follows:
```JavaScript ```javascript
const request = net.request({ const request = net.request({
method: 'GET', method: 'GET',
protocol: 'https:', protocol: 'https:',
@ -104,7 +104,7 @@ The `callback` function is expected to be called back with user credentials:
* `username` string * `username` string
* `password` string * `password` string
```JavaScript ```javascript
request.on('login', (authInfo, callback) => { request.on('login', (authInfo, callback) => {
callback('username', 'password') callback('username', 'password')
}) })
@ -113,9 +113,9 @@ request.on('login', (authInfo, callback) => {
Providing empty credentials will cancel the request and report an authentication Providing empty credentials will cancel the request and report an authentication
error on the response object: error on the response object:
```JavaScript ```javascript
request.on('response', (response) => { request.on('response', (response) => {
console.log(`STATUS: ${response.statusCode}`); console.log(`STATUS: ${response.statusCode}`)
response.on('error', (error) => { response.on('error', (error) => {
console.log(`ERROR: ${JSON.stringify(error)}`) console.log(`ERROR: ${JSON.stringify(error)}`)
}) })

View file

@ -154,20 +154,22 @@ const isMac = process.platform === 'darwin'
const template = [ const template = [
// { role: 'appMenu' } // { role: 'appMenu' }
...(isMac ? [{ ...(isMac
label: app.name, ? [{
submenu: [ label: app.name,
{ role: 'about' }, submenu: [
{ type: 'separator' }, { role: 'about' },
{ role: 'services' }, { type: 'separator' },
{ type: 'separator' }, { role: 'services' },
{ role: 'hide' }, { type: 'separator' },
{ role: 'hideOthers' }, { role: 'hide' },
{ role: 'unhide' }, { role: 'hideOthers' },
{ type: 'separator' }, { role: 'unhide' },
{ role: 'quit' } { type: 'separator' },
] { role: 'quit' }
}] : []), ]
}]
: []),
// { role: 'fileMenu' } // { role: 'fileMenu' }
{ {
label: 'File', label: 'File',
@ -185,23 +187,25 @@ const template = [
{ role: 'cut' }, { role: 'cut' },
{ role: 'copy' }, { role: 'copy' },
{ role: 'paste' }, { role: 'paste' },
...(isMac ? [ ...(isMac
{ role: 'pasteAndMatchStyle' }, ? [
{ role: 'delete' }, { role: 'pasteAndMatchStyle' },
{ role: 'selectAll' }, { role: 'delete' },
{ type: 'separator' }, { role: 'selectAll' },
{ { type: 'separator' },
label: 'Speech', {
submenu: [ label: 'Speech',
{ role: 'startSpeaking' }, submenu: [
{ role: 'stopSpeaking' } { role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
] ]
} : [
] : [ { role: 'delete' },
{ role: 'delete' }, { type: 'separator' },
{ type: 'separator' }, { role: 'selectAll' }
{ role: 'selectAll' } ])
])
] ]
}, },
// { role: 'viewMenu' } // { role: 'viewMenu' }
@ -225,14 +229,16 @@ const template = [
submenu: [ submenu: [
{ role: 'minimize' }, { role: 'minimize' },
{ role: 'zoom' }, { role: 'zoom' },
...(isMac ? [ ...(isMac
{ type: 'separator' }, ? [
{ role: 'front' }, { type: 'separator' },
{ type: 'separator' }, { role: 'front' },
{ role: 'window' } { type: 'separator' },
] : [ { role: 'window' }
{ role: 'close' } ]
]) : [
{ role: 'close' }
])
] ]
}, },
{ {

View file

@ -1481,7 +1481,7 @@ app.whenReady().then(() => {
const protocol = session.fromPartition('some-partition').protocol const protocol = session.fromPartition('some-partition').protocol
if (!protocol.registerFileProtocol('atom', (request, callback) => { if (!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(path.join(__dirname, url)) })
})) { })) {
console.error('Failed to register protocol') console.error('Failed to register protocol')
} }

View file

@ -228,10 +228,10 @@ const win = new BrowserWindow(browserOptions)
// Navigate. // Navigate.
if (browserOptions.transparent) { if (browserOptions.transparent) {
win.loadURL(`file://${__dirname}/index.html`) win.loadFile('index.html')
} else { } else {
// No transparency, so we load a fallback that uses basic styles. // No transparency, so we load a fallback that uses basic styles.
win.loadURL(`file://${__dirname}/fallback.html`) win.loadFile('fallback.html')
} }
``` ```

View file

@ -864,7 +864,7 @@ app.whenReady().then(() => {
}) })
if (!result) { if (!result) {
// The device wasn't found so we need to either wait longer (eg until the // The device wasn't found so we need to either wait longer (eg until the
// device is turned on) or cancel the request by calling the callback // device is turned on) or cancel the request by calling the callback
// with an empty string. // with an empty string.
callback('') callback('')
} else { } else {

View file

@ -23,7 +23,7 @@ function createWindow () {
if (portList && portList.length > 0) { if (portList && portList.length > 0) {
callback(portList[0].portId) callback(portList[0].portId)
} else { } else {
// eslint-disable-next-line standard/no-callback-literal // eslint-disable-next-line n/no-callback-literal
callback('') // Could not find any matching devices callback('') // Could not find any matching devices
} }
}) })

View file

@ -24,9 +24,7 @@ function createWindow () {
event.preventDefault() event.preventDefault()
if (details.deviceList && details.deviceList.length > 0) { if (details.deviceList && details.deviceList.length > 0) {
const deviceToReturn = details.deviceList.find((device) => { const deviceToReturn = details.deviceList.find((device) => {
if (!grantedDeviceThroughPermHandler || (device.deviceId !== grantedDeviceThroughPermHandler.deviceId)) { return !grantedDeviceThroughPermHandler || (device.deviceId !== grantedDeviceThroughPermHandler.deviceId)
return true
}
}) })
if (deviceToReturn) { if (deviceToReturn) {
callback(deviceToReturn.deviceId) callback(deviceToReturn.deviceId)

View file

@ -3,9 +3,7 @@ const path = require('path')
async function handleFileOpen () { async function handleFileOpen () {
const { canceled, filePaths } = await dialog.showOpenDialog() const { canceled, filePaths } = await dialog.showOpenDialog()
if (canceled) { if (!canceled) {
} else {
return filePaths[0] return filePaths[0]
} }
} }

View file

@ -37,7 +37,7 @@ This installs all necessary packages for you and generates a `wdio.conf.js` conf
Update the capabilities in your configuration file to point to your Electron app binary: Update the capabilities in your configuration file to point to your Electron app binary:
```javascript title='wdio.conf.js' ```javascript title='wdio.conf.js'
export.config = { exports.config = {
// ... // ...
capabilities: [{ capabilities: [{
browserName: 'chrome', browserName: 'chrome',
@ -214,10 +214,10 @@ test('example test', async () => {
const isPackaged = await electronApp.evaluate(async ({ app }) => { const isPackaged = await electronApp.evaluate(async ({ app }) => {
// This runs in Electron's main process, parameter here is always // This runs in Electron's main process, parameter here is always
// the result of the require('electron') in the main app script. // the result of the require('electron') in the main app script.
return app.isPackaged; return app.isPackaged
}); })
expect(isPackaged).toBe(false); expect(isPackaged).toBe(false)
// Wait for the first BrowserWindow to open // Wait for the first BrowserWindow to open
// and return its Page object // and return its Page object
@ -226,7 +226,7 @@ test('example test', async () => {
// close app // close app
await electronApp.close() await electronApp.close()
}); })
``` ```
Then, run Playwright Test using `npx playwright test`. You should see the test pass in your Then, run Playwright Test using `npx playwright test`. You should see the test pass in your
@ -338,7 +338,7 @@ class TestDriver {
} }
} }
module.exports = { TestDriver }; module.exports = { TestDriver }
``` ```
In your app code, can then write a simple handler to receive RPC calls: In your app code, can then write a simple handler to receive RPC calls:

View file

@ -127,7 +127,7 @@ try {
authors: 'My App Inc.', authors: 'My App Inc.',
exe: 'myapp.exe', exe: 'myapp.exe',
certificateFile: './cert.pfx', certificateFile: './cert.pfx',
certificatePassword: 'this-is-a-secret', certificatePassword: 'this-is-a-secret'
}) })
console.log('It worked!') console.log('It worked!')
} catch (e) { } catch (e) {
@ -159,7 +159,7 @@ const msiCreator = new MSICreator({
version: '1.1.2', version: '1.1.2',
outputDirectory: '/path/to/output/folder', outputDirectory: '/path/to/output/folder',
certificateFile: './cert.pfx', certificateFile: './cert.pfx',
certificatePassword: 'this-is-a-secret', certificatePassword: 'this-is-a-secret'
}) })
// Step 2: Create a .wxs template file // Step 2: Create a .wxs template file

View file

@ -34,19 +34,19 @@ Using the [React Developer Tools][react-devtools] as an example:
API. For React Developer Tools `v4.9.0`, it looks something like: API. For React Developer Tools `v4.9.0`, it looks something like:
```javascript ```javascript
const { app, session } = require('electron') const { app, session } = require('electron')
const path = require('path') const path = require('path')
const os = require('os') const os = require('os')
// on macOS // on macOS
const reactDevToolsPath = path.join( const reactDevToolsPath = path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.9.0_0' '/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/4.9.0_0'
) )
app.whenReady().then(async () => { app.whenReady().then(async () => {
await session.defaultSession.loadExtension(reactDevToolsPath) await session.defaultSession.loadExtension(reactDevToolsPath)
}) })
``` ```
**Notes:** **Notes:**

View file

@ -51,10 +51,10 @@ sections.
In the main process, set an IPC listener on the `set-title` channel with the `ipcMain.on` API: In the main process, set an IPC listener on the `set-title` channel with the `ipcMain.on` API:
```javascript {6-10,22} title='main.js (Main Process)' ```javascript {6-10,22} title='main.js (Main Process)'
const {app, BrowserWindow, ipcMain} = require('electron') const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path') const path = require('path')
//... // ...
function handleSetTitle (event, title) { function handleSetTitle (event, title) {
const webContents = event.sender const webContents = event.sender
@ -74,8 +74,8 @@ function createWindow () {
app.whenReady().then(() => { app.whenReady().then(() => {
ipcMain.on('set-title', handleSetTitle) ipcMain.on('set-title', handleSetTitle)
createWindow() createWindow()
} })
//... // ...
``` ```
The above `handleSetTitle` callback has two parameters: an [IpcMainEvent][] structure and a The above `handleSetTitle` callback has two parameters: an [IpcMainEvent][] structure and a
@ -100,7 +100,7 @@ variable to your renderer process.
const { contextBridge, ipcRenderer } = require('electron') const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', { contextBridge.exposeInMainWorld('electronAPI', {
setTitle: (title) => ipcRenderer.send('set-title', title) setTitle: (title) => ipcRenderer.send('set-title', title)
}) })
``` ```
@ -142,9 +142,9 @@ script:
const setButton = document.getElementById('btn') const setButton = document.getElementById('btn')
const titleInput = document.getElementById('title') const titleInput = document.getElementById('title')
setButton.addEventListener('click', () => { setButton.addEventListener('click', () => {
const title = titleInput.value const title = titleInput.value
window.electronAPI.setTitle(title) window.electronAPI.setTitle(title)
}); })
``` ```
At this point, your demo should be fully functional. Try using the input field and see what happens At this point, your demo should be fully functional. Try using the input field and see what happens
@ -185,13 +185,11 @@ provided to the renderer process. Please refer to
const { BrowserWindow, dialog, ipcMain } = require('electron') const { BrowserWindow, dialog, ipcMain } = require('electron')
const path = require('path') const path = require('path')
//... // ...
async function handleFileOpen() { async function handleFileOpen () {
const { canceled, filePaths } = await dialog.showOpenDialog() const { canceled, filePaths } = await dialog.showOpenDialog()
if (canceled) { if (!canceled) {
return
} else {
return filePaths[0] return filePaths[0]
} }
} }
@ -209,7 +207,7 @@ app.whenReady(() => {
ipcMain.handle('dialog:openFile', handleFileOpen) ipcMain.handle('dialog:openFile', handleFileOpen)
createWindow() createWindow()
}) })
//... // ...
``` ```
:::tip on channel names :::tip on channel names
@ -379,7 +377,7 @@ module that uses the `webContents.send` API to send an IPC message from the main
target renderer. target renderer.
```javascript {11-26} title='main.js (Main Process)' ```javascript {11-26} title='main.js (Main Process)'
const {app, BrowserWindow, Menu, ipcMain} = require('electron') const { app, BrowserWindow, Menu, ipcMain } = require('electron')
const path = require('path') const path = require('path')
function createWindow () { function createWindow () {
@ -395,11 +393,11 @@ function createWindow () {
submenu: [ submenu: [
{ {
click: () => mainWindow.webContents.send('update-counter', 1), click: () => mainWindow.webContents.send('update-counter', 1),
label: 'Increment', label: 'Increment'
}, },
{ {
click: () => mainWindow.webContents.send('update-counter', -1), click: () => mainWindow.webContents.send('update-counter', -1),
label: 'Decrement', label: 'Decrement'
} }
] ]
} }
@ -408,8 +406,7 @@ function createWindow () {
mainWindow.loadFile('index.html') mainWindow.loadFile('index.html')
} }
//... // ...
``` ```
For the purposes of the tutorial, it's important to note that the `click` handler For the purposes of the tutorial, it's important to note that the `click` handler
@ -432,7 +429,7 @@ modules in the preload script to expose IPC functionality to the renderer proces
const { contextBridge, ipcRenderer } = require('electron') const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', { contextBridge.exposeInMainWorld('electronAPI', {
onUpdateCounter: (callback) => ipcRenderer.on('update-counter', callback) onUpdateCounter: (callback) => ipcRenderer.on('update-counter', callback)
}) })
``` ```
@ -452,12 +449,12 @@ rather than exposing it over the context bridge.
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
const counter = document.getElementById('counter') const counter = document.getElementById('counter')
ipcRenderer.on('update-counter', (_event, value) => { ipcRenderer.on('update-counter', (_event, value) => {
const oldValue = Number(counter.innerText) const oldValue = Number(counter.innerText)
const newValue = oldValue + value const newValue = oldValue + value
counter.innerText = newValue counter.innerText = newValue
}) })
}) })
``` ```
@ -493,9 +490,9 @@ so that the value of the `#counter` element is updated whenever we fire an `upda
const counter = document.getElementById('counter') const counter = document.getElementById('counter')
window.electronAPI.onUpdateCounter((_event, value) => { window.electronAPI.onUpdateCounter((_event, value) => {
const oldValue = Number(counter.innerText) const oldValue = Number(counter.innerText)
const newValue = oldValue + value const newValue = oldValue + value
counter.innerText = newValue counter.innerText = newValue
}) })
``` ```
@ -526,11 +523,11 @@ window.electronAPI.onUpdateCounter((event, value) => {
In the main process, listen for `counter-value` events and handle them appropriately. In the main process, listen for `counter-value` events and handle them appropriately.
```javascript title='main.js (Main Process)' ```javascript title='main.js (Main Process)'
//... // ...
ipcMain.on('counter-value', (_event, value) => { ipcMain.on('counter-value', (_event, value) => {
console.log(value) // will print value to Node console console.log(value) // will print value to Node console
}) })
//... // ...
``` ```
## Pattern 4: Renderer to renderer ## Pattern 4: Renderer to renderer

View file

@ -84,11 +84,11 @@ renderer process using the [addEventListener() API][addEventListener-api].
```javascript fiddle='docs/fiddles/features/keyboard-shortcuts/web-apis|focus=renderer.js' ```javascript fiddle='docs/fiddles/features/keyboard-shortcuts/web-apis|focus=renderer.js'
const handleKeyPress = (event) => { const handleKeyPress = (event) => {
// You can put code here to handle the keypress. // You can put code here to handle the keypress.
document.getElementById("last-keypress").innerText = event.key; document.getElementById('last-keypress').innerText = event.key
console.log(`You pressed ${event.key}`); console.log(`You pressed ${event.key}`)
} }
window.addEventListener('keyup', handleKeyPress, true); window.addEventListener('keyup', handleKeyPress, true)
``` ```
> Note: the third parameter `true` indicates that the listener will always receive > Note: the third parameter `true` indicates that the listener will always receive

View file

@ -29,7 +29,7 @@ const { app, BrowserWindow, Menu } = require('electron')
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
win.loadFile('index.html') win.loadFile('index.html')
@ -66,7 +66,6 @@ app.on('activate', () => {
createWindow() createWindow()
} }
}) })
``` ```
After launching the Electron application, right click the application icon. After launching the Electron application, right click the application icon.

View file

@ -17,29 +17,29 @@ Notification objects created using this module do not appear unless their `show(
method is called. method is called.
```js title='Main Process' ```js title='Main Process'
const { Notification } = require("electron"); const { Notification } = require('electron')
const NOTIFICATION_TITLE = "Basic Notification"; const NOTIFICATION_TITLE = 'Basic Notification'
const NOTIFICATION_BODY = "Notification from the Main process"; const NOTIFICATION_BODY = 'Notification from the Main process'
new Notification({ new Notification({
title: NOTIFICATION_TITLE, title: NOTIFICATION_TITLE,
body: NOTIFICATION_BODY, body: NOTIFICATION_BODY
}).show(); }).show()
``` ```
Here's a full example that you can open with Electron Fiddle: Here's a full example that you can open with Electron Fiddle:
```javascript fiddle='docs/fiddles/features/notifications/main' ```javascript fiddle='docs/fiddles/features/notifications/main'
const { Notification } = require("electron"); const { Notification } = require('electron')
const NOTIFICATION_TITLE = "Basic Notification"; const NOTIFICATION_TITLE = 'Basic Notification'
const NOTIFICATION_BODY = "Notification from the Main process"; const NOTIFICATION_BODY = 'Notification from the Main process'
new Notification({ new Notification({
title: NOTIFICATION_TITLE, title: NOTIFICATION_TITLE,
body: NOTIFICATION_BODY, body: NOTIFICATION_BODY
}).show(); }).show()
``` ```
### Show notifications in the renderer process ### Show notifications in the renderer process
@ -48,25 +48,25 @@ Notifications can be displayed directly from the renderer process with the
[web Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API). [web Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API).
```js title='Renderer Process' ```js title='Renderer Process'
const NOTIFICATION_TITLE = "Title"; const NOTIFICATION_TITLE = 'Title'
const NOTIFICATION_BODY = const NOTIFICATION_BODY =
"Notification from the Renderer process. Click to log to console."; 'Notification from the Renderer process. Click to log to console.'
const CLICK_MESSAGE = "Notification clicked"; const CLICK_MESSAGE = 'Notification clicked'
new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }).onclick = new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }).onclick =
() => console.log(CLICK_MESSAGE); () => console.log(CLICK_MESSAGE)
``` ```
Here's a full example that you can open with Electron Fiddle: Here's a full example that you can open with Electron Fiddle:
```javascript fiddle='docs/fiddles/features/notifications/renderer' ```javascript fiddle='docs/fiddles/features/notifications/renderer'
const NOTIFICATION_TITLE = "Title"; const NOTIFICATION_TITLE = 'Title'
const NOTIFICATION_BODY = const NOTIFICATION_BODY =
"Notification from the Renderer process. Click to log to console."; 'Notification from the Renderer process. Click to log to console.'
const CLICK_MESSAGE = "Notification clicked"; const CLICK_MESSAGE = 'Notification clicked'
new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }).onclick = new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }).onclick =
() => console.log(CLICK_MESSAGE); () => console.log(CLICK_MESSAGE)
``` ```
## Platform considerations ## Platform considerations

View file

@ -158,13 +158,13 @@ A preload script can be attached to the main process in the `BrowserWindow` cons
```js title='main.js' ```js title='main.js'
const { BrowserWindow } = require('electron') const { BrowserWindow } = require('electron')
//... // ...
const win = new BrowserWindow({ const win = new BrowserWindow({
webPreferences: { webPreferences: {
preload: 'path/to/preload.js', preload: 'path/to/preload.js'
}, }
}) })
//... // ...
``` ```
Because the preload script shares a global [`Window`][window-mdn] interface with the Because the preload script shares a global [`Window`][window-mdn] interface with the
@ -177,7 +177,7 @@ the [`contextIsolation`][context-isolation] default.
```js title='preload.js' ```js title='preload.js'
window.myAPI = { window.myAPI = {
desktop: true, desktop: true
} }
``` ```
@ -196,7 +196,7 @@ securely:
const { contextBridge } = require('electron') const { contextBridge } = require('electron')
contextBridge.exposeInMainWorld('myAPI', { contextBridge.exposeInMainWorld('myAPI', {
desktop: true, desktop: true
}) })
``` ```

View file

@ -29,7 +29,7 @@ To set the represented file of window, you can use the
```javascript fiddle='docs/fiddles/features/represented-file' ```javascript fiddle='docs/fiddles/features/represented-file'
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const os = require('os'); const os = require('os')
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({

View file

@ -742,19 +742,19 @@ You should be validating the `sender` of **all** IPC messages by default.
```js title='main.js (Main Process)' ```js title='main.js (Main Process)'
// Bad // Bad
ipcMain.handle('get-secrets', () => { ipcMain.handle('get-secrets', () => {
return getSecrets(); return getSecrets()
}); })
// Good // Good
ipcMain.handle('get-secrets', (e) => { ipcMain.handle('get-secrets', (e) => {
if (!validateSender(e.senderFrame)) return null; if (!validateSender(e.senderFrame)) return null
return getSecrets(); return getSecrets()
}); })
function validateSender(frame) { function validateSender (frame) {
// Value the host of the URL using an actual URL parser and an allowlist // Value the host of the URL using an actual URL parser and an allowlist
if ((new URL(frame.url)).host === 'electronjs.org') return true; if ((new URL(frame.url)).host === 'electronjs.org') return true
return false; return false
} }
``` ```

View file

@ -125,7 +125,7 @@ main process entry point is configured correctly. Create a `main.js` file in the
of your project with a single line of code: of your project with a single line of code:
```js title='main.js' ```js title='main.js'
console.log(`Hello from Electron 👋`) console.log('Hello from Electron 👋')
``` ```
Because Electron's main process is a Node.js runtime, you can execute arbitrary Node.js code Because Electron's main process is a Node.js runtime, you can execute arbitrary Node.js code
@ -199,7 +199,7 @@ const { app, BrowserWindow } = require('electron')
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
win.loadFile('index.html') win.loadFile('index.html')
@ -247,7 +247,7 @@ The `createWindow()` function loads your web page into a new BrowserWindow insta
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
win.loadFile('index.html') win.loadFile('index.html')

View file

@ -73,7 +73,7 @@ const { contextBridge } = require('electron')
contextBridge.exposeInMainWorld('versions', { contextBridge.exposeInMainWorld('versions', {
node: () => process.versions.node, node: () => process.versions.node,
chrome: () => process.versions.chrome, chrome: () => process.versions.chrome,
electron: () => process.versions.electron, electron: () => process.versions.electron
// we can also expose variables, not just functions // we can also expose variables, not just functions
}) })
``` ```
@ -90,8 +90,8 @@ const createWindow = () => {
width: 800, width: 800,
height: 600, height: 600,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js')
}, }
}) })
win.loadFile('index.html') win.loadFile('index.html')
@ -183,7 +183,7 @@ contextBridge.exposeInMainWorld('versions', {
node: () => process.versions.node, node: () => process.versions.node,
chrome: () => process.versions.chrome, chrome: () => process.versions.chrome,
electron: () => process.versions.electron, electron: () => process.versions.electron,
ping: () => ipcRenderer.invoke('ping'), ping: () => ipcRenderer.invoke('ping')
// we can also expose variables, not just functions // we can also expose variables, not just functions
}) })
``` ```
@ -211,8 +211,8 @@ const createWindow = () => {
width: 800, width: 800,
height: 600, height: 600,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js')
}, }
}) })
win.loadFile('index.html') win.loadFile('index.html')
} }

View file

@ -153,14 +153,14 @@ For more information on code signing, check out the
module.exports = { module.exports = {
packagerConfig: { packagerConfig: {
osxSign: {}, osxSign: {},
//... // ...
osxNotarize: { osxNotarize: {
tool: 'notarytool', tool: 'notarytool',
appleId: process.env.APPLE_ID, appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_PASSWORD, appleIdPassword: process.env.APPLE_PASSWORD,
teamId: process.env.APPLE_TEAM_ID, teamId: process.env.APPLE_TEAM_ID
} }
//... // ...
} }
} }
``` ```
@ -170,17 +170,17 @@ module.exports = {
```js title='forge.config.js' ```js title='forge.config.js'
module.exports = { module.exports = {
//... // ...
makers: [ makers: [
{ {
name: '@electron-forge/maker-squirrel', name: '@electron-forge/maker-squirrel',
config: { config: {
certificateFile: './cert.pfx', certificateFile: './cert.pfx',
certificatePassword: process.env.CERTIFICATE_PASSWORD, certificatePassword: process.env.CERTIFICATE_PASSWORD
}, }
}, }
], ]
//... // ...
} }
``` ```

View file

@ -86,13 +86,13 @@ module.exports = {
config: { config: {
repository: { repository: {
owner: 'github-user-name', owner: 'github-user-name',
name: 'github-repo-name', name: 'github-repo-name'
}, },
prerelease: false, prerelease: false,
draft: true, draft: true
}, }
}, }
], ]
} }
``` ```

View file

@ -121,7 +121,7 @@ autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
title: 'Application Update', title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName, message: process.platform === 'win32' ? releaseNotes : releaseName,
detail: detail:
'A new version has been downloaded. Restart the application to apply the updates.', 'A new version has been downloaded. Restart the application to apply the updates.'
} }
dialog.showMessageBox(dialogOpts).then((returnValue) => { dialog.showMessageBox(dialogOpts).then((returnValue) => {

View file

@ -9,7 +9,7 @@
"@electron/docs-parser": "^1.1.0", "@electron/docs-parser": "^1.1.0",
"@electron/fiddle-core": "^1.0.4", "@electron/fiddle-core": "^1.0.4",
"@electron/github-app-auth": "^1.5.0", "@electron/github-app-auth": "^1.5.0",
"@electron/lint-roller": "^1.1.0", "@electron/lint-roller": "^1.2.1",
"@electron/typescript-definitions": "^8.14.0", "@electron/typescript-definitions": "^8.14.0",
"@octokit/rest": "^19.0.7", "@octokit/rest": "^19.0.7",
"@primer/octicons": "^10.0.0", "@primer/octicons": "^10.0.0",
@ -44,6 +44,7 @@
"eslint-plugin-import": "^2.22.0", "eslint-plugin-import": "^2.22.0",
"eslint-plugin-mocha": "^7.0.1", "eslint-plugin-mocha": "^7.0.1",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1", "eslint-plugin-standard": "^4.0.1",
"eslint-plugin-typescript": "^0.14.0", "eslint-plugin-typescript": "^0.14.0",
"events": "^3.2.0", "events": "^3.2.0",
@ -64,7 +65,6 @@
"remark-preset-lint-markdown-style-guide": "^4.0.0", "remark-preset-lint-markdown-style-guide": "^4.0.0",
"semver": "^5.6.0", "semver": "^5.6.0",
"shx": "^0.3.2", "shx": "^0.3.2",
"standard-markdown": "^6.0.0",
"stream-json": "^1.7.1", "stream-json": "^1.7.1",
"tap-xunit": "^2.4.1", "tap-xunit": "^2.4.1",
"temp": "^0.8.3", "temp": "^0.8.3",
@ -93,7 +93,7 @@
"lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"", "lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"",
"lint:docs-relative-links": "electron-lint-markdown-links --root docs \"**/*.md\"", "lint:docs-relative-links": "electron-lint-markdown-links --root docs \"**/*.md\"",
"lint:markdownlint": "electron-markdownlint \"*.md\" \"docs/**/*.md\"", "lint:markdownlint": "electron-markdownlint \"*.md\" \"docs/**/*.md\"",
"lint:js-in-markdown": "standard-markdown docs", "lint:js-in-markdown": "electron-lint-markdown-standard --root docs \"**/*.md\"",
"create-api-json": "node script/create-api-json.js", "create-api-json": "node script/create-api-json.js",
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --api=electron-api.json && node spec/ts-smoke/runner.js", "create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --api=electron-api.json && node spec/ts-smoke/runner.js",
"gn-typescript-definitions": "npm run create-typescript-definitions && shx cp electron.d.ts", "gn-typescript-definitions": "npm run create-typescript-definitions && shx cp electron.d.ts",

1328
yarn.lock

File diff suppressed because it is too large Load diff