docs: Update codes in docs to use require('electron')
This commit is contained in:
parent
8b2942c279
commit
eac2e7cc61
32 changed files with 134 additions and 157 deletions
|
@ -31,32 +31,32 @@
|
||||||
### Modules for the Main Process:
|
### Modules for the Main Process:
|
||||||
|
|
||||||
* [app](api/app.md)
|
* [app](api/app.md)
|
||||||
* [auto-updater](api/auto-updater.md)
|
* [autoUpdater](api/auto-updater.md)
|
||||||
* [browser-window](api/browser-window.md)
|
* [BrowserWindow](api/browser-window.md)
|
||||||
* [content-tracing](api/content-tracing.md)
|
* [contentTracing](api/content-tracing.md)
|
||||||
* [dialog](api/dialog.md)
|
* [dialog](api/dialog.md)
|
||||||
* [global-shortcut](api/global-shortcut.md)
|
* [globalShortcut](api/global-shortcut.md)
|
||||||
* [ipc-main](api/ipc-main.md)
|
* [ipcMain](api/ipc-main.md)
|
||||||
* [menu](api/menu.md)
|
* [Menu](api/menu.md)
|
||||||
* [menu-item](api/menu-item.md)
|
* [MenuItem](api/menu-item.md)
|
||||||
* [power-monitor](api/power-monitor.md)
|
* [powerMonitor](api/power-monitor.md)
|
||||||
* [power-save-blocker](api/power-save-blocker.md)
|
* [powerSaveBlocker](api/power-save-blocker.md)
|
||||||
* [protocol](api/protocol.md)
|
* [protocol](api/protocol.md)
|
||||||
* [session](api/session.md)
|
* [session](api/session.md)
|
||||||
* [web-contents](api/web-contents.md)
|
* [webContents](api/web-contents.md)
|
||||||
* [tray](api/tray.md)
|
* [Tray](api/tray.md)
|
||||||
|
|
||||||
### Modules for the Renderer Process (Web Page):
|
### Modules for the Renderer Process (Web Page):
|
||||||
|
|
||||||
* [ipc-renderer](api/ipc-renderer.md)
|
* [ipcRenderer](api/ipc-renderer.md)
|
||||||
* [remote](api/remote.md)
|
* [remote](api/remote.md)
|
||||||
* [web-frame](api/web-frame.md)
|
* [webFrame](api/web-frame.md)
|
||||||
|
|
||||||
### Modules for Both Processes:
|
### Modules for Both Processes:
|
||||||
|
|
||||||
* [clipboard](api/clipboard.md)
|
* [clipboard](api/clipboard.md)
|
||||||
* [crash-reporter](api/crash-reporter.md)
|
* [crashReporter](api/crash-reporter.md)
|
||||||
* [native-image](api/native-image.md)
|
* [nativeImage](api/native-image.md)
|
||||||
* [screen](api/screen.md)
|
* [screen](api/screen.md)
|
||||||
* [shell](api/shell.md)
|
* [shell](api/shell.md)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ The following example shows how to quit the application when the last window is
|
||||||
closed:
|
closed:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const app = require('electron').app;
|
||||||
app.on('window-all-closed', function() {
|
app.on('window-all-closed', function() {
|
||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@ The `BrowserWindow` class gives you the ability to create a browser window. For
|
||||||
example:
|
example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, show: false });
|
var win = new BrowserWindow({ width: 800, height: 600, show: false });
|
||||||
win.on('closed', function() {
|
win.on('closed', function() {
|
||||||
|
@ -291,11 +291,8 @@ Remove the DevTools extension whose name is `name`.
|
||||||
Objects created with `new BrowserWindow` have the following properties:
|
Objects created with `new BrowserWindow` have the following properties:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
|
||||||
|
|
||||||
// In this example `win` is our instance
|
// In this example `win` is our instance
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
var win = new BrowserWindow({ width: 800, height: 600 });
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### `win.webContents`
|
### `win.webContents`
|
||||||
|
@ -316,14 +313,6 @@ Objects created with `new BrowserWindow` have the following instance methods:
|
||||||
|
|
||||||
**Note:** Some methods are only available on specific operating systems and are labeled as such.
|
**Note:** Some methods are only available on specific operating systems and are labeled as such.
|
||||||
|
|
||||||
```javascript
|
|
||||||
var BrowserWindow = require('browser-window');
|
|
||||||
|
|
||||||
// In this example `win` is our instance
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### `win.destroy()`
|
### `win.destroy()`
|
||||||
|
|
||||||
Force closing the window, the `unload` and `beforeunload` event won't be emitted
|
Force closing the window, the `unload` and `beforeunload` event won't be emitted
|
||||||
|
|
|
@ -6,7 +6,7 @@ them in your app's main script before the [ready][ready] event of [app][app]
|
||||||
module is emitted:
|
module is emitted:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const app = require('electron').app;
|
||||||
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');
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ The `clipboard` module provides methods to perform copy and paste operations.
|
||||||
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
|
||||||
var clipboard = require('clipboard');
|
const clipboard = require('electron').clipboard;
|
||||||
clipboard.writeText('Example String');
|
clipboard.writeText('Example String');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ On X Window systems, there is also a selection clipboard. To manipulate it
|
||||||
you need to pass `selection` to each method:
|
you need to pass `selection` to each method:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var clipboard = require('clipboard');
|
|
||||||
clipboard.writeText('Example String', 'selection');
|
clipboard.writeText('Example String', 'selection');
|
||||||
console.log(clipboard.readText('selection'));
|
console.log(clipboard.readText('selection'));
|
||||||
```
|
```
|
||||||
|
@ -82,7 +81,6 @@ Returns an array of supported formats for the clipboard `type`.
|
||||||
Returns whether the clipboard supports the format of specified `data`.
|
Returns whether the clipboard supports the format of specified `data`.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var clipboard = require('clipboard');
|
|
||||||
console.log(clipboard.has('<p>selection</p>'));
|
console.log(clipboard.has('<p>selection</p>'));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -102,7 +100,6 @@ Reads `data` from the clipboard.
|
||||||
* `type` String (optional)
|
* `type` String (optional)
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var clipboard = require('clipboard');
|
|
||||||
clipboard.write({text: 'test', html: "<b>test</b>"});
|
clipboard.write({text: 'test', html: "<b>test</b>"});
|
||||||
```
|
```
|
||||||
Writes `data` to the clipboard.
|
Writes `data` to the clipboard.
|
||||||
|
|
|
@ -6,7 +6,7 @@ so you need to open `chrome://tracing/` in a Chrome browser and load the
|
||||||
generated file to view the result.
|
generated file to view the result.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var contentTracing = require('content-tracing');
|
const contentTracing = require('electron').contentTracing;
|
||||||
|
|
||||||
contentTracing.startRecording('*', contentTracing.DEFAULT_OPTIONS, function() {
|
contentTracing.startRecording('*', contentTracing.DEFAULT_OPTIONS, function() {
|
||||||
console.log('Tracing started');
|
console.log('Tracing started');
|
||||||
|
|
|
@ -6,7 +6,7 @@ The following is an example of automatically submitting a crash report to a
|
||||||
remote server:
|
remote server:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var crashReporter = require('crash-reporter');
|
const crashReporter = require('electron').crashReporter;
|
||||||
|
|
||||||
crashReporter.start({
|
crashReporter.start({
|
||||||
productName: 'YourName',
|
productName: 'YourName',
|
||||||
|
|
|
@ -8,7 +8,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
|
||||||
var dialog = require('dialog');
|
const dialog = require('electron').dialog;
|
||||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ To create a frameless window, you need to set `frame` to `false` in
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ the window controls ("traffic lights") for standard window actions.
|
||||||
You can do so by specifying the new `title-bar-style` option:
|
You can do so by specifying the new `title-bar-style` option:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
var win = new BrowserWindow({ 'title-bar-style': 'hidden' });
|
||||||
var win = new BrowserWindow({ width: 800, height: 600, 'title-bar-style': 'hidden' });
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Transparent window
|
## Transparent window
|
||||||
|
|
|
@ -9,8 +9,9 @@ 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
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var globalShortcut = require('global-shortcut');
|
const app = electron.app;
|
||||||
|
const globalShortcut = electron.globalShortcut;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
// Register a 'ctrl+x' shortcut listener.
|
// Register a 'ctrl+x' shortcut listener.
|
||||||
|
|
|
@ -19,7 +19,7 @@ processes:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In main process.
|
// In main process.
|
||||||
var ipcMain = require('ipc-main');
|
const ipcMain = require('electron').ipcMain;
|
||||||
ipcMain.on('asynchronous-message', function(event, arg) {
|
ipcMain.on('asynchronous-message', function(event, arg) {
|
||||||
console.log(arg); // prints "ping"
|
console.log(arg); // prints "ping"
|
||||||
event.sender.send('asynchronous-reply', 'pong');
|
event.sender.send('asynchronous-reply', 'pong');
|
||||||
|
@ -33,7 +33,7 @@ ipcMain.on('synchronous-message', function(event, arg) {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In renderer process (web page).
|
// In renderer process (web page).
|
||||||
var ipcRenderer = require('ipc-renderer');
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
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', function(event, arg) {
|
||||||
|
|
|
@ -16,9 +16,9 @@ the user right clicks the page:
|
||||||
```html
|
```html
|
||||||
<!-- index.html -->
|
<!-- index.html -->
|
||||||
<script>
|
<script>
|
||||||
var remote = require('remote');
|
const remote = require('electron').remote;
|
||||||
var Menu = remote.require('menu');
|
const Menu = remote.require('electron').Menu;
|
||||||
var MenuItem = remote.require('menu-item');
|
const MenuItem = remote.require('electron').MenuItem;
|
||||||
|
|
||||||
var menu = new Menu();
|
var menu = new Menu();
|
||||||
menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked'); } }));
|
menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked'); } }));
|
||||||
|
@ -136,14 +136,14 @@ var template = [
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click: function() { require('shell').openExternal('http://electron.atom.io') }
|
click: function() { require('electron').shell.openExternal('http://electron.atom.io') }
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform == 'darwin') {
|
||||||
var name = require('app').getName();
|
var name = require('electron').app.getName();
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: name,
|
label: name,
|
||||||
submenu: [
|
submenu: [
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# NativeImage
|
# nativeImage
|
||||||
|
|
||||||
In Electron, for the APIs that take images, you can pass either file paths or
|
In Electron, for the APIs that take images, you can pass either file paths or
|
||||||
`NativeImage` instances. An empty image will be used when `null` is passed.
|
`nativeImage` instances. An empty image will be used when `null` is passed.
|
||||||
|
|
||||||
For example, when creating a tray or setting a window's icon, you can pass an
|
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`:
|
||||||
|
@ -11,10 +11,9 @@ var appIcon = new Tray('/Users/somebody/images/icon.png');
|
||||||
var window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});
|
var 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 clipboard = require('clipboard');
|
|
||||||
var image = clipboard.readImage();
|
var image = clipboard.readImage();
|
||||||
var appIcon = new Tray(image);
|
var appIcon = new Tray(image);
|
||||||
```
|
```
|
||||||
|
@ -84,40 +83,40 @@ To mark an image as a template image, its filename should end with the word
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
The `NativeImage` class has the following methods:
|
The `nativeImage` class has the following methods:
|
||||||
|
|
||||||
### `NativeImage.createEmpty()`
|
### `nativeImage.createEmpty()`
|
||||||
|
|
||||||
Creates an empty `NativeImage` instance.
|
Creates an empty `nativeImage` instance.
|
||||||
|
|
||||||
### `NativeImage.createFromPath(path)`
|
### `nativeImage.createFromPath(path)`
|
||||||
|
|
||||||
* `path` String
|
* `path` String
|
||||||
|
|
||||||
Creates a new `NativeImage` instance from a file located at `path`.
|
Creates a new `nativeImage` instance from a file located at `path`.
|
||||||
|
|
||||||
### `NativeImage.createFromBuffer(buffer[, scaleFactor])`
|
### `nativeImage.createFromBuffer(buffer[, scaleFactor])`
|
||||||
|
|
||||||
* `buffer` [Buffer][buffer]
|
* `buffer` [Buffer][buffer]
|
||||||
* `scaleFactor` Double (optional)
|
* `scaleFactor` Double (optional)
|
||||||
|
|
||||||
Creates a new `NativeImage` instance from `buffer`. The default `scaleFactor` is
|
Creates a new `nativeImage` instance from `buffer`. The default `scaleFactor` is
|
||||||
1.0.
|
1.0.
|
||||||
|
|
||||||
### `NativeImage.createFromDataUrl(dataUrl)`
|
### `nativeImage.createFromDataUrl(dataUrl)`
|
||||||
|
|
||||||
* `dataUrl` String
|
* `dataUrl` String
|
||||||
|
|
||||||
Creates a new `NativeImage` instance from `dataUrl`.
|
Creates a new `nativeImage` instance from `dataUrl`.
|
||||||
|
|
||||||
## Instance Methods
|
## Instance Methods
|
||||||
|
|
||||||
The following methods are available on instances of `nativeImage`:
|
The following methods are available on instances of `nativeImage`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var NativeImage = require('native-image');
|
const nativeImage = require('electron').nativeImage;
|
||||||
|
|
||||||
var image = NativeImage.createFromPath('/Users/somebody/images/icon.png');
|
var image = nativeImage.createFromPath('/Users/somebody/images/icon.png');
|
||||||
```
|
```
|
||||||
|
|
||||||
### `image.toPng()`
|
### `image.toPng()`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# power-monitor
|
# powerMonitor
|
||||||
|
|
||||||
The `power-monitor` module is used to monitor power state changes. You can
|
The `power-monitor` module is used to monitor power state changes. You can
|
||||||
only use it in the main process. You should not use this module until the `ready`
|
only use it in the main process. You should not use this module until the `ready`
|
||||||
|
@ -7,10 +7,8 @@ event of the `app` module is emitted.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
require('power-monitor').on('suspend', function() {
|
require('electron').powerMonitor.on('suspend', function() {
|
||||||
console.log('The system is going to sleep');
|
console.log('The system is going to sleep');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# powerSaveBlocker
|
# powerSaveBlocker
|
||||||
|
|
||||||
The `power-save-blocker` module is used to block the system from entering
|
The `powerSaveBlocker` module is used to block the system from entering
|
||||||
low-power (sleep) mode and thus allowing the app to keep the system and screen
|
low-power (sleep) mode and thus allowing the app to keep the system and screen
|
||||||
active.
|
active.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var powerSaveBlocker = require('power-save-blocker');
|
const powerSaveBlocker = require('electron').powerSaveBlocker;
|
||||||
|
|
||||||
var id = powerSaveBlocker.start('prevent-display-sleep');
|
var id = powerSaveBlocker.start('prevent-display-sleep');
|
||||||
console.log(powerSaveBlocker.isStarted(id));
|
console.log(powerSaveBlocker.isStarted(id));
|
||||||
|
|
|
@ -7,11 +7,12 @@ An example of implementing a protocol that has the same effect as the
|
||||||
`file://` protocol:
|
`file://` protocol:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var path = require('path');
|
const app = electron.app;
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
var protocol = require('protocol');
|
var protocol = electron.protocol;
|
||||||
protocol.registerFileProtocol('atom', function(request, callback) {
|
protocol.registerFileProtocol('atom', function(request, callback) {
|
||||||
var url = request.url.substr(7);
|
var url = request.url.substr(7);
|
||||||
callback({path: path.normalize(__dirname + '/' + url)});
|
callback({path: path.normalize(__dirname + '/' + url)});
|
||||||
|
|
|
@ -3,13 +3,17 @@
|
||||||
The `remote` module provides a simple way to do inter-process communication
|
The `remote` module provides a simple way to do inter-process communication
|
||||||
(IPC) between the renderer process (web page) and the main process.
|
(IPC) between the renderer process (web page) and the main process.
|
||||||
|
|
||||||
In Electron, GUI-related modules (such as `dialog`, `menu` etc.) are only available in the main process, not in the renderer process. In order to use them from the renderer process, the `ipc` module is necessary to send inter-process messages to the main process. With the `remote` module, you can invoke methods of the main process object without explicitly sending inter-process messages, similar to Java's [RMI](http://en.wikipedia.org/wiki/Java_remote_method_invocation).
|
In Electron, GUI-related modules (such as `dialog`, `menu` etc.) are only
|
||||||
|
available in the main process, not in the renderer process. In order to use them
|
||||||
An example of creating a browser window from a renderer process:
|
from the renderer process, the `ipc` module is necessary to send inter-process
|
||||||
|
messages to the main process. With the `remote` module, you can invoke methods
|
||||||
|
of the main process object without explicitly sending inter-process messages,
|
||||||
|
similar to Java's [RMI][rmi]. An example of creating a browser window from a
|
||||||
|
renderer process:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var remote = require('remote');
|
const remote = require('electron').remote;
|
||||||
var BrowserWindow = remote.require('browser-window');
|
const BrowserWindow = remote.require('electron').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');
|
||||||
|
@ -96,8 +100,6 @@ 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
|
||||||
var remote = require('remote');
|
|
||||||
|
|
||||||
remote.getCurrentWindow().on('close', function() {
|
remote.getCurrentWindow().on('close', function() {
|
||||||
// blabla...
|
// blabla...
|
||||||
});
|
});
|
||||||
|
@ -146,3 +148,5 @@ process.
|
||||||
|
|
||||||
Returns the `process` object in the main process. This is the same as
|
Returns the `process` object in the main process. This is the same as
|
||||||
`remote.getGlobal('process')` but is cached.
|
`remote.getGlobal('process')` but is cached.
|
||||||
|
|
||||||
|
[rmi]: http://en.wikipedia.org/wiki/Java_remote_method_invocation
|
||||||
|
|
|
@ -6,20 +6,20 @@ position, etc. You should not use this module until the `ready` event of the
|
||||||
|
|
||||||
`screen` is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter).
|
`screen` is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter).
|
||||||
|
|
||||||
**Note:** In the renderer / DevTools, `window.screen` is a reserved
|
**Note:** In the renderer / DevTools, `window.screen` is a reserved DOM
|
||||||
DOM property, so writing `var screen = require('screen')` will not work. In our
|
property, so writing `var screen = require('electron').screen` will not work.
|
||||||
examples below, we use `electronScreen` as the variable name instead.
|
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
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var BrowserWindow = require('browser-window');
|
const app = electron.app;
|
||||||
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
var mainWindow;
|
var mainWindow;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
var electronScreen = require('screen');
|
var electronScreen = electron.screen;
|
||||||
var size = electronScreen.getPrimaryDisplay().workAreaSize;
|
var size = electronScreen.getPrimaryDisplay().workAreaSize;
|
||||||
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
mainWindow = new BrowserWindow({ width: size.width, height: size.height });
|
||||||
});
|
});
|
||||||
|
@ -28,13 +28,14 @@ app.on('ready', function() {
|
||||||
Another example of creating a window in the external display:
|
Another example of creating a window in the external display:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var BrowserWindow = require('browser-window');
|
const app = electron.app;
|
||||||
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
var mainWindow;
|
var mainWindow;
|
||||||
|
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
var electronScreen = require('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 (var i in displays) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ a property of [`BrowserWindow`](browser-window.md). You can access it through an
|
||||||
instance of `BrowserWindow`. For example:
|
instance of `BrowserWindow`. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
var win = new BrowserWindow({ width: 800, height: 600 });
|
||||||
win.loadUrl("http://github.com");
|
win.loadUrl("http://github.com");
|
||||||
|
@ -43,7 +43,7 @@ The `session` object has the following methods:
|
||||||
The `cookies` gives you ability to query and modify cookies. For example:
|
The `cookies` gives you ability to query and modify cookies. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
|
|
||||||
var win = new BrowserWindow({ width: 800, height: 600 });
|
var win = new BrowserWindow({ width: 800, height: 600 });
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,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
|
||||||
var shell = require('shell');
|
const shell = require('electron').shell;
|
||||||
|
|
||||||
shell.openExternal('https://github.com');
|
shell.openExternal('https://github.com');
|
||||||
```
|
```
|
||||||
|
|
|
@ -19,8 +19,9 @@ 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
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var BrowserWindow = require('browser-window');
|
const app = electron.app;
|
||||||
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
var window = null;
|
var window = null;
|
||||||
|
|
||||||
|
@ -38,8 +39,8 @@ ability to use node modules:
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var remote = require('remote');
|
const remote = require('electron').remote;
|
||||||
console.log(remote.require('app').getVersion());
|
console.log(remote.require('electron').app.getVersion());
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -4,9 +4,10 @@ A `Tray` represents an icon in an operating system's notification area, it is
|
||||||
usually attached with a context menu.
|
usually attached with a context menu.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var Menu = require('menu');
|
const app = electron.app;
|
||||||
var Tray = require('tray');
|
const Menu = electron.Menu;
|
||||||
|
const Tray = electron.Tray;
|
||||||
|
|
||||||
var appIcon = null;
|
var appIcon = null;
|
||||||
app.on('ready', function(){
|
app.on('ready', function(){
|
||||||
|
|
|
@ -8,7 +8,7 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the
|
||||||
`webContents` object:
|
`webContents` object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
|
|
||||||
var win = new BrowserWindow({width: 800, height: 1500});
|
var win = new BrowserWindow({width: 800, height: 1500});
|
||||||
win.loadUrl("http://github.com");
|
win.loadUrl("http://github.com");
|
||||||
|
@ -211,17 +211,15 @@ e.g. the `http://` or `file://`.
|
||||||
|
|
||||||
### `webContents.getUrl()`
|
### `webContents.getUrl()`
|
||||||
|
|
||||||
```javascript
|
Returns URL of the current web page.
|
||||||
var BrowserWindow = require('browser-window');
|
|
||||||
|
|
||||||
|
```javascript
|
||||||
var win = new BrowserWindow({width: 800, height: 600});
|
var win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadUrl("http://github.com");
|
win.loadUrl("http://github.com");
|
||||||
|
|
||||||
var currentUrl = win.webContents.getUrl();
|
var currentUrl = win.webContents.getUrl();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns URL of the current web page.
|
|
||||||
|
|
||||||
### `webContents.getTitle()`
|
### `webContents.getTitle()`
|
||||||
|
|
||||||
Returns the title of the current web page.
|
Returns the title of the current web page.
|
||||||
|
@ -445,8 +443,8 @@ By default, an empty `options` will be regarded as:
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var win = new BrowserWindow({width: 800, height: 600});
|
var win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadUrl("http://github.com");
|
win.loadUrl("http://github.com");
|
||||||
|
@ -538,7 +536,7 @@ app.on('ready', function() {
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
require('ipcRenderer').on('ping', function(event, message) {
|
require('electron').ipcRenderer.on('ping', function(event, message) {
|
||||||
console.log(message); // Prints "whoooooooh!"
|
console.log(message); // Prints "whoooooooh!"
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -6,7 +6,7 @@ web page.
|
||||||
An example of zooming current page to 200%.
|
An example of zooming current page to 200%.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var webFrame = require('web-frame');
|
var webFrame = require('electron').webFrame;
|
||||||
|
|
||||||
webFrame.setZoomFactor(2);
|
webFrame.setZoomFactor(2);
|
||||||
```
|
```
|
||||||
|
@ -59,7 +59,7 @@ whether the word passed is correctly spelled.
|
||||||
An example of using [node-spellchecker][spellchecker] as provider:
|
An example of using [node-spellchecker][spellchecker] as provider:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
require('web-frame').setSpellCheckProvider("en-US", true, {
|
webFrame.setSpellCheckProvider("en-US", true, {
|
||||||
spellCheck: function(text) {
|
spellCheck: function(text) {
|
||||||
return !(require('spellchecker').isMisspelled(text));
|
return !(require('spellchecker').isMisspelled(text));
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,7 +515,7 @@ The following example code opens the new url in system's default browser.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('new-window', function(e) {
|
webview.addEventListener('new-window', function(e) {
|
||||||
require('shell').openExternal(e.url);
|
require('electron').shell.openExternal(e.url);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -555,9 +555,9 @@ webview.send('ping');
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In guest page.
|
// In guest page.
|
||||||
var ipc = require('ipc');
|
var ipcRenderer = require('electron').ipcRenderer;
|
||||||
ipc.on('ping', function() {
|
ipcRenderer.on('ping', function() {
|
||||||
ipc.sendToHost('pong');
|
ipcRenderer.sendToHost('pong');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -51,14 +51,14 @@ $ asar list /path/to/example.asar
|
||||||
Read a file in the `asar` archive:
|
Read a file in the `asar` archive:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
fs.readFileSync('/path/to/example.asar/file.txt');
|
fs.readFileSync('/path/to/example.asar/file.txt');
|
||||||
```
|
```
|
||||||
|
|
||||||
List all files under the root of the archive:
|
List all files under the root of the archive:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
fs.readdirSync('/path/to/example.asar');
|
fs.readdirSync('/path/to/example.asar');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -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
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
var win = new BrowserWindow({width: 800, height: 600});
|
var 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');
|
||||||
```
|
```
|
||||||
|
|
|
@ -86,7 +86,6 @@ To add a file to recent documents, you can use the
|
||||||
[app.addRecentDocument][addrecentdocument] API:
|
[app.addRecentDocument][addrecentdocument] API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
|
||||||
app.addRecentDocument('/Users/USERNAME/Desktop/work.type');
|
app.addRecentDocument('/Users/USERNAME/Desktop/work.type');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -125,8 +124,10 @@ To set your custom dock menu, you can use the `app.dock.setMenu` API, which is
|
||||||
only available on OS X:
|
only available on OS X:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var Menu = require('menu');
|
const app = electron.app;
|
||||||
|
const Menu = electron.Menu;
|
||||||
|
|
||||||
var dockMenu = Menu.buildFromTemplate([
|
var dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click: function() { console.log('New Window'); } },
|
{ label: 'New Window', click: function() { console.log('New Window'); } },
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{ label: 'New Window with Settings', submenu: [
|
||||||
|
@ -172,7 +173,6 @@ To set user tasks for your application, you can use
|
||||||
[app.setUserTasks][setusertaskstasks] API:
|
[app.setUserTasks][setusertaskstasks] API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
|
||||||
app.setUserTasks([
|
app.setUserTasks([
|
||||||
{
|
{
|
||||||
program: process.execPath,
|
program: process.execPath,
|
||||||
|
@ -220,8 +220,9 @@ You can use [BrowserWindow.setThumbarButtons][setthumbarbuttons] to set
|
||||||
thumbnail toolbar in your application:
|
thumbnail toolbar in your application:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
const BrowserWindow = require('electron').BrowserWindow;
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var win = new BrowserWindow({
|
var win = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600
|
height: 600
|
||||||
|
|
|
@ -24,14 +24,15 @@ Then you can load the extension in Electron by opening DevTools in any window,
|
||||||
and running the following code in the DevTools console:
|
and running the following code in the DevTools console:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
require('remote').require('browser-window').addDevToolsExtension('/some-directory/react-devtools/shells/chrome');
|
const BrowserWindow = require('electron').remote.require('electron').BrowserWindow;
|
||||||
|
BrowserWindow.addDevToolsExtension('/some-directory/react-devtools/shells/chrome');
|
||||||
```
|
```
|
||||||
|
|
||||||
To unload the extension, you can call the `BrowserWindow.removeDevToolsExtension`
|
To unload the extension, you can call the `BrowserWindow.removeDevToolsExtension`
|
||||||
API with its name and it will not load the next time you open the DevTools:
|
API with its name and it will not load the next time you open the DevTools:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
require('remote').require('browser-window').removeDevToolsExtension('React Developer Tools');
|
BrowserWindow.removeDevToolsExtension('React Developer Tools');
|
||||||
```
|
```
|
||||||
|
|
||||||
## Format of DevTools Extension
|
## Format of DevTools Extension
|
||||||
|
|
|
@ -6,10 +6,11 @@ using standard HTML5 APIs, as shown in the following example.
|
||||||
_main.js_
|
_main.js_
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var BrowserWindow = require('browser-window');
|
const app = electron.app;
|
||||||
var onlineStatusWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
|
var onlineStatusWindow;
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
||||||
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
|
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
|
||||||
|
@ -45,11 +46,12 @@ to the main process and handled as needed, as shown in the following example.
|
||||||
_main.js_
|
_main.js_
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var ipcMain = require('ipc-main');
|
const app = electron.app;
|
||||||
var BrowserWindow = require('browser-window');
|
const ipcMain = electron.ipcMain;
|
||||||
var onlineStatusWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
|
var onlineStatusWindow;
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false });
|
||||||
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
|
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
|
||||||
|
@ -67,7 +69,7 @@ _online-status.html_
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var ipcRenderer = require('ipc-renderer');
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
var updateOnlineStatus = function() {
|
var updateOnlineStatus = function() {
|
||||||
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
||||||
};
|
};
|
||||||
|
|
|
@ -78,11 +78,12 @@ The `main.js` should create windows and handle system events, a typical
|
||||||
example being:
|
example being:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app'); // Module to control application life.
|
const electron = require('electron');
|
||||||
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
const app = electron.app; // Module to control application life.
|
||||||
|
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
|
||||||
|
|
||||||
// Report crashes to our server.
|
// Report crashes to our server.
|
||||||
require('crash-reporter').start();
|
electron.crashReporter.start();
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
|
|
|
@ -19,23 +19,6 @@ before the app ready event. Also, add the `plugins` switch of `browser-window`.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
|
||||||
var BrowserWindow = require('browser-window');
|
|
||||||
|
|
||||||
// Report crashes to our server.
|
|
||||||
require('crash-reporter').start();
|
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
|
||||||
// be closed automatically when the javascript object is GCed.
|
|
||||||
var mainWindow = null;
|
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
|
||||||
app.on('window-all-closed', function() {
|
|
||||||
if (process.platform != 'darwin') {
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Specify flash path.
|
// Specify flash path.
|
||||||
// On Windows, it might be /path/to/pepflashplayer.dll
|
// On Windows, it might be /path/to/pepflashplayer.dll
|
||||||
// On OS X, /path/to/PepperFlashPlayer.plugin
|
// On OS X, /path/to/PepperFlashPlayer.plugin
|
||||||
|
|
|
@ -41,7 +41,7 @@ upstream, except that you have to manually specify how to connect chrome driver
|
||||||
and where to find Electron's binary:
|
and where to find Electron's binary:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var webdriver = require('selenium-webdriver');
|
const webdriver = require('selenium-webdriver');
|
||||||
|
|
||||||
var driver = new webdriver.Builder()
|
var driver = new webdriver.Builder()
|
||||||
// The "9515" is the port opened by chrome driver.
|
// The "9515" is the port opened by chrome driver.
|
||||||
|
@ -93,7 +93,7 @@ $ npm install webdriverio
|
||||||
### 3. Connect to chrome driver
|
### 3. Connect to chrome driver
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var webdriverio = require('webdriverio');
|
const webdriverio = require('webdriverio');
|
||||||
var options = {
|
var options = {
|
||||||
host: "localhost", // Use localhost as chrome driver server
|
host: "localhost", // Use localhost as chrome driver server
|
||||||
port: 9515, // "9515" is the port opened by chrome driver.
|
port: 9515, // "9515" is the port opened by chrome driver.
|
||||||
|
|
Loading…
Reference in a new issue