Skip to content

Commit

Permalink
📝 Update API documentation to ES6 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
stevekinney committed May 4, 2016
1 parent 178496a commit 5a9f28e
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 176 deletions.
20 changes: 10 additions & 10 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The following example shows how to quit the application when the last window is
closed:

```javascript
const app = require('electron').app;
app.on('window-all-closed', function() {
const { app } = require('electron');
app.on('window-all-closed', () => {
app.quit();
});
```
Expand Down Expand Up @@ -218,7 +218,7 @@ should prevent the default behavior with `event.preventDefault()` and call
`callback(username, password)` with the credentials.

```javascript
app.on('login', function(event, webContents, request, authInfo, callback) {
app.on('login', (event, webContents, request, authInfo, callback) => {
event.preventDefault();
callback('username', 'secret');
})
Expand Down Expand Up @@ -386,12 +386,12 @@ default protocol handler.

### `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
(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.

The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.
Expand Down Expand Up @@ -462,9 +462,9 @@ An example of activating the window of primary instance when a second instance
starts:

```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.
if (myWindow) {
if (myWindow.isMinimized()) myWindow.restore();
Expand All @@ -478,7 +478,7 @@ if (shouldQuit) {
}

// Create myWindow, load the rest of the app, etc...
app.on('ready', function() {
app.on('ready', () => {
});
```

Expand Down Expand Up @@ -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
[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
[LSCopyDefaultHandlerForURLScheme]:
[LSCopyDefaultHandlerForURLScheme]:
https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/#//apple_ref/c/func/LSCopyDefaultHandlerForURLScheme
10 changes: 5 additions & 5 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
```javascript
// In the main process.
const BrowserWindow = require('electron').BrowserWindow;
const { BrowserWindow } = require('electron');

// 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 });
win.on('closed', function() {
let win = new BrowserWindow({ width: 800, height: 600, show: false });
win.on('closed', () => {
win = null;
});

Expand Down Expand Up @@ -315,7 +315,7 @@ Commands are lowercased with underscores replaced with hyphens and the
e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`.

```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
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
someWindow.webContents.goBack();
Expand Down
4 changes: 2 additions & 2 deletions docs/api/chrome-command-line-switches.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ your app's main script before the [ready][ready] event of the [app][app] module
is emitted:

```javascript
const app = require('electron').app;
const { app } = require('electron');
app.commandLine.appendSwitch('remote-debugging-port', '8315');
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');

app.on('ready', function() {
app.on('ready', () => {
// Your code here
});
```
Expand Down
2 changes: 1 addition & 1 deletion docs/api/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The following example shows how to write a string to the clipboard:

```javascript
const clipboard = require('electron').clipboard;
const { clipboard } = require('electron');
clipboard.writeText('Example String');
```

Expand Down
6 changes: 3 additions & 3 deletions docs/api/content-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This module does not include a web interface so you need to open
result.

```javascript
const contentTracing = require('electron').contentTracing;
const { contentTracing } = require('electron');

const options = {
categoryFilter: '*',
Expand All @@ -18,8 +18,8 @@ const options = {
contentTracing.startRecording(options, function() {
console.log('Tracing started');

setTimeout(function() {
contentTracing.stopRecording('', function(path) {
setTimeout(() => {
contentTracing.stopRecording('', (path) => {
console.log('Tracing data recorded to ' + path);
});
}, 5000);
Expand Down
2 changes: 1 addition & 1 deletion docs/api/crash-reporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The following is an example of automatically submitting a crash report to a
remote server:

```javascript
const crashReporter = require('electron').crashReporter;
const { crashReporter } = require('electron');

crashReporter.start({
productName: 'YourName',
Expand Down
4 changes: 2 additions & 2 deletions docs/api/desktop-capturer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ microphone, camera, or screen.

```javascript
// 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;
for (var i = 0; i < sources.length; ++i) {
if (sources[i].name == "Electron") {
Expand Down
4 changes: 2 additions & 2 deletions docs/api/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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').dialog;
const { dialog } = require('electron');
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
```

The Dialog is opened from Electron's main thread. If you want to use the dialog
object from a renderer process, remember to access it using the remote:

```javascript
const dialog = require('electron').remote.dialog;
const { dialog } = require('electron').remote;
```

## Methods
Expand Down
8 changes: 4 additions & 4 deletions docs/api/download-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ control the download item.

```javascript
// 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.
item.setSavePath('/tmp/save.pdf');
console.log(item.getMimeType());
console.log(item.getFilename());
console.log(item.getTotalBytes());
item.on('updated', function() {
item.on('updated', () => {
console.log('Received bytes: ' + item.getReceivedBytes());
});
item.on('done', function(e, state) {
if (state == "completed") {
item.on('done', (e, state) => {
if (state === "completed") {
console.log("Download successfully");
} else {
console.log("Download is cancelled or interrupted that can't be resumed");
Expand Down
10 changes: 5 additions & 5 deletions docs/api/file-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ Example on getting a real path from a dragged-onto-the-app file:
</div>

<script>
var holder = document.getElementById('holder');
holder.ondragover = function () {
const holder = document.getElementById('holder');
holder.ondragover = () => {
return false;
};
holder.ondragleave = holder.ondragend = function () {
holder.ondragleave = holder.ondragend = () => {
return false;
};
holder.ondrop = function (e) {
holder.ondrop = (e) => {
e.preventDefault();
var file = e.dataTransfer.files[0];
const file = e.dataTransfer.files[0];
console.log('File you dragged here is', file.path);
return false;
};
Expand Down
8 changes: 4 additions & 4 deletions docs/api/frameless-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ To create a frameless window, you need to set `frame` to `false` in


```javascript
const BrowserWindow = require('electron').BrowserWindow;
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
const { BrowserWindow } = require('electron');
let win = new BrowserWindow({ width: 800, height: 600, frame: false });
```

### Alternatives on OS X
Expand All @@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions.
You can do so by specifying the new `titleBarStyle` option:

```javascript
var win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
let win = new BrowserWindow({ 'titleBarStyle': 'hidden' });
```

## Transparent window
Expand All @@ -37,7 +37,7 @@ By setting the `transparent` option to `true`, you can also make the frameless
window transparent:

```javascript
var win = new BrowserWindow({ transparent: true, frame: false });
let win = new BrowserWindow({ transparent: true, frame: false });
```

### Limitations
Expand Down
9 changes: 4 additions & 5 deletions docs/api/global-shortcut.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ event of the app module is emitted.

```javascript
const electron = require('electron');
const app = electron.app;
const globalShortcut = electron.globalShortcut;
const { app, globalShortcut } = electron;

app.on('ready', function() {
app.on('ready', () => {
// 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');
});

Expand All @@ -29,7 +28,7 @@ app.on('ready', function() {
console.log(globalShortcut.isRegistered('CommandOrControl+X'));
});

app.on('will-quit', function() {
app.on('will-quit', () => {
// Unregister a shortcut.
globalShortcut.unregister('CommandOrControl+X');

Expand Down
10 changes: 5 additions & 5 deletions docs/api/ipc-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ processes:

```javascript
// In main process.
const ipcMain = require('electron').ipcMain;
ipcMain.on('asynchronous-message', function(event, arg) {
const { ipcMain } = require('electron');
ipcMain.on('asynchronous-message', (event, arg) => {
console.log(arg); // prints "ping"
event.sender.send('asynchronous-reply', 'pong');
});

ipcMain.on('synchronous-message', function(event, arg) {
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg); // prints "ping"
event.returnValue = 'pong';
});
```

```javascript
// In renderer process (web page).
const ipcRenderer = require('electron').ipcRenderer;
const { ipcRenderer } = require('electron');
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"
});
ipcRenderer.send('asynchronous-message', 'ping');
Expand Down
Loading

0 comments on commit 5a9f28e

Please sign in to comment.