📝 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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { app } = require('electron');
 | 
			
		||||
const {app} = require('electron');
 | 
			
		||||
 | 
			
		||||
app.on('window-all-closed', () => {
 | 
			
		||||
  app.quit();
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,10 +4,10 @@
 | 
			
		|||
 | 
			
		||||
```javascript
 | 
			
		||||
// In the main process.
 | 
			
		||||
const { BrowserWindow } = require('electron');
 | 
			
		||||
const {BrowserWindow} = require('electron');
 | 
			
		||||
 | 
			
		||||
// 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 });
 | 
			
		||||
win.on('closed', () => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
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');
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ This module does not include a web interface so you need to open
 | 
			
		|||
result.
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { contentTracing } = require('electron');
 | 
			
		||||
const {contentTracing} = require('electron');
 | 
			
		||||
 | 
			
		||||
const options = {
 | 
			
		||||
  categoryFilter: '*',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,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',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ microphone, camera, or screen.
 | 
			
		|||
 | 
			
		||||
```javascript
 | 
			
		||||
// In the renderer process.
 | 
			
		||||
var { desktopCapturer } = require('electron');
 | 
			
		||||
const {desktopCapturer} = require('electron');
 | 
			
		||||
 | 
			
		||||
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
 | 
			
		||||
  if (error) throw error;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,8 @@ An example of showing a dialog to select multiple files and directories:
 | 
			
		|||
 | 
			
		||||
```javascript
 | 
			
		||||
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' ]}));
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { dialog } = require('electron').remote;
 | 
			
		||||
const {dialog} = require('electron').remote;
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Methods
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ To create a frameless window, you need to set `frame` to `false` in
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { BrowserWindow } = require('electron');
 | 
			
		||||
const {BrowserWindow} = require('electron');
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const electron = require('electron');
 | 
			
		||||
const { app, globalShortcut } = electron;
 | 
			
		||||
const {app, globalShortcut} = require('electron');
 | 
			
		||||
 | 
			
		||||
app.on('ready', () => {
 | 
			
		||||
  // Register a 'CommandOrControl+X' shortcut listener.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,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');
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +37,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) => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ the user right clicks the page:
 | 
			
		|||
```html
 | 
			
		||||
<!-- index.html -->
 | 
			
		||||
<script>
 | 
			
		||||
const { Menu, MenuItem } = require('electron').remote;
 | 
			
		||||
const {Menu, MenuItem} = require('electron').remote;
 | 
			
		||||
 | 
			
		||||
const menu = new Menu();
 | 
			
		||||
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
For example:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { powerSaveBlocker } = require('electron');
 | 
			
		||||
const {powerSaveBlocker} = require('electron');
 | 
			
		||||
 | 
			
		||||
const id = powerSaveBlocker.start('prevent-display-sleep');
 | 
			
		||||
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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { BrowserWindow } = require('electron').remote;
 | 
			
		||||
const {BrowserWindow} = require('electron').remote;
 | 
			
		||||
 | 
			
		||||
var win = new BrowserWindow({ width: 800, height: 600 });
 | 
			
		||||
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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const electron = require('electron');
 | 
			
		||||
const { app, BrowserWindow } = electron;
 | 
			
		||||
const {app, BrowserWindow, screen: electronScreen} = require('electron');
 | 
			
		||||
 | 
			
		||||
let mainWindow;
 | 
			
		||||
 | 
			
		||||
app.on('ready', () => {
 | 
			
		||||
  const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
 | 
			
		||||
  const {width, height} = electronScreen.getPrimaryDisplay().workAreaSize;
 | 
			
		||||
  mainWindow = new BrowserWindow({ width, height });
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
| 
						 | 
				
			
			@ -27,13 +26,11 @@ app.on('ready', () => {
 | 
			
		|||
Another example of creating a window in the external display:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const electron = require('electron');
 | 
			
		||||
const { app, BrowserWindow } = electron;
 | 
			
		||||
const {app, BrowserWindow, screen: electronScreen} = require('electron');
 | 
			
		||||
 | 
			
		||||
let mainWindow;
 | 
			
		||||
 | 
			
		||||
app.on('ready', () => {
 | 
			
		||||
  var electronScreen = electron.screen;
 | 
			
		||||
  var displays = electronScreen.getAllDisplays();
 | 
			
		||||
  var externalDisplay = null;
 | 
			
		||||
  for (let i in displays) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ property of [`webContents`](web-contents.md) which is a property of
 | 
			
		|||
[`BrowserWindow`](browser-window.md).
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { BrowserWindow } = require('electron');
 | 
			
		||||
const {BrowserWindow} = require('electron');
 | 
			
		||||
 | 
			
		||||
let win = new BrowserWindow({ width: 800, height: 600 });
 | 
			
		||||
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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { shell } = require('electron');
 | 
			
		||||
const {shell} = require('electron');
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { app, BrowserWindow } = require('electron');
 | 
			
		||||
const {app, BrowserWindow} = require('electron');
 | 
			
		||||
 | 
			
		||||
let window = null;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -37,8 +37,8 @@ extra ability to use node modules:
 | 
			
		|||
<html>
 | 
			
		||||
<body>
 | 
			
		||||
<script>
 | 
			
		||||
  const { remote } = require('electron');
 | 
			
		||||
  console.log(remote.app.getVersion());
 | 
			
		||||
  const {app} = require('electron').remote;
 | 
			
		||||
  console.log(app.getVersion());
 | 
			
		||||
</script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +53,7 @@ As of 0.37, you can use
 | 
			
		|||
built-in modules.
 | 
			
		||||
 | 
			
		||||
```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
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ destructuring to access the individual modules from `electron`.
 | 
			
		|||
 | 
			
		||||
```javascript
 | 
			
		||||
const electron = require('electron');
 | 
			
		||||
const { app, BrowserWindow } = electron;
 | 
			
		||||
const {app, BrowserWindow} = electron;
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
This is equivalent to the following code:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ 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});
 | 
			
		||||
win.loadURL('http://github.com');
 | 
			
		||||
| 
						 | 
				
			
			@ -673,7 +673,7 @@ By default, an empty `options` will be regarded as:
 | 
			
		|||
```
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { BrowserWindow } = require('electron');
 | 
			
		||||
const {BrowserWindow} = require('electron');
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
 | 
			
		||||
let win = new BrowserWindow({width: 800, height: 600});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
An example of zooming current page to 200%.
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { webFrame } = require('electron');
 | 
			
		||||
const {webFrame} = require('electron');
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { shell } = require('electron');
 | 
			
		||||
const {shell} = require('electron');
 | 
			
		||||
 | 
			
		||||
webview.addEventListener('new-window', (e) => {
 | 
			
		||||
  const protocol = require('url').parse(e.url).protocol;
 | 
			
		||||
| 
						 | 
				
			
			@ -732,7 +732,7 @@ webview.send('ping');
 | 
			
		|||
 | 
			
		||||
```javascript
 | 
			
		||||
// In guest page.
 | 
			
		||||
var { ipcRenderer } = require('electron');
 | 
			
		||||
const {ipcRenderer} = require('electron');
 | 
			
		||||
ipcRenderer.on('ping', () => {
 | 
			
		||||
  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`:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { BrowserWindow } = require('electron');
 | 
			
		||||
const {BrowserWindow} = require('electron');
 | 
			
		||||
let win = new BrowserWindow({width: 800, height: 600});
 | 
			
		||||
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:
 | 
			
		||||
 | 
			
		||||
```javascript
 | 
			
		||||
const { BrowserWindow } = require('electron');
 | 
			
		||||
const {BrowserWindow} = require('electron');
 | 
			
		||||
const path = require('path');
 | 
			
		||||
 | 
			
		||||
let win = new BrowserWindow({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,7 +71,7 @@ _online-status.html_
 | 
			
		|||
<html>
 | 
			
		||||
<body>
 | 
			
		||||
<script>
 | 
			
		||||
  const { ipcRenderer } = require('electron');
 | 
			
		||||
  const {ipcRenderer} = require('electron');
 | 
			
		||||
  const updateOnlineStatus = () => {
 | 
			
		||||
    ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
 | 
			
		||||
  };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue