📝 Match destructuring style
[ci skip]
This commit is contained in:
parent
5787bb0226
commit
4d7296e1db
24 changed files with 37 additions and 39 deletions
|
@ -6,7 +6,8 @@ The following example shows how to quit the application when the last window is
|
||||||
closed:
|
closed:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { app } = require('electron');
|
const {app} = require('electron');
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
const { BrowserWindow } = require('electron');
|
const {BrowserWindow} = require('electron');
|
||||||
|
|
||||||
// Or in the renderer process.
|
// Or in the renderer process.
|
||||||
const { BrowserWindow } = require('electron').remote;
|
const {BrowserWindow} = require('electron').remote;
|
||||||
|
|
||||||
let win = new BrowserWindow({ width: 800, height: 600, show: false });
|
let win = new BrowserWindow({ width: 800, height: 600, show: false });
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ your app's main script before the [ready][ready] event of the [app][app] module
|
||||||
is emitted:
|
is emitted:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { app } = require('electron');
|
const {app} = require('electron');
|
||||||
app.commandLine.appendSwitch('remote-debugging-port', '8315');
|
app.commandLine.appendSwitch('remote-debugging-port', '8315');
|
||||||
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');
|
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
The following example shows how to write a string to the clipboard:
|
The following example shows how to write a string to the clipboard:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { clipboard } = require('electron');
|
const {clipboard} = require('electron');
|
||||||
clipboard.writeText('Example String');
|
clipboard.writeText('Example String');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ This module does not include a web interface so you need to open
|
||||||
result.
|
result.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { contentTracing } = require('electron');
|
const {contentTracing} = require('electron');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
categoryFilter: '*',
|
categoryFilter: '*',
|
||||||
|
|
|
@ -6,7 +6,7 @@ The following is an example of automatically submitting a crash report to a
|
||||||
remote server:
|
remote server:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { crashReporter } = require('electron');
|
const {crashReporter} = require('electron');
|
||||||
|
|
||||||
crashReporter.start({
|
crashReporter.start({
|
||||||
productName: 'YourName',
|
productName: 'YourName',
|
||||||
|
|
|
@ -5,7 +5,7 @@ microphone, camera, or screen.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the renderer process.
|
// In the renderer process.
|
||||||
var { 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;
|
if (error) throw error;
|
||||||
|
|
|
@ -6,7 +6,8 @@ An example of showing a dialog to select multiple files and directories:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = ...; // BrowserWindow in which to show the dialog
|
var win = ...; // BrowserWindow in which to show the dialog
|
||||||
const { dialog } = require('electron');
|
const {dialog} = require('electron');
|
||||||
|
|
||||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ 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:
|
object from a renderer process, remember to access it using the remote:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { dialog } = require('electron').remote;
|
const {dialog} = require('electron').remote;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
|
@ -14,7 +14,7 @@ To create a frameless window, you need to set `frame` to `false` in
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron');
|
const {BrowserWindow} = require('electron');
|
||||||
let win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
let win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,7 @@ not have the keyboard focus. You should not use this module until the `ready`
|
||||||
event of the app module is emitted.
|
event of the app module is emitted.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const {app, globalShortcut} = require('electron');
|
||||||
const { app, globalShortcut } = electron;
|
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
// Register a 'CommandOrControl+X' shortcut listener.
|
// Register a 'CommandOrControl+X' shortcut listener.
|
||||||
|
|
|
@ -23,7 +23,7 @@ processes:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In main process.
|
// In main process.
|
||||||
const { ipcMain } = require('electron');
|
const {ipcMain} = require('electron');
|
||||||
ipcMain.on('asynchronous-message', (event, arg) => {
|
ipcMain.on('asynchronous-message', (event, arg) => {
|
||||||
console.log(arg); // prints "ping"
|
console.log(arg); // prints "ping"
|
||||||
event.sender.send('asynchronous-reply', 'pong');
|
event.sender.send('asynchronous-reply', 'pong');
|
||||||
|
@ -37,7 +37,7 @@ ipcMain.on('synchronous-message', (event, arg) => {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In renderer process (web page).
|
// In renderer process (web page).
|
||||||
const { ipcRenderer } = require('electron');
|
const {ipcRenderer} = require('electron');
|
||||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||||
|
|
||||||
ipcRenderer.on('asynchronous-reply', (event, arg) => {
|
ipcRenderer.on('asynchronous-reply', (event, arg) => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ the user right clicks the page:
|
||||||
```html
|
```html
|
||||||
<!-- index.html -->
|
<!-- index.html -->
|
||||||
<script>
|
<script>
|
||||||
const { Menu, MenuItem } = require('electron').remote;
|
const {Menu, MenuItem} = require('electron').remote;
|
||||||
|
|
||||||
const menu = new Menu();
|
const menu = new Menu();
|
||||||
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { powerSaveBlocker } = require('electron');
|
const {powerSaveBlocker} = require('electron');
|
||||||
|
|
||||||
const id = powerSaveBlocker.start('prevent-display-sleep');
|
const id = powerSaveBlocker.start('prevent-display-sleep');
|
||||||
console.log(powerSaveBlocker.isStarted(id));
|
console.log(powerSaveBlocker.isStarted(id));
|
||||||
|
|
|
@ -14,7 +14,7 @@ similar to Java's [RMI][rmi]. An example of creating a browser window from a
|
||||||
renderer process:
|
renderer process:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron').remote;
|
const {BrowserWindow} = require('electron').remote;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
var win = new BrowserWindow({ width: 800, height: 600 });
|
||||||
win.loadURL('https://github.com');
|
win.loadURL('https://github.com');
|
||||||
|
|
|
@ -13,13 +13,12 @@ In our examples below, we use `electronScreen` as the variable name instead.
|
||||||
An example of creating a window that fills the whole screen:
|
An example of creating a window that fills the whole screen:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const {app, BrowserWindow, screen: electronScreen} = require('electron');
|
||||||
const { app, BrowserWindow } = electron;
|
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
|
const {width, height} = electronScreen.getPrimaryDisplay().workAreaSize;
|
||||||
mainWindow = new BrowserWindow({ width, height });
|
mainWindow = new BrowserWindow({ width, height });
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -27,13 +26,11 @@ app.on('ready', () => {
|
||||||
Another example of creating a window in the external display:
|
Another example of creating a window in the external display:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const {app, BrowserWindow, screen: electronScreen} = require('electron');
|
||||||
const { app, BrowserWindow } = electron;
|
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
var electronScreen = electron.screen;
|
|
||||||
var displays = electronScreen.getAllDisplays();
|
var displays = electronScreen.getAllDisplays();
|
||||||
var externalDisplay = null;
|
var externalDisplay = null;
|
||||||
for (let i in displays) {
|
for (let i in displays) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ property of [`webContents`](web-contents.md) which is a property of
|
||||||
[`BrowserWindow`](browser-window.md).
|
[`BrowserWindow`](browser-window.md).
|
||||||
|
|
||||||
```javascript
|
```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');
|
win.loadURL('http://github.com');
|
||||||
|
|
|
@ -7,7 +7,7 @@ The `shell` module provides functions related to desktop integration.
|
||||||
An example of opening a URL in the user's default browser:
|
An example of opening a URL in the user's default browser:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { shell } = require('electron');
|
const {shell} = require('electron');
|
||||||
|
|
||||||
shell.openExternal('https://github.com');
|
shell.openExternal('https://github.com');
|
||||||
```
|
```
|
||||||
|
|
|
@ -19,7 +19,7 @@ scripts to be able to use those modules.
|
||||||
The main process script is just like a normal Node.js script:
|
The main process script is just like a normal Node.js script:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { app, BrowserWindow } = require('electron');
|
const {app, BrowserWindow} = require('electron');
|
||||||
|
|
||||||
let window = null;
|
let window = null;
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ extra ability to use node modules:
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
const { remote } = require('electron');
|
const {app} = require('electron').remote;
|
||||||
console.log(remote.app.getVersion());
|
console.log(app.getVersion());
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -53,7 +53,7 @@ As of 0.37, you can use
|
||||||
built-in modules.
|
built-in modules.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { app, BrowserWindow } = require('electron');
|
const {app, BrowserWindow} = require('electron');
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need the entire `electron` module, you can require it and then using
|
If you need the entire `electron` module, you can require it and then using
|
||||||
|
@ -61,7 +61,7 @@ destructuring to access the individual modules from `electron`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const { app, BrowserWindow } = electron;
|
const {app, BrowserWindow} = electron;
|
||||||
```
|
```
|
||||||
|
|
||||||
This is equivalent to the following code:
|
This is equivalent to the following code:
|
||||||
|
|
|
@ -9,7 +9,7 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the
|
||||||
`webContents` object:
|
`webContents` object:
|
||||||
|
|
||||||
```javascript
|
```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');
|
win.loadURL('http://github.com');
|
||||||
|
@ -673,7 +673,7 @@ By default, an empty `options` will be regarded as:
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron');
|
const {BrowserWindow} = require('electron');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
let win = new BrowserWindow({width: 800, height: 600});
|
let win = new BrowserWindow({width: 800, height: 600});
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
An example of zooming current page to 200%.
|
An example of zooming current page to 200%.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { webFrame } = require('electron');
|
const {webFrame} = require('electron');
|
||||||
|
|
||||||
webFrame.setZoomFactor(2);
|
webFrame.setZoomFactor(2);
|
||||||
```
|
```
|
||||||
|
|
|
@ -644,7 +644,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.
|
The following example code opens the new url in system's default browser.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { shell } = require('electron');
|
const {shell} = require('electron');
|
||||||
|
|
||||||
webview.addEventListener('new-window', (e) => {
|
webview.addEventListener('new-window', (e) => {
|
||||||
const protocol = require('url').parse(e.url).protocol;
|
const protocol = require('url').parse(e.url).protocol;
|
||||||
|
@ -732,7 +732,7 @@ webview.send('ping');
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In guest page.
|
// In guest page.
|
||||||
var { ipcRenderer } = require('electron');
|
const {ipcRenderer} = require('electron');
|
||||||
ipcRenderer.on('ping', () => {
|
ipcRenderer.on('ping', () => {
|
||||||
ipcRenderer.sendToHost('pong');
|
ipcRenderer.sendToHost('pong');
|
||||||
});
|
});
|
||||||
|
|
|
@ -71,7 +71,7 @@ require('/path/to/example.asar/dir/module.js');
|
||||||
You can also display a web page in an `asar` archive with `BrowserWindow`:
|
You can also display a web page in an `asar` archive with `BrowserWindow`:
|
||||||
|
|
||||||
```javascript
|
```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('file:///path/to/example.asar/static/index.html');
|
win.loadURL('file:///path/to/example.asar/static/index.html');
|
||||||
```
|
```
|
||||||
|
|
|
@ -209,7 +209,7 @@ You can use [BrowserWindow.setThumbarButtons][setthumbarbuttons] to set
|
||||||
thumbnail toolbar in your application:
|
thumbnail toolbar in your application:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron');
|
const {BrowserWindow} = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
let win = new BrowserWindow({
|
let win = new BrowserWindow({
|
||||||
|
|
|
@ -71,7 +71,7 @@ _online-status.html_
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
const { ipcRenderer } = require('electron');
|
const {ipcRenderer} = require('electron');
|
||||||
const updateOnlineStatus = () => {
|
const updateOnlineStatus = () => {
|
||||||
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue