chore: update to standard 12
This commit is contained in:
parent
9e85bdb02c
commit
558fff69e7
198 changed files with 4455 additions and 2940 deletions
|
@ -16,7 +16,7 @@ using the [`register`](global-shortcut.md#globalshortcutregisteraccelerator-call
|
|||
method, i.e.
|
||||
|
||||
```javascript
|
||||
const {app, globalShortcut} = require('electron')
|
||||
const { app, globalShortcut } = require('electron')
|
||||
|
||||
app.on('ready', () => {
|
||||
// Register a 'CommandOrControl+Y' shortcut listener.
|
||||
|
|
|
@ -8,7 +8,7 @@ The following example shows how to quit the application when the last window is
|
|||
closed:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit()
|
||||
})
|
||||
|
@ -268,7 +268,7 @@ certificate you should prevent the default behavior with
|
|||
`event.preventDefault()` and call `callback(true)`.
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||
if (url === 'https://github.com') {
|
||||
|
@ -300,7 +300,7 @@ and `callback` can be called with an entry filtered from the list. Using
|
|||
certificate from the store.
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
app.on('select-client-certificate', (event, webContents, url, list, callback) => {
|
||||
event.preventDefault()
|
||||
|
@ -335,7 +335,7 @@ should prevent the default behavior with `event.preventDefault()` and call
|
|||
`callback(username, password)` with the credentials.
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
app.on('login', (event, webContents, request, authInfo, callback) => {
|
||||
event.preventDefault()
|
||||
|
@ -375,7 +375,7 @@ Returns:
|
|||
Emitted when Electron has created a new `session`.
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
app.on('session-created', (event, session) => {
|
||||
console.log(session)
|
||||
|
@ -448,9 +448,9 @@ An example of restarting current instance immediately and adding a new command
|
|||
line argument to the new instance:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
app.relaunch({args: process.argv.slice(1).concat(['--relaunch'])})
|
||||
app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) })
|
||||
app.exit(0)
|
||||
```
|
||||
|
||||
|
@ -712,7 +712,7 @@ items can be obtained using `app.getJumpListSettings()`.
|
|||
Here's a very simple example of creating a custom Jump List:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
|
||||
app.setJumpList([
|
||||
{
|
||||
|
@ -798,7 +798,7 @@ An example of activating the window of primary instance when a second instance
|
|||
starts:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
let myWindow = null
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
|
|
|
@ -49,17 +49,17 @@ app.getAppMetrics()
|
|||
|
||||
// Deprecated
|
||||
const metrics = app.getAppMetrics()
|
||||
const {memory} = metrics[0] // Deprecated property
|
||||
const { memory } = metrics[0] // Deprecated property
|
||||
```
|
||||
|
||||
## `BrowserWindow`
|
||||
|
||||
```js
|
||||
// Deprecated
|
||||
let optionsA = {webPreferences: {blinkFeatures: ''}}
|
||||
let optionsA = { webPreferences: { blinkFeatures: '' } }
|
||||
let windowA = new BrowserWindow(optionsA)
|
||||
// Replace with
|
||||
let optionsB = {webPreferences: {enableBlinkFeatures: ''}}
|
||||
let optionsB = { webPreferences: { enableBlinkFeatures: '' } }
|
||||
let windowB = new BrowserWindow(optionsB)
|
||||
|
||||
// Deprecated
|
||||
|
@ -175,9 +175,9 @@ tray.setHighlightMode('off')
|
|||
|
||||
```js
|
||||
// Deprecated
|
||||
webContents.openDevTools({detach: true})
|
||||
webContents.openDevTools({ detach: true })
|
||||
// Replace with
|
||||
webContents.openDevTools({mode: 'detach'})
|
||||
webContents.openDevTools({ mode: 'detach' })
|
||||
|
||||
// Removed
|
||||
webContents.setSize(options)
|
||||
|
@ -190,12 +190,12 @@ webContents.setSize(options)
|
|||
// Deprecated
|
||||
webFrame.registerURLSchemeAsSecure('app')
|
||||
// Replace with
|
||||
protocol.registerStandardSchemes(['app'], {secure: true})
|
||||
protocol.registerStandardSchemes(['app'], { secure: true })
|
||||
|
||||
// Deprecated
|
||||
webFrame.registerURLSchemeAsPrivileged('app', {secure: true})
|
||||
webFrame.registerURLSchemeAsPrivileged('app', { secure: true })
|
||||
// Replace with
|
||||
protocol.registerStandardSchemes(['app'], {secure: true})
|
||||
protocol.registerStandardSchemes(['app'], { secure: true })
|
||||
```
|
||||
|
||||
## `<webview>`
|
||||
|
@ -232,10 +232,10 @@ The following list includes the breaking API changes made in Electron 2.0.
|
|||
|
||||
```js
|
||||
// Deprecated
|
||||
let optionsA = {titleBarStyle: 'hidden-inset'}
|
||||
let optionsA = { titleBarStyle: 'hidden-inset' }
|
||||
let windowA = new BrowserWindow(optionsA)
|
||||
// Replace with
|
||||
let optionsB = {titleBarStyle: 'hiddenInset'}
|
||||
let optionsB = { titleBarStyle: 'hiddenInset' }
|
||||
let windowB = new BrowserWindow(optionsB)
|
||||
```
|
||||
|
||||
|
@ -245,7 +245,7 @@ let windowB = new BrowserWindow(optionsB)
|
|||
// Removed
|
||||
menu.popup(browserWindow, 100, 200, 2)
|
||||
// Replaced with
|
||||
menu.popup(browserWindow, {x: 100, y: 200, positioningItem: 2})
|
||||
menu.popup(browserWindow, { x: 100, y: 200, positioningItem: 2 })
|
||||
```
|
||||
|
||||
## `nativeImage`
|
||||
|
|
|
@ -16,9 +16,9 @@ relative to its owning window. It is meant to be an alternative to the
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
const {BrowserView, BrowserWindow} = require('electron')
|
||||
const { BrowserView, BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.on('closed', () => {
|
||||
win = null
|
||||
})
|
||||
|
|
|
@ -6,12 +6,12 @@ Process: [Main](../glossary.md#main-process)
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
// Or use `remote` from the renderer process.
|
||||
// const {BrowserWindow} = require('electron').remote
|
||||
// const { BrowserWindow } = require('electron').remote
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.on('closed', () => {
|
||||
win = null
|
||||
})
|
||||
|
@ -40,8 +40,8 @@ process has rendered the page for the first time if the window has not been show
|
|||
the window after this event will have no visual flash:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({show: false})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ show: false })
|
||||
win.once('ready-to-show', () => {
|
||||
win.show()
|
||||
})
|
||||
|
@ -58,9 +58,9 @@ the app feel slow. In this case, it is recommended to show the window
|
|||
immediately, and use a `backgroundColor` close to your app's background:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow({backgroundColor: '#2e2c29'})
|
||||
let win = new BrowserWindow({ backgroundColor: '#2e2c29' })
|
||||
win.loadURL('https://github.com')
|
||||
```
|
||||
|
||||
|
@ -72,10 +72,10 @@ to set `backgroundColor` to make app feel more native.
|
|||
By using `parent` option, you can create child windows:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let top = new BrowserWindow()
|
||||
let child = new BrowserWindow({parent: top})
|
||||
let child = new BrowserWindow({ parent: top })
|
||||
child.show()
|
||||
top.show()
|
||||
```
|
||||
|
@ -88,9 +88,9 @@ A modal window is a child window that disables parent window, to create a modal
|
|||
window, you have to set both `parent` and `modal` options:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let child = new BrowserWindow({parent: top, modal: true, show: false})
|
||||
let child = new BrowserWindow({ parent: top, modal: true, show: false })
|
||||
child.loadURL('https://github.com')
|
||||
child.once('ready-to-show', () => {
|
||||
child.show()
|
||||
|
@ -558,7 +558,7 @@ Commands are lowercased, underscores are replaced with hyphens, and the
|
|||
e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.on('app-command', (e, cmd) => {
|
||||
// Navigate the window back when the user hits their mouse back button
|
||||
|
@ -692,7 +692,7 @@ an Object containing `name` and `version` properties.
|
|||
To check if a DevTools extension is installed you can run the following:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let installed = BrowserWindow.getDevToolsExtensions().hasOwnProperty('devtron')
|
||||
console.log(installed)
|
||||
|
@ -706,9 +706,9 @@ is emitted.
|
|||
Objects created with `new BrowserWindow` have the following properties:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
// In this example `win` is our instance
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL('https://github.com')
|
||||
```
|
||||
|
||||
|
@ -1085,7 +1085,7 @@ attached just below the window frame, but you may want to display them beneath
|
|||
a HTML-rendered toolbar. For example:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
let toolbarRect = document.getElementById('toolbar').getBoundingClientRect()
|
||||
|
@ -1354,7 +1354,7 @@ The `flags` is an array that can include following `String`s:
|
|||
Sets the region of the window to show as the thumbnail image displayed when
|
||||
hovering over the window in the taskbar. You can reset the thumbnail to be
|
||||
the entire window by specifying an empty region:
|
||||
`{x: 0, y: 0, width: 0, height: 0}`.
|
||||
`{ x: 0, y: 0, width: 0, height: 0 }`.
|
||||
|
||||
#### `win.setThumbnailToolTip(toolTip)` _Windows_
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ your app's main script before the [ready][ready] event of the [app][app] module
|
|||
is emitted:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
app.commandLine.appendSwitch('remote-debugging-port', '8315')
|
||||
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1')
|
||||
|
||||
|
@ -72,7 +72,7 @@ list of hosts. This flag has an effect only if used in tandem with
|
|||
For example:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
app.commandLine.appendSwitch('proxy-bypass-list', '<local>;*.google.com;*foo.com;1.2.3.4:5678')
|
||||
```
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer
|
|||
The following example shows how to write a string to the clipboard:
|
||||
|
||||
```javascript
|
||||
const {clipboard} = require('electron')
|
||||
const { clipboard } = require('electron')
|
||||
clipboard.writeText('Example String')
|
||||
```
|
||||
|
||||
|
@ -15,7 +15,7 @@ On X Window systems, there is also a selection clipboard. To manipulate it
|
|||
you need to pass `selection` to each method:
|
||||
|
||||
```javascript
|
||||
const {clipboard} = require('electron')
|
||||
const { clipboard } = require('electron')
|
||||
clipboard.writeText('Example String', 'selection')
|
||||
console.log(clipboard.readText('selection'))
|
||||
```
|
||||
|
@ -141,7 +141,7 @@ Returns `String[]` - An array of supported formats for the clipboard `type`.
|
|||
Returns `Boolean` - Whether the clipboard supports the specified `format`.
|
||||
|
||||
```javascript
|
||||
const {clipboard} = require('electron')
|
||||
const { clipboard } = require('electron')
|
||||
console.log(clipboard.has('<p>selection</p>'))
|
||||
```
|
||||
|
||||
|
@ -176,7 +176,7 @@ Writes the `buffer` into the clipboard as `format`.
|
|||
* `type` String (optional)
|
||||
|
||||
```javascript
|
||||
const {clipboard} = require('electron')
|
||||
clipboard.write({text: 'test', html: '<b>test</b>'})
|
||||
const { clipboard } = require('electron')
|
||||
clipboard.write({ text: 'test', html: '<b>test</b>' })
|
||||
```
|
||||
Writes `data` to the clipboard.
|
||||
|
|
|
@ -14,7 +14,7 @@ module is emitted.
|
|||
|
||||
|
||||
```javascript
|
||||
const {app, contentTracing} = require('electron')
|
||||
const { app, contentTracing } = require('electron')
|
||||
|
||||
app.on('ready', () => {
|
||||
const options = {
|
||||
|
|
|
@ -10,7 +10,7 @@ a `Session`.
|
|||
For example:
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
|
||||
// Query all cookies.
|
||||
session.defaultSession.cookies.get({}, (error, cookies) => {
|
||||
|
@ -18,13 +18,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(error, 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)
|
||||
})
|
||||
|
|
|
@ -8,7 +8,7 @@ The following is an example of automatically submitting a crash report to a
|
|||
remote server:
|
||||
|
||||
```javascript
|
||||
const {crashReporter} = require('electron')
|
||||
const { crashReporter } = require('electron')
|
||||
|
||||
crashReporter.start({
|
||||
productName: 'YourName',
|
||||
|
@ -71,18 +71,18 @@ first call `start` you can call `addExtraParameter` on macOS or call `start`
|
|||
again with the new/updated `extra` parameters on Linux and Windows.
|
||||
|
||||
```js
|
||||
const args = [
|
||||
`--reporter-url=${submitURL}`,
|
||||
`--application-name=${productName}`,
|
||||
`--crashes-directory=${crashesDirectory}`
|
||||
]
|
||||
const env = {
|
||||
ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
||||
}
|
||||
spawn(process.execPath, args, {
|
||||
env: env,
|
||||
detached: true
|
||||
})
|
||||
const args = [
|
||||
`--reporter-url=${submitURL}`,
|
||||
`--application-name=${productName}`,
|
||||
`--crashes-directory=${crashesDirectory}`
|
||||
]
|
||||
const env = {
|
||||
ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
||||
}
|
||||
spawn(process.execPath, args, {
|
||||
env: env,
|
||||
detached: true
|
||||
})
|
||||
```
|
||||
|
||||
**Note:** On macOS, Electron uses a new `crashpad` client for crash collection and reporting.
|
||||
|
|
|
@ -8,7 +8,7 @@ Chrome Developer Tools has a [special binding][rdp] available at JavaScript
|
|||
runtime that allows interacting with pages and instrumenting them.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
try {
|
||||
|
|
|
@ -10,9 +10,9 @@ title is `Electron`:
|
|||
|
||||
```javascript
|
||||
// In the renderer process.
|
||||
const {desktopCapturer} = require('electron')
|
||||
const { desktopCapturer } = require('electron')
|
||||
|
||||
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
||||
desktopCapturer.getSources({ types: ['window', 'screen'] }, (error, sources) => {
|
||||
if (error) throw error
|
||||
for (let i = 0; i < sources.length; ++i) {
|
||||
if (sources[i].name === 'Electron') {
|
||||
|
@ -28,9 +28,8 @@ desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
|||
maxHeight: 720
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((stream) => handleStream(stream))
|
||||
.catch((e) => handleError(e))
|
||||
}).then((stream) => handleStream(stream))
|
||||
.catch((e) => handleError(e))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,15 @@ Process: [Main](../glossary.md#main-process)
|
|||
An example of showing a dialog to select multiple files and directories:
|
||||
|
||||
```javascript
|
||||
const {dialog} = require('electron')
|
||||
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}))
|
||||
const { dialog } = require('electron')
|
||||
console.log(dialog.showOpenDialog({ properties: ['openFile', 'openDirectory', 'multiSelections'] }))
|
||||
```
|
||||
|
||||
The Dialog is opened from Electron's main thread. If you want to use the dialog
|
||||
object from a renderer process, remember to access it using the remote:
|
||||
|
||||
```javascript
|
||||
const {dialog} = require('electron').remote
|
||||
const { dialog } = require('electron').remote
|
||||
console.log(dialog)
|
||||
```
|
||||
|
||||
|
@ -66,10 +66,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: ['*'] }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
|
|
@ -10,7 +10,7 @@ control the download item.
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.webContents.session.on('will-download', (event, item, webContents) => {
|
||||
// Set the save path, making Electron not to prompt a save dialog.
|
||||
|
|
|
@ -14,8 +14,8 @@ 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})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ width: 800, height: 600, frame: false })
|
||||
win.show()
|
||||
```
|
||||
|
||||
|
@ -33,8 +33,8 @@ You can do so by specifying the `titleBarStyle` option:
|
|||
Results in a hidden title bar and a full size content window, yet the title bar still has the standard window controls (“traffic lights”) in the top left.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({titleBarStyle: 'hidden'})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ titleBarStyle: 'hidden' })
|
||||
win.show()
|
||||
```
|
||||
|
||||
|
@ -43,8 +43,8 @@ win.show()
|
|||
Results in a hidden title bar with an alternative look where the traffic light buttons are slightly more inset from the window edge.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({titleBarStyle: 'hiddenInset'})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ titleBarStyle: 'hiddenInset' })
|
||||
win.show()
|
||||
```
|
||||
|
||||
|
@ -56,8 +56,8 @@ with mouse events that occur with the standard window toolbar buttons. This
|
|||
option is only applicable for frameless windows.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({titleBarStyle: 'customButtonsOnHover', frame: false})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ titleBarStyle: 'customButtonsOnHover', frame: false })
|
||||
win.show()
|
||||
```
|
||||
|
||||
|
@ -67,8 +67,8 @@ By setting the `transparent` option to `true`, you can also make the frameless
|
|||
window transparent:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({transparent: true, frame: false})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ transparent: true, frame: false })
|
||||
win.show()
|
||||
```
|
||||
|
||||
|
@ -98,7 +98,7 @@ events, you can call the [win.setIgnoreMouseEvents(ignore)][ignore-mouse-events]
|
|||
API:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.setIgnoreMouseEvents(true)
|
||||
```
|
||||
|
@ -114,7 +114,7 @@ allowing events such as `mouseleave` to be emitted:
|
|||
let win = require('electron').remote.getCurrentWindow()
|
||||
let el = document.getElementById('clickThroughElement')
|
||||
el.addEventListener('mouseenter', () => {
|
||||
win.setIgnoreMouseEvents(true, {forward: true})
|
||||
win.setIgnoreMouseEvents(true, { forward: true })
|
||||
})
|
||||
el.addEventListener('mouseleave', () => {
|
||||
win.setIgnoreMouseEvents(false)
|
||||
|
|
|
@ -13,7 +13,7 @@ not have the keyboard focus. You should not use this module until the `ready`
|
|||
event of the app module is emitted.
|
||||
|
||||
```javascript
|
||||
const {app, globalShortcut} = require('electron')
|
||||
const { app, globalShortcut } = require('electron')
|
||||
|
||||
app.on('ready', () => {
|
||||
// Register a 'CommandOrControl+X' shortcut listener.
|
||||
|
|
|
@ -25,7 +25,7 @@ processes:
|
|||
|
||||
```javascript
|
||||
// In main process.
|
||||
const {ipcMain} = require('electron')
|
||||
const { ipcMain } = require('electron')
|
||||
ipcMain.on('asynchronous-message', (event, arg) => {
|
||||
console.log(arg) // prints "ping"
|
||||
event.sender.send('asynchronous-reply', 'pong')
|
||||
|
@ -39,7 +39,7 @@ ipcMain.on('synchronous-message', (event, arg) => {
|
|||
|
||||
```javascript
|
||||
// In renderer process (web page).
|
||||
const {ipcRenderer} = require('electron')
|
||||
const { ipcRenderer } = require('electron')
|
||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
|
||||
|
||||
ipcRenderer.on('asynchronous-reply', (event, arg) => {
|
||||
|
|
|
@ -149,42 +149,42 @@ An example of creating the application menu in the main process with the
|
|||
simple template API:
|
||||
|
||||
```javascript
|
||||
const {app, Menu} = require('electron')
|
||||
const { app, Menu } = require('electron')
|
||||
|
||||
const template = [
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{role: 'undo'},
|
||||
{role: 'redo'},
|
||||
{type: 'separator'},
|
||||
{role: 'cut'},
|
||||
{role: 'copy'},
|
||||
{role: 'paste'},
|
||||
{role: 'pasteandmatchstyle'},
|
||||
{role: 'delete'},
|
||||
{role: 'selectall'}
|
||||
{ role: 'undo' },
|
||||
{ role: 'redo' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'pasteandmatchstyle' },
|
||||
{ role: 'delete' },
|
||||
{ role: 'selectall' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{role: 'reload'},
|
||||
{role: 'forcereload'},
|
||||
{role: 'toggledevtools'},
|
||||
{type: 'separator'},
|
||||
{role: 'resetzoom'},
|
||||
{role: 'zoomin'},
|
||||
{role: 'zoomout'},
|
||||
{type: 'separator'},
|
||||
{role: 'togglefullscreen'}
|
||||
{ role: 'reload' },
|
||||
{ role: 'forcereload' },
|
||||
{ role: 'toggledevtools' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'resetzoom' },
|
||||
{ role: 'zoomin' },
|
||||
{ role: 'zoomout' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'togglefullscreen' }
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'window',
|
||||
submenu: [
|
||||
{role: 'minimize'},
|
||||
{role: 'close'}
|
||||
{ role: 'minimize' },
|
||||
{ role: 'close' }
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -202,37 +202,37 @@ if (process.platform === 'darwin') {
|
|||
template.unshift({
|
||||
label: app.getName(),
|
||||
submenu: [
|
||||
{role: 'about'},
|
||||
{type: 'separator'},
|
||||
{role: 'services', submenu: []},
|
||||
{type: 'separator'},
|
||||
{role: 'hide'},
|
||||
{role: 'hideothers'},
|
||||
{role: 'unhide'},
|
||||
{type: 'separator'},
|
||||
{role: 'quit'}
|
||||
{ role: 'about' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'services', submenu: [] },
|
||||
{ type: 'separator' },
|
||||
{ role: 'hide' },
|
||||
{ role: 'hideothers' },
|
||||
{ role: 'unhide' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'quit' }
|
||||
]
|
||||
})
|
||||
|
||||
// Edit menu
|
||||
template[1].submenu.push(
|
||||
{type: 'separator'},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
{role: 'startspeaking'},
|
||||
{role: 'stopspeaking'}
|
||||
{ role: 'startspeaking' },
|
||||
{ role: 'stopspeaking' }
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
// Window menu
|
||||
template[3].submenu = [
|
||||
{role: 'close'},
|
||||
{role: 'minimize'},
|
||||
{role: 'zoom'},
|
||||
{type: 'separator'},
|
||||
{role: 'front'}
|
||||
{ role: 'close' },
|
||||
{ role: 'minimize' },
|
||||
{ role: 'zoom' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'front' }
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -249,17 +249,17 @@ the user right clicks the page:
|
|||
```html
|
||||
<!-- index.html -->
|
||||
<script>
|
||||
const {remote} = require('electron')
|
||||
const {Menu, MenuItem} = remote
|
||||
const { remote } = require('electron')
|
||||
const { Menu, MenuItem } = 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()
|
||||
menu.popup({window: remote.getCurrentWindow()})
|
||||
menu.popup({ window: remote.getCurrentWindow() })
|
||||
}, false)
|
||||
</script>
|
||||
```
|
||||
|
|
|
@ -11,17 +11,17 @@ For example, when creating a tray or setting a window's icon, you can pass an
|
|||
image file path as a `String`:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow, Tray} = require('electron')
|
||||
const { BrowserWindow, Tray } = require('electron')
|
||||
|
||||
const appIcon = new Tray('/Users/somebody/images/icon.png')
|
||||
let win = new BrowserWindow({icon: '/Users/somebody/images/window.png'})
|
||||
let win = new BrowserWindow({ icon: '/Users/somebody/images/window.png' })
|
||||
console.log(appIcon, win)
|
||||
```
|
||||
|
||||
Or read the image from the clipboard which returns a `NativeImage`:
|
||||
|
||||
```javascript
|
||||
const {clipboard, Tray} = require('electron')
|
||||
const { clipboard, Tray } = require('electron')
|
||||
const image = clipboard.readImage()
|
||||
const appIcon = new Tray(image)
|
||||
console.log(appIcon)
|
||||
|
@ -73,7 +73,7 @@ images/
|
|||
|
||||
|
||||
```javascript
|
||||
const {Tray} = require('electron')
|
||||
const { Tray } = require('electron')
|
||||
let appIcon = new Tray('/Users/somebody/images/icon.png')
|
||||
console.log(appIcon)
|
||||
```
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
Process: [Main](../glossary.md#main-process)
|
||||
|
||||
```javascript
|
||||
const {netLog} = require('electron')
|
||||
const { netLog } = require('electron')
|
||||
console.log('Start recording net-logs')
|
||||
netLog.startLogging('/path/to/net-log')
|
||||
// After some network events
|
||||
|
|
|
@ -30,9 +30,9 @@ For instance, the following example quickly shows how the `net` API might be
|
|||
used:
|
||||
|
||||
```javascript
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
app.on('ready', () => {
|
||||
const {net} = require('electron')
|
||||
const { net } = require('electron')
|
||||
const request = net.request('https://github.com')
|
||||
request.on('response', (response) => {
|
||||
console.log(`STATUS: ${response.statusCode}`)
|
||||
|
|
|
@ -11,7 +11,7 @@ For example:
|
|||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const {app} = electron
|
||||
const { app } = electron
|
||||
|
||||
app.on('ready', () => {
|
||||
electron.powerMonitor.on('suspend', () => {
|
||||
|
|
|
@ -7,7 +7,7 @@ Process: [Main](../glossary.md#main-process)
|
|||
For example:
|
||||
|
||||
```javascript
|
||||
const {powerSaveBlocker} = require('electron')
|
||||
const { powerSaveBlocker } = require('electron')
|
||||
|
||||
const id = powerSaveBlocker.start('prevent-display-sleep')
|
||||
console.log(powerSaveBlocker.isStarted(id))
|
||||
|
|
|
@ -8,13 +8,13 @@ An example of implementing a protocol that has the same effect as the
|
|||
`file://` protocol:
|
||||
|
||||
```javascript
|
||||
const {app, protocol} = require('electron')
|
||||
const { app, protocol } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
app.on('ready', () => {
|
||||
protocol.registerFileProtocol('atom', (request, callback) => {
|
||||
const url = request.url.substr(7)
|
||||
callback({path: path.normalize(`${__dirname}/${url}`)})
|
||||
callback({ path: path.normalize(`${__dirname}/${url}`) })
|
||||
}, (error) => {
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
|
@ -62,7 +62,7 @@ are disabled for non standard schemes. So in general if you want to register a
|
|||
custom protocol to replace the `http` protocol, you have to register it as a standard scheme:
|
||||
|
||||
```javascript
|
||||
const {app, protocol} = require('electron')
|
||||
const { app, protocol } = require('electron')
|
||||
|
||||
protocol.registerStandardSchemes(['atom'])
|
||||
app.on('ready', () => {
|
||||
|
@ -99,7 +99,7 @@ going to be created with `scheme`. `completion` will be called with
|
|||
|
||||
To handle the `request`, the `callback` should be called with either the file's
|
||||
path or an object that has a `path` property, e.g. `callback(filePath)` or
|
||||
`callback({path: filePath})`.
|
||||
`callback({ path: filePath })`.
|
||||
|
||||
When `callback` is called with nothing, a number, or an object that has an
|
||||
`error` property, the `request` will fail with the `error` number you
|
||||
|
@ -134,10 +134,10 @@ should be called with either a `Buffer` object or an object that has the `data`,
|
|||
Example:
|
||||
|
||||
```javascript
|
||||
const {protocol} = require('electron')
|
||||
const { protocol } = require('electron')
|
||||
|
||||
protocol.registerBufferProtocol('atom', (request, callback) => {
|
||||
callback({mimeType: 'text/html', data: Buffer.from('<h5>Response</h5>')})
|
||||
callback({ mimeType: 'text/html', data: Buffer.from('<h5>Response</h5>') })
|
||||
}, (error) => {
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
|
@ -218,8 +218,8 @@ has the `data`, `statusCode`, and `headers` properties.
|
|||
Example:
|
||||
|
||||
```javascript
|
||||
const {protocol} = require('electron')
|
||||
const {PassThrough} = require('stream')
|
||||
const { protocol } = require('electron')
|
||||
const { PassThrough } = require('stream')
|
||||
|
||||
function createStream (text) {
|
||||
const rv = new PassThrough() // PassThrough is also a Readable stream
|
||||
|
@ -245,7 +245,7 @@ It is possible to pass any object that implements the readable stream API (emits
|
|||
`data`/`end`/`error` events). For example, here's how a file could be returned:
|
||||
|
||||
```javascript
|
||||
const {protocol} = require('electron')
|
||||
const { protocol } = require('electron')
|
||||
const fs = require('fs')
|
||||
|
||||
protocol.registerStreamProtocol('atom', (request, callback) => {
|
||||
|
|
|
@ -16,8 +16,8 @@ similar to Java's [RMI][rmi]. An example of creating a browser window from a
|
|||
renderer process:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron').remote
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
const { BrowserWindow } = require('electron').remote
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL('https://github.com')
|
||||
```
|
||||
|
||||
|
@ -158,7 +158,7 @@ project/
|
|||
|
||||
```js
|
||||
// main process: main/index.js
|
||||
const {app} = require('electron')
|
||||
const { app } = require('electron')
|
||||
app.on('ready', () => { /* ... */ })
|
||||
```
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ and preload.js:
|
|||
// private scope that can access a subset of Electron renderer APIs. We must be
|
||||
// careful to not leak any objects into the global scope!
|
||||
const fs = require('fs')
|
||||
const {ipcRenderer} = require('electron')
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
// read a configuration file using the `fs` module
|
||||
const buf = fs.readFileSync('allowed-popup-urls.json')
|
||||
|
|
|
@ -10,19 +10,19 @@ module is emitted.
|
|||
`screen` is an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter).
|
||||
|
||||
**Note:** In the renderer / DevTools, `window.screen` is a reserved DOM
|
||||
property, so writing `let {screen} = require('electron')` will not work.
|
||||
property, so writing `let { screen } = require('electron')` will not work.
|
||||
|
||||
An example of creating a window that fills the whole screen:
|
||||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const {app, BrowserWindow} = electron
|
||||
const { app, BrowserWindow } = electron
|
||||
|
||||
let win
|
||||
|
||||
app.on('ready', () => {
|
||||
const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize
|
||||
win = new BrowserWindow({width, height})
|
||||
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize
|
||||
win = new BrowserWindow({ width, height })
|
||||
win.loadURL('https://github.com')
|
||||
})
|
||||
```
|
||||
|
@ -31,7 +31,7 @@ Another example of creating a window in the external display:
|
|||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
let win
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@ You can also access the `session` of existing pages by using the `session`
|
|||
property of [`WebContents`](web-contents.md), or from the `session` module.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
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
|
||||
|
@ -59,7 +59,7 @@ Process: [Main](../glossary.md#main-process)
|
|||
You can create a `Session` object in the `session` module:
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
const ses = session.fromPartition('persist:name')
|
||||
console.log(ses.getUserAgent())
|
||||
```
|
||||
|
@ -80,7 +80,7 @@ Calling `event.preventDefault()` will cancel the download and `item` will not be
|
|||
available from next tick of the process.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
session.defaultSession.on('will-download', (event, item, webContents) => {
|
||||
event.preventDefault()
|
||||
require('request')(item.getURL(), (data) => {
|
||||
|
@ -239,7 +239,7 @@ window.webContents.session.enableNetworkEmulation({
|
|||
})
|
||||
|
||||
// To emulate a network outage.
|
||||
window.webContents.session.enableNetworkEmulation({offline: true})
|
||||
window.webContents.session.enableNetworkEmulation({ offline: true })
|
||||
```
|
||||
|
||||
#### `ses.disableNetworkEmulation()`
|
||||
|
@ -272,11 +272,11 @@ Calling `setCertificateVerifyProc(null)` will revert back to default certificate
|
|||
verify proc.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
win.webContents.session.setCertificateVerifyProc((request, callback) => {
|
||||
const {hostname} = request
|
||||
const { hostname } = request
|
||||
if (hostname === 'github.com') {
|
||||
callback(0)
|
||||
} else {
|
||||
|
@ -303,7 +303,7 @@ Calling `callback(true)` will allow the permission and `callback(false)` will re
|
|||
To clear the handler, call `setPermissionRequestHandler(null)`.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
session.fromPartition('some-partition').setPermissionRequestHandler((webContents, permission, callback) => {
|
||||
if (webContents.getURL() === 'some-host' && permission === 'notifications') {
|
||||
return callback(false) // denied.
|
||||
|
@ -329,7 +329,7 @@ Returning `true` will allow the permission and `false` will reject it.
|
|||
To clear the handler, call `setPermissionCheckHandler(null)`.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
session.fromPartition('some-partition').setPermissionCheckHandler((webContents, permission) => {
|
||||
if (webContents.getURL() === 'some-host' && permission === 'notifications') {
|
||||
return false // denied
|
||||
|
@ -354,7 +354,7 @@ Dynamically sets whether to always send credentials for HTTP NTLM or Negotiate
|
|||
authentication.
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
// consider any url ending with `example.com`, `foobar.com`, `baz`
|
||||
// for integrated authentication.
|
||||
session.defaultSession.allowNTLMCredentialsForDomains('*example.com, *foobar.com, *baz')
|
||||
|
@ -441,14 +441,14 @@ A [WebRequest](web-request.md) object for this session.
|
|||
A [Protocol](protocol.md) object for this session.
|
||||
|
||||
```javascript
|
||||
const {app, session} = require('electron')
|
||||
const { app, session } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
app.on('ready', function () {
|
||||
const protocol = session.fromPartition('some-partition').protocol
|
||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
||||
var url = request.url.substr(7)
|
||||
callback({path: path.normalize(`${__dirname}/${url}`)})
|
||||
callback({ path: path.normalize(`${__dirname}/${url}`) })
|
||||
}, function (error) {
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
|
|
|
@ -9,7 +9,7 @@ The `shell` module provides functions related to desktop integration.
|
|||
An example of opening a URL in the user's default browser:
|
||||
|
||||
```javascript
|
||||
const {shell} = require('electron')
|
||||
const { shell } = require('electron')
|
||||
|
||||
shell.openExternal('https://github.com')
|
||||
```
|
||||
|
|
|
@ -19,11 +19,11 @@ scripts to be able to use those modules.
|
|||
The main process script is like a normal Node.js script:
|
||||
|
||||
```javascript
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
let win = null
|
||||
|
||||
app.on('ready', () => {
|
||||
win = new BrowserWindow({width: 800, height: 600})
|
||||
win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL('https://github.com')
|
||||
})
|
||||
```
|
||||
|
@ -36,7 +36,7 @@ extra ability to use node modules:
|
|||
<html>
|
||||
<body>
|
||||
<script>
|
||||
const {app} = require('electron').remote
|
||||
const { app } = require('electron').remote
|
||||
console.log(app.getVersion())
|
||||
</script>
|
||||
</body>
|
||||
|
@ -52,7 +52,7 @@ As of 0.37, you can use
|
|||
built-in modules.
|
||||
|
||||
```javascript
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
let win
|
||||
|
||||
|
@ -67,7 +67,7 @@ destructuring to access the individual modules from `electron`.
|
|||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const {app, BrowserWindow} = electron
|
||||
const { app, BrowserWindow } = electron
|
||||
|
||||
let win
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
Process: [Main](../glossary.md#main-process)
|
||||
|
||||
```javascript
|
||||
const {systemPreferences} = require('electron')
|
||||
const { systemPreferences } = require('electron')
|
||||
console.log(systemPreferences.isDarkMode())
|
||||
```
|
||||
|
||||
|
@ -185,8 +185,8 @@ 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
|
||||
const {BrowserWindow, systemPreferences} = require('electron')
|
||||
let browserOptions = {width: 1000, height: 800}
|
||||
const { BrowserWindow, systemPreferences } = require('electron')
|
||||
let browserOptions = { width: 1000, height: 800 }
|
||||
|
||||
// Make the window transparent only if the platform supports it.
|
||||
if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) {
|
||||
|
|
|
@ -36,9 +36,9 @@ Below is an example of a simple slot machine touch bar game with a button
|
|||
and some labels.
|
||||
|
||||
```javascript
|
||||
const {app, BrowserWindow, TouchBar} = require('electron')
|
||||
const { app, BrowserWindow, TouchBar } = require('electron')
|
||||
|
||||
const {TouchBarLabel, TouchBarButton, TouchBarSpacer} = TouchBar
|
||||
const { TouchBarLabel, TouchBarButton, TouchBarSpacer } = TouchBar
|
||||
|
||||
let spinning = false
|
||||
|
||||
|
@ -114,13 +114,13 @@ const finishSpin = () => {
|
|||
|
||||
const touchBar = new TouchBar([
|
||||
spin,
|
||||
new TouchBarSpacer({size: 'large'}),
|
||||
new TouchBarSpacer({ size: 'large' }),
|
||||
reel1,
|
||||
new TouchBarSpacer({size: 'small'}),
|
||||
new TouchBarSpacer({ size: 'small' }),
|
||||
reel2,
|
||||
new TouchBarSpacer({size: 'small'}),
|
||||
new TouchBarSpacer({ size: 'small' }),
|
||||
reel3,
|
||||
new TouchBarSpacer({size: 'large'}),
|
||||
new TouchBarSpacer({ size: 'large' }),
|
||||
result
|
||||
])
|
||||
|
||||
|
|
|
@ -7,16 +7,16 @@ Process: [Main](../glossary.md#main-process)
|
|||
`Tray` is an [EventEmitter][event-emitter].
|
||||
|
||||
```javascript
|
||||
const {app, Menu, Tray} = require('electron')
|
||||
const { app, Menu, Tray } = require('electron')
|
||||
|
||||
let tray = null
|
||||
app.on('ready', () => {
|
||||
tray = 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' }
|
||||
])
|
||||
tray.setToolTip('This is my application.')
|
||||
tray.setContextMenu(contextMenu)
|
||||
|
@ -35,14 +35,14 @@ __Platform limitations:__
|
|||
you have to call `setContextMenu` again. For example:
|
||||
|
||||
```javascript
|
||||
const {app, Menu, Tray} = require('electron')
|
||||
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: 'Item1', type: 'radio' },
|
||||
{ label: 'Item2', type: 'radio' }
|
||||
])
|
||||
|
||||
// Make a change to the context menu
|
||||
|
@ -225,9 +225,9 @@ by toggling between `'never'` and `'always'` modes when the window visibility
|
|||
changes.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow, Tray} = require('electron')
|
||||
const { BrowserWindow, Tray } = require('electron')
|
||||
|
||||
const win = new BrowserWindow({width: 800, height: 600})
|
||||
const win = new BrowserWindow({ width: 800, height: 600 })
|
||||
const tray = new Tray('/path/to/my/icon')
|
||||
|
||||
tray.on('click', () => {
|
||||
|
|
|
@ -11,9 +11,9 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the
|
|||
`webContents` object:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 1500})
|
||||
let win = new BrowserWindow({ width: 800, height: 1500 })
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
let contents = win.webContents
|
||||
|
@ -25,7 +25,7 @@ console.log(contents)
|
|||
These methods can be accessed from the `webContents` module:
|
||||
|
||||
```javascript
|
||||
const {webContents} = require('electron')
|
||||
const { webContents } = require('electron')
|
||||
console.log(webContents)
|
||||
```
|
||||
|
||||
|
@ -140,7 +140,7 @@ instance, failing to do so may result in unexpected behavior. For example:
|
|||
```javascript
|
||||
myBrowserWindow.webContents.on('new-window', (event, url) => {
|
||||
event.preventDefault()
|
||||
const win = new BrowserWindow({show: false})
|
||||
const win = new BrowserWindow({ show: false })
|
||||
win.once('ready-to-show', () => win.show())
|
||||
win.loadURL(url)
|
||||
event.newGuest = win
|
||||
|
@ -240,8 +240,8 @@ Calling `event.preventDefault()` will ignore the `beforeunload` event handler
|
|||
and allow the page to be unloaded.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow, dialog} = require('electron')
|
||||
const win = new BrowserWindow({width: 800, height: 600})
|
||||
const { BrowserWindow, dialog } = require('electron')
|
||||
const win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.webContents.on('will-prevent-unload', (event) => {
|
||||
const choice = dialog.showMessageBox(win, {
|
||||
type: 'question',
|
||||
|
@ -312,9 +312,9 @@ To only prevent the menu shortcuts, use
|
|||
[`setIgnoreMenuShortcuts`](#contentssetignoremenushortcutsignore-experimental):
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
|
||||
win.webContents.on('before-input-event', (event, input) => {
|
||||
// For example, only enable application menu keyboard shortcuts when
|
||||
|
@ -535,13 +535,13 @@ first available device will be selected. `callback` should be called with
|
|||
cancel the request.
|
||||
|
||||
```javascript
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
let win = null
|
||||
app.commandLine.appendSwitch('enable-experimental-web-platform-features')
|
||||
|
||||
app.on('ready', () => {
|
||||
win = new BrowserWindow({width: 800, height: 600})
|
||||
win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.webContents.on('select-bluetooth-device', (event, deviceList, callback) => {
|
||||
event.preventDefault()
|
||||
let result = deviceList.find((device) => {
|
||||
|
@ -568,9 +568,9 @@ Emitted when a new frame is generated. Only the dirty area is passed in the
|
|||
buffer.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
let win = new BrowserWindow({webPreferences: {offscreen: true}})
|
||||
let win = new BrowserWindow({ webPreferences: { offscreen: true } })
|
||||
win.webContents.on('paint', (event, dirty, image) => {
|
||||
// updateBitmap(dirty, image.getBitmap())
|
||||
})
|
||||
|
@ -642,8 +642,8 @@ e.g. the `http://` or `file://`. If the load should bypass http cache then
|
|||
use the `pragma` header to achieve it.
|
||||
|
||||
```javascript
|
||||
const {webContents} = require('electron')
|
||||
const options = {extraHeaders: 'pragma: no-cache\n'}
|
||||
const { webContents } = require('electron')
|
||||
const options = { extraHeaders: 'pragma: no-cache\n' }
|
||||
webContents.loadURL('https://github.com', options)
|
||||
```
|
||||
|
||||
|
@ -685,8 +685,8 @@ Initiates a download of the resource at `url` without navigating. The
|
|||
Returns `String` - The URL of the current web page.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
let currentURL = win.webContents.getURL()
|
||||
|
@ -979,7 +979,7 @@ can be obtained by subscribing to [`found-in-page`](web-contents.md#event-found-
|
|||
Stops any `findInPage` request for the `webContents` with the provided `action`.
|
||||
|
||||
```javascript
|
||||
const {webContents} = require('electron')
|
||||
const { webContents } = require('electron')
|
||||
webContents.on('found-in-page', (event, result) => {
|
||||
if (result.finalUpdate) webContents.stopFindInPage('clearSelection')
|
||||
})
|
||||
|
@ -1037,7 +1037,7 @@ the system's default printer if `deviceName` is empty and the default settings
|
|||
for printing.
|
||||
|
||||
Calling `window.print()` in web page is equivalent to calling
|
||||
`webContents.print({silent: false, printBackground: false, deviceName: ''})`.
|
||||
`webContents.print({ silent: false, printBackground: false, deviceName: '' })`.
|
||||
|
||||
Use `page-break-before: always; ` CSS style to force to print to a new page.
|
||||
|
||||
|
@ -1080,10 +1080,10 @@ Use `page-break-before: always; ` CSS style to force to print to a new page.
|
|||
An example of `webContents.printToPDF`:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
const fs = require('fs')
|
||||
|
||||
let win = new BrowserWindow({width: 800, height: 600})
|
||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL('http://github.com')
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
|
@ -1106,7 +1106,7 @@ Adds the specified path to DevTools workspace. Must be used after DevTools
|
|||
creation:
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.webContents.on('devtools-opened', () => {
|
||||
win.webContents.addWorkSpace(__dirname)
|
||||
|
@ -1167,7 +1167,7 @@ An example of showing devtools in a `<webview>` tag:
|
|||
An example of showing devtools in a `BrowserWindow`:
|
||||
|
||||
```js
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
let win = null
|
||||
let devtools = null
|
||||
|
@ -1177,7 +1177,7 @@ app.once('ready', () => {
|
|||
devtools = new BrowserWindow()
|
||||
win.loadURL('https://github.com')
|
||||
win.webContents.setDevToolsWebContents(devtools.webContents)
|
||||
win.webContents.openDevTools({mode: 'detach'})
|
||||
win.webContents.openDevTools({ mode: 'detach' })
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -1236,11 +1236,11 @@ An example of sending messages from the main process to the renderer process:
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
let win = null
|
||||
|
||||
app.on('ready', () => {
|
||||
win = new BrowserWindow({width: 800, height: 600})
|
||||
win = new BrowserWindow({ width: 800, height: 600 })
|
||||
win.loadURL(`file://${__dirname}/index.html`)
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
win.webContents.send('ping', 'whoooooooh!')
|
||||
|
@ -1270,7 +1270,7 @@ app.on('ready', () => {
|
|||
* `mobile` - Mobile screen type.
|
||||
* `screenSize` [Size](structures/size.md) - Set the emulated screen size (screenPosition == mobile).
|
||||
* `viewPosition` [Point](structures/point.md) - Position the view on the screen
|
||||
(screenPosition == mobile) (default: `{x: 0, y: 0}`).
|
||||
(screenPosition == mobile) (default: `{ x: 0, y: 0 }`).
|
||||
* `deviceScaleFactor` Integer - Set the device scale factor (if zero defaults to
|
||||
original device scale factor) (default: `0`).
|
||||
* `viewSize` [Size](structures/size.md) - Set the emulated view size (empty means no override)
|
||||
|
@ -1373,7 +1373,7 @@ the cursor when dragging.
|
|||
Returns `Boolean` - true if the process of saving page has been initiated successfully.
|
||||
|
||||
```javascript
|
||||
const {BrowserWindow} = require('electron')
|
||||
const { BrowserWindow } = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
|
||||
win.loadURL('https://github.com')
|
||||
|
|
|
@ -11,7 +11,7 @@ be retrieved by certain properties and methods (e.g. `webFrame.firstChild`).
|
|||
An example of zooming current page to 200%.
|
||||
|
||||
```javascript
|
||||
const {webFrame} = require('electron')
|
||||
const { webFrame } = require('electron')
|
||||
|
||||
webFrame.setZoomFactor(2)
|
||||
```
|
||||
|
@ -73,7 +73,7 @@ whether the word passed is correctly spelled.
|
|||
An example of using [node-spellchecker][spellchecker] as provider:
|
||||
|
||||
```javascript
|
||||
const {webFrame} = require('electron')
|
||||
const { webFrame } = require('electron')
|
||||
webFrame.setSpellCheckProvider('en-US', true, {
|
||||
spellCheck (text) {
|
||||
return !(require('spellchecker').isMisspelled(text))
|
||||
|
@ -105,7 +105,7 @@ Specify an option with the value of `false` to omit it from the registration.
|
|||
An example of registering a privileged scheme, without bypassing Content Security Policy:
|
||||
|
||||
```javascript
|
||||
const {webFrame} = require('electron')
|
||||
const { webFrame } = require('electron')
|
||||
webFrame.registerURLSchemeAsPrivileged('foo', { bypassCSP: false })
|
||||
```
|
||||
|
||||
|
@ -177,7 +177,7 @@ Returns an object describing usage information of Blink's internal memory
|
|||
caches.
|
||||
|
||||
```javascript
|
||||
const {webFrame} = require('electron')
|
||||
const { webFrame } = require('electron')
|
||||
console.log(webFrame.getResourceUsage())
|
||||
```
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ called with a `response` object when `listener` has done its work.
|
|||
An example of adding `User-Agent` header for requests:
|
||||
|
||||
```javascript
|
||||
const {session} = require('electron')
|
||||
const { session } = require('electron')
|
||||
|
||||
// Modify the user agent for all requests to the following urls.
|
||||
const filter = {
|
||||
|
@ -32,7 +32,7 @@ const filter = {
|
|||
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
|
||||
details.requestHeaders['User-Agent'] = 'MyAgent'
|
||||
callback({cancel: false, requestHeaders: details.requestHeaders})
|
||||
callback({ cancel: false, requestHeaders: details.requestHeaders })
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
@ -752,7 +752,7 @@ Fired when the guest page attempts to open a new browser window.
|
|||
The following example code opens the new url in system's default browser.
|
||||
|
||||
```javascript
|
||||
const {shell} = require('electron')
|
||||
const { shell } = require('electron')
|
||||
const webview = document.querySelector('webview')
|
||||
|
||||
webview.addEventListener('new-window', (e) => {
|
||||
|
@ -844,7 +844,7 @@ webview.send('ping')
|
|||
|
||||
```javascript
|
||||
// In guest page.
|
||||
const {ipcRenderer} = require('electron')
|
||||
const { ipcRenderer } = require('electron')
|
||||
ipcRenderer.on('ping', () => {
|
||||
ipcRenderer.sendToHost('pong')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue