📝 Update API documentation to ES6 [ci skip]
This commit is contained in:
parent
178496afe5
commit
5a9f28e034
28 changed files with 168 additions and 176 deletions
|
@ -6,8 +6,8 @@ The following example shows how to quit the application when the last window is
|
||||||
closed:
|
closed:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const app = require('electron').app;
|
const { app } = require('electron');
|
||||||
app.on('window-all-closed', function() {
|
app.on('window-all-closed', () => {
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -218,7 +218,7 @@ should prevent the default behavior with `event.preventDefault()` and call
|
||||||
`callback(username, password)` with the credentials.
|
`callback(username, password)` with the credentials.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('login', function(event, webContents, request, authInfo, callback) {
|
app.on('login', (event, webContents, request, authInfo, callback) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
callback('username', 'secret');
|
callback('username', 'secret');
|
||||||
})
|
})
|
||||||
|
@ -386,12 +386,12 @@ default protocol handler.
|
||||||
|
|
||||||
### `app.isDefaultProtocolClient(protocol)` _OS X_ _Windows_
|
### `app.isDefaultProtocolClient(protocol)` _OS X_ _Windows_
|
||||||
|
|
||||||
* `protocol` String - The name of your protocol, without `://`.
|
* `protocol` String - The name of your protocol, without `://`.
|
||||||
|
|
||||||
This method checks if the current executable is the default handler for a protocol
|
This method checks if the current executable is the default handler for a protocol
|
||||||
(aka URI scheme). If so, it will return true. Otherwise, it will return false.
|
(aka URI scheme). If so, it will return true. Otherwise, it will return false.
|
||||||
|
|
||||||
**Note:** On OS X, you can use this method to check if the app has been registered as the default protocol handler for a protocol. You can also verify this by checking `~/Library/Preferences/com.apple.LaunchServices.plist` on the OS X machine.
|
**Note:** On OS X, you can use this method to check if the app has been registered as the default protocol handler for a protocol. You can also verify this by checking `~/Library/Preferences/com.apple.LaunchServices.plist` on the OS X machine.
|
||||||
Please refer to [Apple's documentation][LSCopyDefaultHandlerForURLScheme] for details.
|
Please refer to [Apple's documentation][LSCopyDefaultHandlerForURLScheme] for details.
|
||||||
|
|
||||||
The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.
|
The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.
|
||||||
|
@ -462,9 +462,9 @@ An example of activating the window of primary instance when a second instance
|
||||||
starts:
|
starts:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myWindow = null;
|
let myWindow = null;
|
||||||
|
|
||||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
|
||||||
// Someone tried to run a second instance, we should focus our window.
|
// Someone tried to run a second instance, we should focus our window.
|
||||||
if (myWindow) {
|
if (myWindow) {
|
||||||
if (myWindow.isMinimized()) myWindow.restore();
|
if (myWindow.isMinimized()) myWindow.restore();
|
||||||
|
@ -478,7 +478,7 @@ if (shouldQuit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create myWindow, load the rest of the app, etc...
|
// Create myWindow, load the rest of the app, etc...
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -568,5 +568,5 @@ Sets the `image` associated with this dock icon.
|
||||||
[tasks]:http://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#tasks
|
[tasks]:http://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#tasks
|
||||||
[app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx
|
[app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx
|
||||||
[CFBundleURLTypes]: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-102207-TPXREF115
|
[CFBundleURLTypes]: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-102207-TPXREF115
|
||||||
[LSCopyDefaultHandlerForURLScheme]:
|
[LSCopyDefaultHandlerForURLScheme]:
|
||||||
https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/#//apple_ref/c/func/LSCopyDefaultHandlerForURLScheme
|
https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/#//apple_ref/c/func/LSCopyDefaultHandlerForURLScheme
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
// Or in the renderer process.
|
// Or in the renderer process.
|
||||||
const BrowserWindow = require('electron').remote.BrowserWindow;
|
const { BrowserWindow } = require('electron').remote;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, show: false });
|
let win = new BrowserWindow({ width: 800, height: 600, show: false });
|
||||||
win.on('closed', function() {
|
win.on('closed', () => {
|
||||||
win = null;
|
win = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ Commands are lowercased with underscores replaced with hyphens and the
|
||||||
e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`.
|
e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
someWindow.on('app-command', function(e, cmd) {
|
someWindow.on('app-command', (e, cmd) => {
|
||||||
// Navigate the window back when the user hits their mouse back button
|
// Navigate the window back when the user hits their mouse back button
|
||||||
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
||||||
someWindow.webContents.goBack();
|
someWindow.webContents.goBack();
|
||||||
|
|
|
@ -7,11 +7,11 @@ 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').app;
|
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');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
// Your code here
|
// Your code here
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -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').clipboard;
|
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').contentTracing;
|
const { contentTracing } = require('electron');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
categoryFilter: '*',
|
categoryFilter: '*',
|
||||||
|
@ -18,8 +18,8 @@ const options = {
|
||||||
contentTracing.startRecording(options, function() {
|
contentTracing.startRecording(options, function() {
|
||||||
console.log('Tracing started');
|
console.log('Tracing started');
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
contentTracing.stopRecording('', function(path) {
|
contentTracing.stopRecording('', (path) => {
|
||||||
console.log('Tracing data recorded to ' + path);
|
console.log('Tracing data recorded to ' + path);
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
|
@ -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').crashReporter;
|
const { crashReporter } = require('electron');
|
||||||
|
|
||||||
crashReporter.start({
|
crashReporter.start({
|
||||||
productName: 'YourName',
|
productName: 'YourName',
|
||||||
|
|
|
@ -5,9 +5,9 @@ microphone, camera, or screen.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the renderer process.
|
// In the renderer process.
|
||||||
var desktopCapturer = require('electron').desktopCapturer;
|
var { desktopCapturer } = require('electron');
|
||||||
|
|
||||||
desktopCapturer.getSources({types: ['window', 'screen']}, function(error, sources) {
|
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
for (var i = 0; i < sources.length; ++i) {
|
for (var i = 0; i < sources.length; ++i) {
|
||||||
if (sources[i].name == "Electron") {
|
if (sources[i].name == "Electron") {
|
||||||
|
|
|
@ -6,7 +6,7 @@ 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').dialog;
|
const { dialog } = require('electron');
|
||||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -14,7 +14,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.dialog;
|
const { dialog } = require('electron').remote;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
|
@ -8,17 +8,17 @@ control the download item.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
win.webContents.session.on('will-download', function(event, item, webContents) {
|
win.webContents.session.on('will-download', (event, item, webContents) => {
|
||||||
// Set the save path, making Electron not to prompt a save dialog.
|
// Set the save path, making Electron not to prompt a save dialog.
|
||||||
item.setSavePath('/tmp/save.pdf');
|
item.setSavePath('/tmp/save.pdf');
|
||||||
console.log(item.getMimeType());
|
console.log(item.getMimeType());
|
||||||
console.log(item.getFilename());
|
console.log(item.getFilename());
|
||||||
console.log(item.getTotalBytes());
|
console.log(item.getTotalBytes());
|
||||||
item.on('updated', function() {
|
item.on('updated', () => {
|
||||||
console.log('Received bytes: ' + item.getReceivedBytes());
|
console.log('Received bytes: ' + item.getReceivedBytes());
|
||||||
});
|
});
|
||||||
item.on('done', function(e, state) {
|
item.on('done', (e, state) => {
|
||||||
if (state == "completed") {
|
if (state === "completed") {
|
||||||
console.log("Download successfully");
|
console.log("Download successfully");
|
||||||
} else {
|
} else {
|
||||||
console.log("Download is cancelled or interrupted that can't be resumed");
|
console.log("Download is cancelled or interrupted that can't be resumed");
|
||||||
|
|
|
@ -15,16 +15,16 @@ Example on getting a real path from a dragged-onto-the-app file:
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var holder = document.getElementById('holder');
|
const holder = document.getElementById('holder');
|
||||||
holder.ondragover = function () {
|
holder.ondragover = () => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
holder.ondragleave = holder.ondragend = function () {
|
holder.ondragleave = holder.ondragend = () => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
holder.ondrop = function (e) {
|
holder.ondrop = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var file = e.dataTransfer.files[0];
|
const file = e.dataTransfer.files[0];
|
||||||
console.log('File you dragged here is', file.path);
|
console.log('File you dragged here is', file.path);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,8 +14,8 @@ To create a frameless window, you need to set `frame` to `false` in
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
let win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Alternatives on OS X
|
### Alternatives on OS X
|
||||||
|
@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions.
|
||||||
You can do so by specifying the new `titleBarStyle` option:
|
You can do so by specifying the new `titleBarStyle` option:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
|
let win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
|
||||||
```
|
```
|
||||||
|
|
||||||
## Transparent window
|
## Transparent window
|
||||||
|
@ -37,7 +37,7 @@ By setting the `transparent` option to `true`, you can also make the frameless
|
||||||
window transparent:
|
window transparent:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = new BrowserWindow({ transparent: true, frame: false });
|
let win = new BrowserWindow({ transparent: true, frame: false });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|
|
@ -12,12 +12,11 @@ event of the app module is emitted.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app, globalShortcut } = electron;
|
||||||
const globalShortcut = electron.globalShortcut;
|
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
// Register a 'CommandOrControl+X' shortcut listener.
|
// Register a 'CommandOrControl+X' shortcut listener.
|
||||||
var ret = globalShortcut.register('CommandOrControl+X', function() {
|
const ret = globalShortcut.register('CommandOrControl+X', function() {
|
||||||
console.log('CommandOrControl+X is pressed');
|
console.log('CommandOrControl+X is pressed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ app.on('ready', function() {
|
||||||
console.log(globalShortcut.isRegistered('CommandOrControl+X'));
|
console.log(globalShortcut.isRegistered('CommandOrControl+X'));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('will-quit', function() {
|
app.on('will-quit', () => {
|
||||||
// Unregister a shortcut.
|
// Unregister a shortcut.
|
||||||
globalShortcut.unregister('CommandOrControl+X');
|
globalShortcut.unregister('CommandOrControl+X');
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,13 @@ processes:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In main process.
|
// In main process.
|
||||||
const ipcMain = require('electron').ipcMain;
|
const { ipcMain } = require('electron');
|
||||||
ipcMain.on('asynchronous-message', function(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');
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('synchronous-message', function(event, arg) {
|
ipcMain.on('synchronous-message', (event, arg) => {
|
||||||
console.log(arg); // prints "ping"
|
console.log(arg); // prints "ping"
|
||||||
event.returnValue = 'pong';
|
event.returnValue = 'pong';
|
||||||
});
|
});
|
||||||
|
@ -37,10 +37,10 @@ ipcMain.on('synchronous-message', function(event, arg) {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In renderer process (web page).
|
// In renderer process (web page).
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
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', function(event, arg) {
|
ipcRenderer.on('asynchronous-reply', (event, arg) => {
|
||||||
console.log(arg); // prints "pong"
|
console.log(arg); // prints "pong"
|
||||||
});
|
});
|
||||||
ipcRenderer.send('asynchronous-message', 'ping');
|
ipcRenderer.send('asynchronous-message', 'ping');
|
||||||
|
|
|
@ -15,16 +15,14 @@ the user right clicks the page:
|
||||||
```html
|
```html
|
||||||
<!-- index.html -->
|
<!-- index.html -->
|
||||||
<script>
|
<script>
|
||||||
const remote = require('electron').remote;
|
const { Menu, MenuItem } = require('electron').remote;
|
||||||
const Menu = remote.Menu;
|
|
||||||
const MenuItem = remote.MenuItem;
|
|
||||||
|
|
||||||
var menu = new Menu();
|
const menu = new Menu();
|
||||||
menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked'); } }));
|
menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } }));
|
||||||
menu.append(new MenuItem({ type: 'separator' }));
|
menu.append(new MenuItem({ type: 'separator' }));
|
||||||
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
|
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
|
||||||
|
|
||||||
window.addEventListener('contextmenu', function (e) {
|
window.addEventListener('contextmenu', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
menu.popup(remote.getCurrentWindow());
|
menu.popup(remote.getCurrentWindow());
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -35,7 +33,7 @@ An example of creating the application menu in the render process with the
|
||||||
simple template API:
|
simple template API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var template = [
|
const template = [
|
||||||
{
|
{
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -80,33 +78,32 @@ var template = [
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: function(item, focusedWindow) {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.reload();
|
||||||
focusedWindow.reload();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: (function() {
|
accelerator: (() => {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform === 'darwin')
|
||||||
return 'Ctrl+Command+F';
|
return 'Ctrl+Command+F';
|
||||||
else
|
else
|
||||||
return 'F11';
|
return 'F11';
|
||||||
})(),
|
})(),
|
||||||
click: function(item, focusedWindow) {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow)
|
if (focusedWindow)
|
||||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: (function() {
|
accelerator: (() => {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform == 'darwin')
|
||||||
return 'Alt+Command+I';
|
return 'Alt+Command+I';
|
||||||
else
|
else
|
||||||
return 'Ctrl+Shift+I';
|
return 'Ctrl+Shift+I';
|
||||||
})(),
|
})(),
|
||||||
click: function(item, focusedWindow) {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow)
|
if (focusedWindow)
|
||||||
focusedWindow.webContents.toggleDevTools();
|
focusedWindow.webContents.toggleDevTools();
|
||||||
}
|
}
|
||||||
|
@ -135,14 +132,14 @@ var template = [
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click: function() { require('electron').shell.openExternal('http://electron.atom.io') }
|
click: () => { require('electron').shell.openExternal('http://electron.atom.io') }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
var name = require('electron').remote.app.getName();
|
const name = require('electron').remote.app.getName();
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: name,
|
label: name,
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -181,7 +178,7 @@ if (process.platform == 'darwin') {
|
||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
accelerator: 'Command+Q',
|
accelerator: 'Command+Q',
|
||||||
click: function() { app.quit(); }
|
click: () => { app.quit(); }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -197,7 +194,7 @@ if (process.platform == 'darwin') {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var menu = Menu.buildFromTemplate(template);
|
const menu = Menu.buildFromTemplate(template);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,15 @@ For example, when creating a tray or setting a window's icon, you can pass an
|
||||||
image file path as a `String`:
|
image file path as a `String`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var appIcon = new Tray('/Users/somebody/images/icon.png');
|
const appIcon = new Tray('/Users/somebody/images/icon.png');
|
||||||
var window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});
|
let window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});
|
||||||
```
|
```
|
||||||
|
|
||||||
Or read the image from the clipboard which returns a `nativeImage`:
|
Or read the image from the clipboard which returns a `nativeImage`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var image = clipboard.readImage();
|
const image = clipboard.readImage();
|
||||||
var appIcon = new Tray(image);
|
const appIcon = new Tray(image);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Supported Formats
|
## Supported Formats
|
||||||
|
|
|
@ -8,8 +8,8 @@ event of the `app` module is emitted.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
require('electron').powerMonitor.on('suspend', function() {
|
require('electron').powerMonitor.on('suspend', () => {
|
||||||
console.log('The system is going to sleep');
|
console.log('The system is going to sleep');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const powerSaveBlocker = require('electron').powerSaveBlocker;
|
const { powerSaveBlocker } = require('electron');
|
||||||
|
|
||||||
var id = powerSaveBlocker.start('prevent-display-sleep');
|
const id = powerSaveBlocker.start('prevent-display-sleep');
|
||||||
console.log(powerSaveBlocker.isStarted(id));
|
console.log(powerSaveBlocker.isStarted(id));
|
||||||
|
|
||||||
powerSaveBlocker.stop(id);
|
powerSaveBlocker.stop(id);
|
||||||
|
|
|
@ -27,8 +27,8 @@ the global scope when node integration is turned off:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// preload.js
|
// preload.js
|
||||||
var _setImmediate = setImmediate;
|
const _setImmediate = setImmediate;
|
||||||
var _clearImmediate = clearImmediate;
|
const _clearImmediate = clearImmediate;
|
||||||
process.once('loaded', function() {
|
process.once('loaded', function() {
|
||||||
global.setImmediate = _setImmediate;
|
global.setImmediate = _setImmediate;
|
||||||
global.clearImmediate = _clearImmediate;
|
global.clearImmediate = _clearImmediate;
|
||||||
|
|
|
@ -7,13 +7,13 @@ An example of implementing a protocol that has the same effect as the
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app } = electron;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
var protocol = electron.protocol;
|
const { protocol } = electron;
|
||||||
protocol.registerFileProtocol('atom', function(request, callback) {
|
protocol.registerFileProtocol('atom', function(request, callback) {
|
||||||
var url = request.url.substr(7);
|
const url = request.url.substr(7);
|
||||||
callback({path: path.normalize(__dirname + '/' + url)});
|
callback({path: path.normalize(__dirname + '/' + url)});
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -95,9 +95,9 @@ should be called with either a `Buffer` object or an object that has the `data`,
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
protocol.registerBufferProtocol('atom', function(request, callback) {
|
protocol.registerBufferProtocol('atom', (request, callback) => {
|
||||||
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')});
|
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')});
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
console.error('Failed to register protocol')
|
console.error('Failed to register protocol')
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,8 +14,7 @@ similar to Java's [RMI][rmi]. An example of creating a browser window from a
|
||||||
renderer process:
|
renderer process:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const remote = require('electron').remote;
|
const { BrowserWindow } = require('electron').remote;
|
||||||
const BrowserWindow = remote.BrowserWindow;
|
|
||||||
|
|
||||||
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');
|
||||||
|
@ -69,26 +68,22 @@ For instance you can't use a function from the renderer process in an
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// main process mapNumbers.js
|
// main process mapNumbers.js
|
||||||
exports.withRendererCallback = function(mapper) {
|
exports.withRendererCallback = (mapper) => {
|
||||||
return [1,2,3].map(mapper);
|
return [1,2,3].map(mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.withLocalCallback = function() {
|
exports.withLocalCallback = () => {
|
||||||
return exports.mapNumbers(function(x) {
|
return exports.mapNumbers(x => x + 1);
|
||||||
return x + 1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// renderer process
|
// renderer process
|
||||||
var mapNumbers = require("remote").require("./mapNumbers");
|
const mapNumbers = require("remote").require("./mapNumbers");
|
||||||
|
|
||||||
var withRendererCb = mapNumbers.withRendererCallback(function(x) {
|
const withRendererCb = mapNumbers.withRendererCallback(x => x + 1);
|
||||||
return x + 1;
|
|
||||||
})
|
|
||||||
|
|
||||||
var withLocalCb = mapNumbers.withLocalCallback()
|
const withLocalCb = mapNumbers.withLocalCallback()
|
||||||
|
|
||||||
console.log(withRendererCb, withLocalCb) // [true, true, true], [2, 3, 4]
|
console.log(withRendererCb, withLocalCb) // [true, true, true], [2, 3, 4]
|
||||||
```
|
```
|
||||||
|
@ -104,7 +99,7 @@ For example, the following code seems innocent at first glance. It installs a
|
||||||
callback for the `close` event on a remote object:
|
callback for the `close` event on a remote object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
remote.getCurrentWindow().on('close', function() {
|
remote.getCurrentWindow().on('close', () => {
|
||||||
// blabla...
|
// blabla...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -14,15 +14,13 @@ An example of creating a window that fills the whole screen:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app, BrowserWindow } = electron;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
|
|
||||||
var mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
var electronScreen = electron.screen;
|
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
|
||||||
var size = electronScreen.getPrimaryDisplay().workAreaSize;
|
mainWindow = new BrowserWindow({ width, height });
|
||||||
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -30,16 +28,15 @@ Another example of creating a window in the external display:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const { app, BrowserWindow } = electron;
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
|
|
||||||
var mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', () => {
|
||||||
var electronScreen = electron.screen;
|
var electronScreen = electron.screen;
|
||||||
var displays = electronScreen.getAllDisplays();
|
var displays = electronScreen.getAllDisplays();
|
||||||
var externalDisplay = null;
|
var externalDisplay = null;
|
||||||
for (var i in displays) {
|
for (let i in displays) {
|
||||||
if (displays[i].bounds.x != 0 || displays[i].bounds.y != 0) {
|
if (displays[i].bounds.x != 0 || displays[i].bounds.y != 0) {
|
||||||
externalDisplay = displays[i];
|
externalDisplay = displays[i];
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,12 +9,12 @@ 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').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
var 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");
|
||||||
|
|
||||||
var ses = win.webContents.session;
|
const ses = win.webContents.session;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
@ -47,7 +47,7 @@ You can create a `Session` object in the `session` module:
|
||||||
```javascript
|
```javascript
|
||||||
const session = require('electron').session;
|
const session = require('electron').session;
|
||||||
|
|
||||||
var ses = session.fromPartition('persist:name');
|
const ses = session.fromPartition('persist:name');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Instance Events
|
### Instance Events
|
||||||
|
@ -66,9 +66,9 @@ Calling `event.preventDefault()` will cancel the download and `item` will not be
|
||||||
available from next tick of the process.
|
available from next tick of the process.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.defaultSession.on('will-download', function(event, item, webContents) {
|
session.defaultSession.on('will-download', (event, item, webContents) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
require('request')(item.getURL(), function(data) {
|
require('request')(item.getURL(), (data) => {
|
||||||
require('fs').writeFileSync('/somewhere', data);
|
require('fs').writeFileSync('/somewhere', data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -84,19 +84,19 @@ The `cookies` gives you ability to query and modify cookies. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Query all cookies.
|
// Query all cookies.
|
||||||
session.defaultSession.cookies.get({}, function(error, cookies) {
|
session.defaultSession.cookies.get({}, (error, cookies) => {
|
||||||
console.log(cookies);
|
console.log(cookies);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Query all cookies associated with a specific url.
|
// Query all cookies associated with a specific url.
|
||||||
session.defaultSession.cookies.get({ url : "http://www.github.com" }, function(error, cookies) {
|
session.defaultSession.cookies.get({ url : "http://www.github.com" }, (error, cookies) => {
|
||||||
console.log(cookies);
|
console.log(cookies);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set a cookie with the given cookie data;
|
// Set a cookie with the given cookie data;
|
||||||
// may overwrite equivalent cookies if they exist.
|
// may overwrite equivalent cookies if they exist.
|
||||||
var 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, function(error) {
|
session.defaultSession.cookies.set(cookie, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
@ -285,8 +285,8 @@ Calling `setCertificateVerifyProc(null)` will revert back to default certificate
|
||||||
verify proc.
|
verify proc.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
myWindow.webContents.session.setCertificateVerifyProc(function(hostname, cert, callback) {
|
myWindow.webContents.session.setCertificateVerifyProc((hostname, cert, callback) => {
|
||||||
if (hostname == 'github.com')
|
if (hostname === 'github.com')
|
||||||
callback(true);
|
callback(true);
|
||||||
else
|
else
|
||||||
callback(false);
|
callback(false);
|
||||||
|
@ -305,9 +305,9 @@ Sets the handler which can be used to respond to permission requests for the `se
|
||||||
Calling `callback(true)` will allow the permission and `callback(false)` will reject it.
|
Calling `callback(true)` will allow the permission and `callback(false)` will reject it.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) {
|
session.fromPartition(partition).setPermissionRequestHandler((webContents, permission, callback) => {
|
||||||
if (webContents.getURL() === host) {
|
if (webContents.getURL() === host) {
|
||||||
if (permission == "notifications") {
|
if (permission === "notifications") {
|
||||||
callback(false); // denied.
|
callback(false); // denied.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -342,11 +342,11 @@ called with an `response` object when `listener` has done its work.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Modify the user agent for all requests to the following urls.
|
// Modify the user agent for all requests to the following urls.
|
||||||
var filter = {
|
const filter = {
|
||||||
urls: ["https://*.github.com/*", "*://electron.github.io"]
|
urls: ["https://*.github.com/*", "*://electron.github.io"]
|
||||||
};
|
};
|
||||||
|
|
||||||
session.defaultSession.webRequest.onBeforeSendHeaders(filter, function(details, callback) {
|
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
|
||||||
details.requestHeaders['User-Agent'] = "MyAgent";
|
details.requestHeaders['User-Agent'] = "MyAgent";
|
||||||
callback({cancel: false, requestHeaders: details.requestHeaders});
|
callback({cancel: false, requestHeaders: details.requestHeaders});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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').shell;
|
const { shell } = require('electron');
|
||||||
|
|
||||||
shell.openExternal('https://github.com');
|
shell.openExternal('https://github.com');
|
||||||
```
|
```
|
||||||
|
|
|
@ -56,7 +56,7 @@ 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):
|
not (transparent windows won't work correctly when DWM composition is disabled):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let browserOptions = {width: 1000, height: 800};
|
let browserOptions = { width: 1000, height: 800 };
|
||||||
|
|
||||||
// Make the window transparent only if the platform supports it.
|
// Make the window transparent only if the platform supports it.
|
||||||
if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) {
|
if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) {
|
||||||
|
|
|
@ -8,10 +8,10 @@ const app = electron.app;
|
||||||
const Menu = electron.Menu;
|
const Menu = electron.Menu;
|
||||||
const Tray = electron.Tray;
|
const Tray = electron.Tray;
|
||||||
|
|
||||||
var appIcon = null;
|
let appIcon = null;
|
||||||
app.on('ready', function(){
|
app.on('ready', () => {
|
||||||
appIcon = new Tray('/path/to/my/icon');
|
appIcon = new Tray('/path/to/my/icon');
|
||||||
var contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'Item1', type: 'radio' },
|
{ label: 'Item1', type: 'radio' },
|
||||||
{ label: 'Item2', type: 'radio' },
|
{ label: 'Item2', type: 'radio' },
|
||||||
{ label: 'Item3', type: 'radio', checked: true },
|
{ label: 'Item3', type: 'radio', checked: true },
|
||||||
|
@ -20,7 +20,6 @@ app.on('ready', function(){
|
||||||
appIcon.setToolTip('This is my application.');
|
appIcon.setToolTip('This is my application.');
|
||||||
appIcon.setContextMenu(contextMenu);
|
appIcon.setContextMenu(contextMenu);
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
__Platform limitations:__
|
__Platform limitations:__
|
||||||
|
|
|
@ -9,12 +9,12 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the
|
||||||
`webContents` object:
|
`webContents` object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
|
|
||||||
var 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");
|
||||||
|
|
||||||
var webContents = win.webContents;
|
let webContents = win.webContents;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
@ -341,10 +341,10 @@ Initiates a download of the resource at `url` without navigating. The
|
||||||
Returns URL of the current web page.
|
Returns URL of the current web page.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var 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");
|
||||||
|
|
||||||
var currentURL = win.webContents.getURL();
|
let currentURL = win.webContents.getURL();
|
||||||
```
|
```
|
||||||
|
|
||||||
### `webContents.getTitle()`
|
### `webContents.getTitle()`
|
||||||
|
@ -614,22 +614,22 @@ By default, an empty `options` will be regarded as:
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const BrowserWindow = require('electron').BrowserWindow;
|
const { BrowserWindow } = require('electron');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var 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');
|
||||||
|
|
||||||
win.webContents.on("did-finish-load", function() {
|
win.webContents.on('did-finish-load', () => {
|
||||||
// Use default printing options
|
// Use default printing options
|
||||||
win.webContents.printToPDF({}, function(error, data) {
|
win.webContents.printToPDF({}, (error, data) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
fs.writeFile("/tmp/print.pdf", data, function(error) {
|
fs.writeFile('/tmp/print.pdf', data, (error) => {
|
||||||
if (error)
|
if (error)
|
||||||
throw error;
|
throw error;
|
||||||
console.log("Write PDF successfully.");
|
console.log('Write PDF successfully.');
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -704,12 +704,13 @@ An example of sending messages from the main process to the renderer process:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// In the main process.
|
||||||
var window = null;
|
let mainWindow = null;
|
||||||
app.on('ready', function() {
|
|
||||||
window = new BrowserWindow({width: 800, height: 600});
|
app.on('ready', () => {
|
||||||
window.loadURL('file://' + __dirname + '/index.html');
|
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||||
window.webContents.on('did-finish-load', function() {
|
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||||
window.webContents.send('ping', 'whoooooooh!');
|
mainWindow.webContents.on('did-finish-load', () => {
|
||||||
|
mainWindow.webContents.send('ping', 'whoooooooh!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -719,7 +720,7 @@ app.on('ready', function() {
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
require('electron').ipcRenderer.on('ping', function(event, message) {
|
require('electron').ipcRenderer.on('ping', (event, message) => {
|
||||||
console.log(message); // Prints "whoooooooh!"
|
console.log(message); // Prints "whoooooooh!"
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -835,8 +836,8 @@ Returns true if the process of saving page has been initiated successfully.
|
||||||
```javascript
|
```javascript
|
||||||
win.loadURL('https://github.com');
|
win.loadURL('https://github.com');
|
||||||
|
|
||||||
win.webContents.on('did-finish-load', function() {
|
win.webContents.on('did-finish-load', () => {
|
||||||
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', function(error) {
|
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', (error) => {
|
||||||
if (!error)
|
if (!error)
|
||||||
console.log("Save page successfully");
|
console.log("Save page successfully");
|
||||||
});
|
});
|
||||||
|
@ -873,13 +874,13 @@ try {
|
||||||
console.log("Debugger attach failed : ", err);
|
console.log("Debugger attach failed : ", err);
|
||||||
};
|
};
|
||||||
|
|
||||||
win.webContents.debugger.on('detach', function(event, reason) {
|
win.webContents.debugger.on('detach', (event, reason) => {
|
||||||
console.log("Debugger detached due to : ", reason);
|
console.log("Debugger detached due to : ", reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.webContents.debugger.on('message', function(event, method, params) {
|
win.webContents.debugger.on('message', (event, method, params) => {
|
||||||
if (method == "Network.requestWillBeSent") {
|
if (method === "Network.requestWillBeSent") {
|
||||||
if (params.request.url == "https://www.github.com")
|
if (params.request.url === "https://www.github.com")
|
||||||
win.webContents.debugger.detach();
|
win.webContents.debugger.detach();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
An example of zooming current page to 200%.
|
An example of zooming current page to 200%.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var webFrame = require('electron').webFrame;
|
const { webFrame } = require('electron');
|
||||||
|
|
||||||
webFrame.setZoomFactor(2);
|
webFrame.setZoomFactor(2);
|
||||||
```
|
```
|
||||||
|
|
|
@ -31,18 +31,20 @@ and displays a "loading..." message during the load time:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
onload = function() {
|
onload = () => {
|
||||||
var webview = document.getElementById("foo");
|
const webview = document.getElementById('foo');
|
||||||
var indicator = document.querySelector(".indicator");
|
const indicator = document.querySelector('.indicator');
|
||||||
|
|
||||||
var loadstart = function() {
|
const loadstart = () => {
|
||||||
indicator.innerText = "loading...";
|
indicator.innerText = 'loading...';
|
||||||
}
|
}
|
||||||
var loadstop = function() {
|
|
||||||
indicator.innerText = "";
|
const loadstop = () => {
|
||||||
|
indicator.innerText = '';
|
||||||
}
|
}
|
||||||
webview.addEventListener("did-start-loading", loadstart);
|
|
||||||
webview.addEventListener("did-stop-loading", loadstop);
|
webview.addEventListener('did-start-loading', loadstart);
|
||||||
|
webview.addEventListener('did-stop-loading', loadstop);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
@ -211,7 +213,7 @@ The `webview` tag has the following methods:
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener("dom-ready", function() {
|
webview.addEventListener("dom-ready", () => {
|
||||||
webview.openDevTools();
|
webview.openDevTools();
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -642,10 +644,12 @@ 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
|
||||||
webview.addEventListener('new-window', function(e) {
|
const { shell } = require('electron');
|
||||||
var protocol = require('url').parse(e.url).protocol;
|
|
||||||
|
webview.addEventListener('new-window', (e) => {
|
||||||
|
const protocol = require('url').parse(e.url).protocol;
|
||||||
if (protocol === 'http:' || protocol === 'https:') {
|
if (protocol === 'http:' || protocol === 'https:') {
|
||||||
require('electron').shell.openExternal(e.url);
|
shell.openExternal(e.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -700,7 +704,7 @@ The following example code navigates the `webview` to `about:blank` when the
|
||||||
guest attempts to close itself.
|
guest attempts to close itself.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('close', function() {
|
webview.addEventListener('close', () => {
|
||||||
webview.src = 'about:blank';
|
webview.src = 'about:blank';
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -719,7 +723,7 @@ between guest page and embedder page:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In embedder page.
|
// In embedder page.
|
||||||
webview.addEventListener('ipc-message', function(event) {
|
webview.addEventListener('ipc-message', (event) => {
|
||||||
console.log(event.channel);
|
console.log(event.channel);
|
||||||
// Prints "pong"
|
// Prints "pong"
|
||||||
});
|
});
|
||||||
|
@ -728,8 +732,8 @@ webview.send('ping');
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In guest page.
|
// In guest page.
|
||||||
var ipcRenderer = require('electron').ipcRenderer;
|
var { ipcRenderer } = require('electron');
|
||||||
ipcRenderer.on('ping', function() {
|
ipcRenderer.on('ping', () => {
|
||||||
ipcRenderer.sendToHost('pong');
|
ipcRenderer.sendToHost('pong');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue