doc: Separate pages into sub directories.

This commit is contained in:
Cheng Zhao 2013-09-09 15:49:13 +08:00
parent 6b81070f67
commit 92241b91ce
21 changed files with 20 additions and 20 deletions

131
docs/api/browser/app.md Normal file
View file

@ -0,0 +1,131 @@
# app
The `app` module is responsible for controlling the application's life time.
The example of quitting the whole application when the last window is closed:
```javascript
var app = require('app');
app.on('window-all-closed', function() {
app.quit();
});
```
## Event: will-finish-launching
Setup crash reporter and auto updater here.
## Event: finish-launching
Do final startup like creating browser window here.
## Event: window-all-closed
Emitted when all windows have been closed.
This event is only emitted when the application is not going to quit. If a
user pressed `Cmd + Q`, or the developer called `app.quit()`, atom-shell would
first try to close all windows and then emit the `will-quit` event, and in
this case the `window-all-closed` would not be emitted.
## Event: will-quit
* `event` Event
Emitted when all windows have been closed and the application will quit.
Calling `event.preventDefault()` will prevent the default behaviour, which is
terminating the application.
See description of `window-all-closed` for the differences between `will-quit`
and it.
## Event: open-file
* `event` Event
* `path` String
Emitted when user wants to open a file with the application, it usually
happens when the application is already opened and then OS wants to reuse the
application to open file.
You should call `event.preventDefault()` if you want to handle this event.
## Event: open-url
* `event` Event
* `url` String
Emitted when user wants to open a URL with the application, this URL scheme
must be registered to be opened by your application.
You should call `event.preventDefault()` if you want to handle this event.
## app.quit()
Try to close all windows. If all windows are successfully closed, the
`will-quit` event will be emitted and by default the application would be
terminated.
This method guarantees all `beforeunload` and `unload` handlers are correctly
executed. It is possible that a window cancels the quitting by returning
`false` in `beforeunload` handler.
## app.terminate()
Quit the application directly, it will not try to close all windows so cleanup
code will not run.
## app.getVersion()
Returns the version of current bundle or executable.
## app.commandLine.appendSwitch(switch, [value])
Append a switch [with optional value] to Chromium's command line.
**Note:** This will not affect `process.argv`, and is mainly used by
**developers to control some low-level Chromium behaviors.
## app.commandLine.appendArgument(value)
Append an argument to Chromium's command line. The argument will quoted properly.
**Note:** This will not affect `process.argv`.
## app.dock.bounce([type])
* `type` String - Can be `critical` or `informational`, the default is
* `informational`
When `critical` is passed, the dock icon will bounce until either the
application becomes active or the request is canceled.
When `informational` is passed, the dock icon will bounce for one second. The
request, though, remains active until either the application becomes active or
the request is canceled.
An ID representing the request would be returned.
**Note:** This API is only available on Mac.
## app.dock.cancelBounce(id)
* `id` Integer
Cancel the bounce of `id`.
**Note:** This API is only available on Mac.
## app.dock.setBadge(text)
* `text` String
Sets the string to be displayed in the docks badging area.
**Note:** This API is only available on Mac.
## app.dock.getBadge()
Returns the badge string of the dock.
**Note:** This API is only available on Mac.

View file

@ -0,0 +1,31 @@
# atom-delegate
The `atom-delegate` returns the delegate object for Chrome Content API. The
atom-shell would call methods of the delegate object when the corresponding
C++ code is called. Developers can override methods of it to control the
underlying behaviour of the browser.
An example of creating a new window when the browser is initialized:
```javascript
var delegate = require('atom-delegate'); // Delegate of Content API.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
// 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;
// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
delegate.browserMainParts.preMainMessageLoopRun = function() {
// Create the browser window,
mainWindow = new BrowserWindow({ width: 800, height: 600 });
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
}
```
## atom-delegate.browserMainParts.preMainMessageLoopRun()
Called when atom-shell has done everything initialization and ready for
creating browser windows.

View file

@ -0,0 +1,42 @@
# auto-updater
`auto-updater` module is a simple wrap around the Sparkle framework, it
provides auto update service for the application.
Before using this module, you should edit the `Info.plist` following
https://github.com/andymatuschak/Sparkle/wiki.
## Event: will-install-update
* `event` Event
* `version` String
* `continueUpdate` Function
This event is emitted when the update is found and going to be installed.
Calling `event.preventDefault()` would pause it, and you can call
`continueUpdate` to continue the update.
## Event: ready-for-update-on-quit
* `event` Event
* `version` String
* `quitAndUpdate` Function
This event is emitted when user chose to delay the update until the quit.
Calling `quitAndUpdate()` would quit the application and install the update.
## autoUpdater.setFeedUrl(url)
* `url` String
## autoUpdater.setAutomaticallyChecksForUpdates(flag)
* `flag` Boolean
## autoUpdater.setAutomaticallyDownloadsUpdates(flag)
* `flag` Boolean
## autoUpdater.checkForUpdates()
## autoUpdater.checkForUpdatesInBackground()

View file

@ -0,0 +1,367 @@
# browser-window
The `BrowserWindow` class gives you ability to create a browser window, an
example is:
```javascript
var BrowserWindow = require('browser-window');
var win = new BrowserWindow({ width: 800, height: 600, show: false });
win.on('destroyed', function() {
win = null;
});
win.loadUrl('https://github.com');
win.show();
```
You can also create a window without chrome by using
[Frameless Window](frameless-window.md) API.
**Note:** Be careful not to use `window` as the variable name.
## Class: BrowserWindow
`BrowserWindow` is an
[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter).
### new BrowserWindow(options)
* `options` Object
* `x` Integer - Window's left offset to screen
* `y` Integer - Window's top offset to screen
* `center` Boolean - Show window in the center of the screen
* `min-width` Integer - Minimum width
* `min-height` Integer - Minimum height
* `max-width` Integer - Maximum width
* `max-height` Integer - Maximum height
* `resizable` Boolean - Whether window is resizable
* `always-on-top` Boolean - Whether the window should always stay on top of other windows
* `fullscreen` Boolean - Whether the window should show in fullscreen
* `kiosk` Boolean - The kiosk mode
* `title` String - Default window title
* `show` Boolean - Whether window should be shown when created
* `frame` Boolean - Specify `false` to create a
[Frameless Window](frameless-window.md)
Creates a new `BrowserWindow` with native properties set by the `options`.
Usually you only need to set the `width` and `height`, other properties will
have decent default values.
### Event: 'page-title-updated'
* `event` Event
Emitted when the document changed its title, calling `event.preventDefault()`
would prevent the native window's title to change.
### Event: 'loading-state-changed'
* `event` Event
* `isLoading` Boolean
Emitted when the window is starting or is done loading a page.
### Event: 'close'
* `event` Event
Emitted when the window is going to be closed. It's emitted before the
`beforeunload` and `unload` event of DOM, calling `event.preventDefault()`
would cancel the close.
Usually you would want to use the `beforeunload` handler to decide whether the
window should be closed, which will also be called when the window is
reloaded. In atom-shell, returning an empty string or `false` would cancel the
close. An example is:
```javascript
window.onbeforeunload = function(e) {
console.log('I do not want to be closed');
// Unlike usual browsers, in which a string should be returned and the user is
// prompted to confirm the page unload. atom-shell gives the power completely
// to the developers, return empty string or false would prevent the unloading
// now. You can also use the dialog API to let user confirm it.
return false;
};
```
### Event: 'closed'
Emitted when the window is closed. At the time of this event, window is not
destroyed yet so you can still do some operations to the window (but you
shouldn't!).
### Event: 'destroyed'
Emitted when the memory taken by the native window is released. Usually you
should dereference the javascript object when received this event.
### Class Method: BrowserWindow.getFocusedWindow()
Returns the window that is focused in this application.
### Class Method: BrowserWindow.fromProcessIdAndRoutingId(processId, routingId)
* `processId` Integer
* `routingId` Integer
Find a window according to its `processId` and `routingId`.
### BrowserWindow.destroy()
Destroy the window and free the memory without closing it.
**Note:** Usually you should always call `Window.close()` to close the window,
**which will emit `beforeunload` and `unload` events for DOM. Only use
**`Window.destroy()` when the window gets into a very bad state and you want
**to force closing it.
### BrowserWindow.close()
Try to close the window, this has the same effect with user manually clicking
the close button of the window. The web page may cancel the close though, see
the [close event](window#event-close).
### BrowserWindow.focus()
Focus on the window.
### BrowserWindow.isFocused()
Returns whether the window is focused.
### BrowserWindow.show()
Shows the window.
### BrowserWindow.hide()
Hides the window.
### BrowserWindow.maximize()
Maximizes the window.
### BrowserWindow.unmaximize()
Unmaximizes the window.
### BrowserWindow.minimize()
Minimizes the window. On some platforms the minimized window will be shown in
the Dock.
### BrowserWindow.restore()
Restores the window from minimized state to its previous state.
### BrowserWindow.setFullScreen(flag)
* `flag` Boolean
Sets whether the window should be in fullscreen mode.
### BrowserWindow.isFullScreen()
Returns whether the window is in fullscreen mode.
### BrowserWindow.setSize(width, height)
* `width` Integer
* `height` Integer
Resizes the window to `width` and `height`.
### BrowserWindow.getSize()
Returns an array that contains window's width and height.
### BrowserWindow.setMinimumSize(width, height)
* `width` Integer
* `height` Integer
Sets the minimum size of window to `width` and `height`.
### BrowserWindow.getMinimumSize()
Returns an array that contains window's minimum width and height.
### BrowserWindow.setMaximumSize(width, height)
* `width` Integer
* `height` Integer
Sets the maximum size of window to `width` and `height`.
### BrowserWindow.getMaximumSize()
Returns an array that contains window's maximum width and height.
### BrowserWindow.setResizable(resizable)
* `resizable` Boolean
Sets whether the window can be manually resized by user.
### BrowserWindow.isResizable()
Returns whether the window can be manually resized by user.
### BrowserWindow.setAlwaysOnTop(flag)
* `flag` Boolean
Sets whether the window should show always on top of other windows. After
setting this, the window is still a normal window, not a toolbox window which
can not be focused on.
### BrowserWindow.isAlwaysOnTop()
Returns whether the window is always on top of other windows.
### BrowserWindow.center()
Moves window to the center of the screen.
### BrowserWindow.setPosition(x, y)
* `x` Integer
* `y` Integer
Moves window to `x` and `y`.
### BrowserWindow.getPosition()
Returns an array that contains window's current position.
### BrowserWindow.setTitle(title)
* `title` String
Changes the title of native window to `title`.
### BrowserWindow.getTitle()
Returns the title of the native window.
**Note:** The title of web page can be different from the title of the native
**window.
### BrowserWindow.flashFlame()
Flashes the window to attract user's attention.
### BrowserWindow.setKiosk(flag)
* `flag` Boolean
Enters or leaves the kiosk mode.
### BrowserWindow.isKiosk()
Returns whether the window is in kiosk mode.
### BrowserWindow.openDevTools()
Opens the developer tools.
### BrowserWindow.closeDevTools()
Closes the developer tools.
### BrowserWindow.inspectElement(x, y)
* `x` Integer
* `y` Integer
Starts inspecting element at position (`x`, `y`).
### BrowserWindow.focusOnWebView()
### BrowserWindow.blurWebView()
### BrowserWindow.restartHangMonitorTimeout()
### BrowserWindow.getPageTitle()
Returns the title of web page.
### BrowserWindow.isLoading()
Returns whether web page is still loading resources.
### BrowserWindow.isWaitingForResponse()
Returns whether web page is waiting for a first-response for the main resource
of the page.
### BrowserWindow.stop()
Stops any pending navigation.
### BrowserWindow.getProcessId()
Returns window's process ID. The process ID and routing ID can be used
together to locate a window.
### BrowserWindow.getRoutingId()
Returns window's routing ID. The process ID and routing ID can be used
together to locate a window.
### BrowserWindow.loadUrl(url)
* `url` URL
Loads the `url` in the window, the `url` must contains the protocol prefix,
e.g. the `http://` or `file://`.
### BrowserWindow.getUrl()
Returns URL of current web page.
### BrowserWindow.canGoBack()
Returns whether the web page can go back.
### BrowserWindow.canGoForward()
Returns whether the web page can go forward.
### BrowserWindow.canGoToOffset(offset)
* `offset` Integer
Returns whether the web page can go to `offset`.
### BrowserWindow.goBack()
Makes the web page go back.
### BrowserWindow.goForward()
Makes the web page go forward.
### BrowserWindow.goToIndex(index)
* `index` Integer
Navigates to the specified absolute index.
### BrowserWindow.goToOffset(offset)
* `offset` Integer
Navigates to the specified offset from the "current entry".
### BrowserWindow.reload()
Reloads current window.
### BrowserWindow.reloadIgnoringCache()
Reloads current window and ignores cache.

View file

@ -0,0 +1,22 @@
# crash-reporter
An example of automatically submitting crash reporters to remote server:
```javascript
crashReporter = require('crash-reporter');
crashReporter.setCompanyName('YourCompany');
crashReporter.setSubmissionUrl('https://your-domain.com/url-to-submit');
crashReporter.setAutoSubmit(true);
```
## crashReporter.setCompanyName(company)
* `company` String
## crashReporter.setSubmissionUrl(url)
* `url` String
## crashReporter.setAutoSubmit(is)
* `is` Boolean

View file

@ -0,0 +1,53 @@
# dialog
The `dialog` module provides functions to show system dialogs, so web
applications can get the same user experience with native applications.
An example of showing a dialog to select multiple files and directories:
```javascript
var win = ...; // window in which to show the dialog
var dialog = require('dialog');
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
```
## dialog.showOpenDialog(options)
* `options` Object
* `title` String
* `defaultPath` String
* `properties` Array - Contains which features the dialog should use, can
contain `openFile`, `openDirectory`, `multiSelections` and
`createDirectory`
On success, returns an array of file paths chosen by the user, otherwise
returns `undefined`.
**Note:** The `dialog.showOpenDialog` API is synchronous and blocks all windows.
## dialog.showSaveDialog(browserWindow, options)
* `browserWindow` BrowserWindow
* `options` Object
* `title` String
* `defaultPath` String
On success, returns the path of file chosen by the user, otherwise returns
`undefined`.
**Note:** The `dialog.showSaveDialog` API is synchronous and blocks all windows.
## dialog.showMessageBox([browserWindow], options)
* `browserWindow` BrowserWindow
* `options` Object
* `type` String - Can be `"none"`, `"info"` or `"warning"`
* `buttons` Array - Array of texts for buttons
* `title` String - Title of the message box, some platforms will not show it
* `message` String - Content of the message box
* `detail` String - Extra information of the message
Shows a message box, it will block until the message box is closed. It returns
the index of the clicked button.
**Note:** The `dialog.showMessageBox` API is synchronous and blocks all windows.

View file

@ -0,0 +1,64 @@
# Frameless window
A frameless window is a window that has no chrome.
## Create a frameless window
To create a frameless window, you only need to specify `frame` to `false` in
[BrowserWindow](api/browser/browser-window.md)'s `options`:
```javascript
var BrowserWindow = require('browser-window');
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
```
## Draggable region
By default, the frameless window is non-draggable. Apps need to specify
`-webkit-app-region: drag` in CSS to tell atom-shell which regions are draggable
(like the OS's standard titlebar), and apps can also use
`-webkit-app-region: no-drag` to exclude the non-draggable area from the
draggable region. Note that only rectangular shape is currently supported.
To make the whole window draggable, you can add `-webkit-app-region: drag` as
`body`'s style:
```html
<body style="-webkit-app-region: drag">
</body>
```
And note that if you have made the whole window draggable, you must also mark
buttons as non-draggable, otherwise it would be impossible for users to click on
them:
```css
button {
-webkit-app-region: no-drag;
}
```
If you're only using a custom titlebar, you also need to make buttons in
titlebar non-draggable.
## Text selection
One thing on frameless window is that the dragging behaviour may conflict with
selecting text, for example, when you drag the titlebar, you may accidentally
select the text on titlebar. To prevent this, you need to disable text
selection on dragging area like this:
```css
.titlebar {
-webkit-user-select: none;
-webkit-app-region: drag;
}
```
## Context menu
On some platforms, the draggable area would be treated as non-client frame, so
when you right click on it a system menu would be popuped. To make context menu
behave correctly on all platforms, you should never custom context menu on
draggable areas.

View file

@ -0,0 +1,52 @@
# ipc (browser)
The `ipc` module allows developers to send asynchronous messages to renderers.
To avoid possible dead-locks, it's not allowed to send synchronous messages in
browser.
## Event: 'message'
* `processId` Integer
* `routingId` Integer
Emitted when renderer sent a message to the browser.
## Event: 'sync-message'
* `event` Object
* `processId` Integer
* `routingId` Integer
Emitted when renderer sent a synchronous message to the browser. The receiver
should store the result in `event.result`.
**Note:** Due to the limitation of `EventEmitter`, returning value in the
event handler has no effect, so we have to store the result by using the
`event` parameter.
## ipc.send(processId, routingId, [args...])
* `processId` Integer
* `routingId` Integer
Send `args...` to the renderer specified by `processId` and `routingId` and
return immediately, the renderer should handle the message by listening to the
`message` event.
## ipc.sendChannel(processId, routingId, channel, [args...])
* `processId` Integer
* `routingId` Integer
* `channel` String
This is the same with ipc.send, except that the renderer should listen to the
`channel` event. The ipc.send(processId, routingId, args...) can be seen as
ipc.sendChannel(processId, routingId, 'message', args...).
**Note:** If the the first argument (e.g. `processId`) is a `BrowserWindow`,
`ipc.sendChannel` would automatically get the `processId` and `routingId`
from it, so you can send a message to window like this:
```javascript
ipc.sendChannel(browserWindow, 'message', ...);
```

View file

@ -0,0 +1,27 @@
# menu-item
## Class: MenuItem
### new MenuItem(options)
* `options` Object
* `click` Function - Callback when the menu item is clicked
* `selector` String - Call the selector of first responder when clicked (OS
X only)
* `type` String - Can be `normal`, `separator`, `submenu`, `checkbox` or
`radio`
* `label` String
* `sublabel` String
* `accelerator` String - In the form of `Command+R`, `Ctrl+C`,
`Shift+Command+D`, `D`, etc.
* `enabled` Boolean
* `visible` Boolean
* `checked` Boolean
* `groupId` Boolean - Should be specified for `radio` type menu item
* `submenu` Menu - Should be specified for `submenu` type menu item, when
it's specified the `type: 'submenu'` can be omitted for the menu item
## Notes on accelerator
On OS X, the `Ctrl` would automatically translated to `Command`, if you really
want `Ctrl` on OS X, you should use `MacCtrl`.

199
docs/api/browser/menu.md Normal file
View file

@ -0,0 +1,199 @@
# menu
The `Menu` class is used to create native menus that can be used as
application menu and context menu. Each menu is consisted of multiple menu
items, and each menu item can have a submenu.
An example of creating a menu dynamically and show it when user right clicks
the page:
```javascript
var Menu = require('menu');
var MenuItem = require('menu-item');
var menu = new Menu();
menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1clicked'); } }));
menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', clicked: true }));
window.addEventListener('contextmenu', function (e) {
e.preventDefault();
menu.popup();
}, false);
```
Another example of creating the application menu with the simple template API:
```javascript
var template = [
{
label: 'Atom Shell',
submenu: [
{
label: 'About Atom Shell',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Hide Atom Shell',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{
label: 'Show All',
selector: 'unhideAllApplications:'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: function() { app.quit(); }
},
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
},
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { BrowserWindow.getFocusedWindow().reloadIgnoringCache(); }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
},
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
},
]
},
];
menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
```
## Class: Menu
### new Menu()
Creates a new menu.
### Class Method: Menu.setApplicationMenu(menu)
* `menu` Menu
Sets `menu` as the application menu.
**Note:** This method is OS X only.
### Class Method: Menu.sendActionToFirstResponder(action)
* `action` String
Sends the `action` to the first responder of application, this is used for
emulating default Cocoa menu behaviors, usually you would just use the
`selector` property of `MenuItem`.
**Note:** This method is OS X only.
### Class Method: Menu.buildFromTemplate(template)
* `template` Array
Generally, the `template` is just an array of `options` for constructing
`MenuItem`, the usage can be referenced above.
You can also attach other fields to element of the `template`, and they will
become properties of the constructed menu items.
### Menu.popup(browserWindow)
* `browserWindow` BrowserWindow
Popups the this as context menu in the `browserWindow`.
### Menu.append(menuItem)
* `menuItem` MenuItem
Appends the `menuItem` to the menu.
### Menu.insert(pos, menuItem)
* `pos` Integer
* `menuItem` MenuItem
Inserts the `menuItem` to the `pos` position of the menu.
### Menu.items
Get the array containing the menu's items.

View file

@ -0,0 +1,20 @@
# power-monitor
The `power-monitor` module is used to monitor the power state change, you can
only use it on the browser side.
An example is:
```javascript
require('power-monitor').on('suspend', function() {
console.log('The system is going to sleep');
});
```
## Event: suspend
Emitted when the system is suspending.
## Event: resume
Emitted when system is resuming.

View file

@ -0,0 +1,68 @@
# protocol
The `protocol` module can register a new protocol or intercept an existing
protocol, so you can custom the response to the requests for vairous protocols.
An example of implementing a protocol that has the same effect with the
`file://` protocol:
```javascript
var protocol = require('protocol');
protocol.registerProtocol('atom', function(request) {
var path = request.url.substr(7)
return new protocol.RequestFileJob(path);
});
```
## protocol.registerProtocol(scheme, handler)
* `scheme` String
* `handler` Function
Registers a custom protocol of `scheme`, the `handler` would be called with
`handler(request)` when the a request with registered `scheme` is made.
You need to return a request job in the `handler` to specify which type of
response you would like to send.
## protocol.unregisterProtocol(scheme)
* `scheme` String
Unregisters the custom protocol of `scheme`.
## protocol.isHandledProtocol(scheme)
* `scheme` String
Returns whether the `scheme` can be handled already.
## protocol.interceptProtocol(scheme, handler)
* `scheme` String
* `handler` Function
Intercepts an existing protocol with `scheme`, returning `null` or `undefined`
in `handler` would use the original protocol handler to handle the request.
## protocol.uninterceptProtocol(scheme)
* `scheme` String
Unintercepts a protocol.
## Class: protocol.RequestFileJob(path)
* `path` String
Create a request job which would query a file of `path` and set corresponding
mime types.
## Class: protocol.RequestStringJob(options)
* `options` Object
* `mimeType` String - Default is `text/plain`
* `charset` String - Default is `UTF-8`
* `data` String
Create a request job which sends a string as response.

View file

@ -0,0 +1,38 @@
# clipboard
An example of writing a string to clipboard:
```javascript
var clipboard = require('clipboard');
clipboard.writeText('Example String');
```
## clipboard.readText()
Returns the content in clipboard as plain text.
## clipboard.writeText(text)
* `text` String
Writes the `text` into clipboard as plain text.
## clipboard.clear()
Clears everything in clipboard.
## clipboard.has(type)
* `type` String
Returns whether clipboard has data in specified `type`.
**Note:** This API is experimental and could be removed in future.
## clipboard.read(type)
* `type` String
Reads the data in clipboard of the `type`.
**Note:** This API is experimental and could be removed in future.

39
docs/api/common/shell.md Normal file
View file

@ -0,0 +1,39 @@
# shell
The `shell` module provides functions related to desktop integration.
An example of opening a URL in default browser:
```javascript
var shell = require('shell');
shell.openExternal('https://github.com');
```
## shell.showItemInFolder(fullPath)
* `fullPath` String
Show the given file in a file manager. If possible, select the file.
## shell.openItem(fullPath)
* `fullPath` String
Open the given file in the desktop's default manner.
## shell.openExternal(url)
* `url` String
Open the given external protocol URL in the desktop's default manner. (For
example, mailto: URLs in the default mail user agent.)
## shell.moveItemToTrash(fullPath)
* `fullPath` String
Move the given file to trash.
## shell.beep()
Play the beep sound.

View file

@ -0,0 +1,79 @@
# ipc (renderer)
The `ipc` module provides a few methods so you can send synchronous and
asynchronous messages to the browser, and also receive messages sent from
browser. If you want to make use of modules of browser from renderer, you
might consider using the [remote](remote.md) module.
An example of echoing messages between browser and renderer:
```javascript
// In browser:
var ipc = require('ipc');
ipc.on('message', function(processId, routingId, m) {
ipc.send(processId, routingId, m);
});
```
```javascript
// In renderer:
var ipc = require('ipc');
ipc.on('message', function(m) {
console.log('Received message', m);
});
ipc.send('Hello world');
```
An example of sending synchronous message from renderer to browser:
```javascript
// In browser:
var ipc = require('ipc');
ipc.on('browser-data-request', function(event, processId, routingId, message) {
event.result = 'THIS SOME DATA FROM THE BROWSER';
});
```
```javascript
// In renderer:
var ipc = require('ipc');
console.log(ipc.sendChannelSync('browser-data-request', 'THIS IS FROM THE RENDERER'));
```
## Event: 'message'
Emitted when browser sent a message to this window.
## ipc.send([args...])
Send all arguments to the browser and return immediately, the browser should
handle the message by listening to the `message` event.
## ipc.sendSync([args...])
Send all arguments to the browser synchronously, and returns the result sent
from browser. The browser should handle the message by listening to the
`sync-message` event.
**Note:** Usually developers should never use this API, since sending
synchronous message would block the browser.
## ipc.sendChannel(channel, [args...])
* `channel` String
This is the same with `ipc.send`, except that the browser should listen to the
`channel` event. The `ipc.send(args...)` can be seen as
`ipc.sendChannel('message', args...)`.
## ipc.sendChannelSync(channel, [args...])
* `channel` String
This is the same with `ipc.sendSync`, except that the browser should listen to
the `channel` event. The `ipc.sendSync(args...)` can be seen as
`ipc.sendChannelSync('sync-message', args...)`.
**Note:** Usually developers should never use this API, since sending
synchronous message would block the browser.

View file

@ -0,0 +1,82 @@
# remote
It's common that the developers want to use modules in browsers from the
renderer, like closing current window, opening file dialogs, etc. Instead of
writing IPC code for every operation you want to do, atom-shell provides the
`remote` module to let you do RPC call just like using normal javascript
objects.
An example of creating a window in renderer:
```javascript
var remote = require('remote');
var BrowserWindow = remote.require('browser-window');
var win = new BrowserWindow({ width: 800, height: 600 });
win.loadUrl('https://github.com');
```
## Lifetime of remote objects
Every object returned by `remote` module represents an object in browser (e.g.
a remote object), so when you call methods of an object, or call a returned
function, or even create a object with the returned constructor, you are
indeed making a synchronous RPC call. And when the renderer releases the last
reference to the remote object, the browser would release the corresponding
reference too.
This also means that, if the renderer keeps a reference to an object in
browser, the object would never be released. So be careful to never leak the
remote objects.
## Passing callbacks
Many APIs in browser accepts callbacks, so the `remote` module also supports
passing callbacks when calling remote functions, and the callbacks passed
would become remote functions in the browser.
But in order to avoid possible dead locks, the callbacks passed to browser
would be called asynchronously in browser, so you should never expect the
browser to get the return value of the passed callback.
Another thing is the lifetime of the remote callbacks in browser, it might be
very tempting to do things like following:
```javascript
var remote = require('remote');
remote.getCurrentWindow().on('close', function() {
// blabla...
});
```
Yes it will work correctly, but when you reload the window, the callback you
setup on the object in browser will not be erased, resources are leaked and
there is no magic in javascript to release a referenced object.
So if you really need to keep a reference of callbacks in browser, you should
write the callback in browser and send messages to renderer. And also make use
of DOM's events like `unload` and `beforeunload`, they will work perfectly.
## remote.require(module)
* `module` String
Return a module in browser.
## remote.getCurrentWindow()
Return the `BrowserWindow` object that represents current window.
`Note:` it doesn't return the `window` object which represents the global
scope, instead it returns an instance of the `BrowserWindow` class which is
created with `browser-window` module in browser.
## remote.getGlobal(name)
* `name` String
Return the `global[name]` value in browser.
## remote.process
Getter to return the `process` object in browser, this is the same with
`remote.getGlobal('process')` but gets cached.