Move wiki content to docs dir
This commit is contained in:
parent
63b85bccab
commit
6bc2a3a5e8
21 changed files with 1344 additions and 0 deletions
42
docs/Build-Instructions-(Mac).md
Normal file
42
docs/Build-Instructions-(Mac).md
Normal file
|
@ -0,0 +1,42 @@
|
|||
## Prerequisites
|
||||
|
||||
* Mac OS X >= 10.7
|
||||
* [Xcode](https://developer.apple.com/technologies/tools/)
|
||||
* [node.js](http://nodejs.org)
|
||||
|
||||
## Getting the code
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/atom/atom-shell.git
|
||||
```
|
||||
|
||||
## Bootstrapping
|
||||
|
||||
The bootstrap script will download all necessary build dependencies and create build project files. Notice that we're using `ninja` to build `atom-shell` so there is no Xcode project generated.
|
||||
|
||||
```bash
|
||||
$ cd atom-shell
|
||||
$ ./script/bootstrap.py
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Build both `Release` and `Debug` targets:
|
||||
|
||||
```bash
|
||||
$ ./script/build.py
|
||||
```
|
||||
|
||||
You can also only build the `Debug` target:
|
||||
|
||||
```bash
|
||||
$ ./script/build.py -c Debug
|
||||
```
|
||||
|
||||
After building is done, you can find `Atom.app` under `out/Debug`.
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
$ ./script/test.py
|
||||
```
|
50
docs/Build-Instructions-(Windows).md
Normal file
50
docs/Build-Instructions-(Windows).md
Normal file
|
@ -0,0 +1,50 @@
|
|||
## Prerequisites
|
||||
|
||||
* Windows 7 or later
|
||||
* Visual Studio 2010 Express or higher
|
||||
* [Python 2.7](http://www.python.org/download/releases/2.7/)
|
||||
* [node.js](http://nodejs.org/)
|
||||
* [git](http://git-scm.com)
|
||||
|
||||
The instructions bellow are executed under [cygwin](http://www.cygwin.com), but it's not a requirement, you can also build atom-shell under Windows's console or other terminals.
|
||||
|
||||
The building of atom-shell is done entirely with command line scripts, so you can use any editor you like to develop atom-shell, but it also means you can not use Visual Studio for the development. Support of building with Visual Studio will come in future.
|
||||
|
||||
**Note:** Even though Visual Studio is not used for building, it's still required because we need the build toolchains it provided.
|
||||
|
||||
## Getting the code
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/atom/atom-shell.git
|
||||
```
|
||||
|
||||
## Bootstrapping
|
||||
|
||||
The bootstrap script will download all necessary build dependencies and create build project files. Notice that we're using `ninja` to build atom-shell so there is no Visual Studio project generated.
|
||||
|
||||
```bash
|
||||
$ cd atom-shell
|
||||
$ python script/bootstrap.py
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Build both Release and Debug targets:
|
||||
|
||||
```bash
|
||||
$ python script/build.py
|
||||
```
|
||||
|
||||
You can also only build the Debug target:
|
||||
|
||||
```bash
|
||||
$ python script/build.py -c Debug
|
||||
```
|
||||
|
||||
After building is done, you can find `atom.exe` under `out\Debug`.
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
$ python script/test.py
|
||||
```
|
27
docs/Build-native-modules.md
Normal file
27
docs/Build-native-modules.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
Since atom-shell is using a different V8 version from the official node, you need to build native module against atom-shell's headers to use them.
|
||||
|
||||
You need to use node-gyp to compile native modules, you can install node-gyp via npm if you hadn't:
|
||||
|
||||
```bash
|
||||
$ npm install -g node-gyp
|
||||
```
|
||||
|
||||
First you need to check which node release atom-shell is carrying via `process.version` (at the time of writing it is v0.10.5), then you can configure and build native modules via following commands:
|
||||
|
||||
```bash
|
||||
$ cd /path-to-module/
|
||||
$ HOME=~/.atom-shell-gyp node-gyp rebuild --target=0.10.5 --arch=ia32 --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
|
||||
```
|
||||
|
||||
The `HOME=~/.atom-shell-gyp` changes where to find development headers. The `--target=0.10.5` is specifying node's version. The `--dist-url=...` specifies where to download the headers.
|
||||
|
||||
## Use npm to build native modules
|
||||
|
||||
Under most circumstances you would want to use npm to install modules, if you're using npm >= v1.2.19 (because [a patch](https://github.com/TooTallNate/node-gyp/commit/afbcdea1ffd25c02bc88d119b10337852c44d400) is needed to make `npm_config_disturl` work) you can use following code to download and build native modules against atom-shell's headers:
|
||||
|
||||
```bash
|
||||
export npm_config_disturl=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
|
||||
export npm_config_target=0.10.5
|
||||
export npm_config_arch=ia32
|
||||
HOME=~/.atom-shell-gyp npm install module-name
|
||||
```
|
16
docs/Coding-Style.md
Normal file
16
docs/Coding-Style.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
## C++ and Python
|
||||
|
||||
For C++ and Python, we just follow Chromium's [Coding Style](http://www.chromium.org/developers/coding-style), there is also a script `script/cpplint.py` to check whether all files confirm.
|
||||
|
||||
The python's version we are using now is Python 2.7.
|
||||
|
||||
## CoffeeScript
|
||||
|
||||
For CoffeeScript, we follow GitHub's [Style Guide](https://github.com/styleguide/javascript), and also following rules:
|
||||
|
||||
* Files should **NOT** end with new line, because we want to match Google's styles.
|
||||
* File names should be concatenated with `-` instead of `_`, e.g. `file-name.coffee` rather than `file_name.coffee`, because in [github/atom](https://github.com/github/atom) module names are usually in the `module-name` form, this rule only apply to `.coffee` files.
|
||||
|
||||
## API Names
|
||||
|
||||
When creating a new API, we should prefer getters and setters instead of jQuery's one-function style, for example, `.getText()` and `.setText(text)` are preferred to `.text([text])`. There is a [discussion](https://github.com/atom/atom-shell/issues/46) of this.
|
41
docs/IPC-(browser).md
Normal file
41
docs/IPC-(browser).md
Normal file
|
@ -0,0 +1,41 @@
|
|||
## Synopsis
|
||||
|
||||
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', ...);
|
||||
```
|
67
docs/IPC-(renderer).md
Normal file
67
docs/IPC-(renderer).md
Normal file
|
@ -0,0 +1,67 @@
|
|||
## Synopsis
|
||||
|
||||
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]] 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.
|
92
docs/Quick-start.md
Normal file
92
docs/Quick-start.md
Normal file
|
@ -0,0 +1,92 @@
|
|||
## Introduction
|
||||
|
||||
Generally, atom-shell lets you create a web-based desktop application in pure javascript. Unlike CEF, which requires you to use C++ to write underlying code, or node-webkit, which only allows you to write everything in the web page, atom-shell gives you the power to use javascript to control the browser side.
|
||||
|
||||
## Browser and renderer
|
||||
|
||||
Atom-shell is built upon Chromium's Content API, so it has the same multi-processes architecture with the Chrome browser. In summary, things about UI are done in the browser process, and each web page instance would start a new renderer process.
|
||||
|
||||
In atom-shell, you can just put everything in a simpler way: when you are executing javascript in browser side, you can control the application's life, create UI widget, deal with system events, and create windows which contain web pages; while on the renderer side, you can only control the web page you are showing, if you want something more like creating a new window, you should use IPC API to tell the browser to do that.
|
||||
|
||||
## The architecture of an app
|
||||
|
||||
Generally, an app of atom-shell should contains at least following files:
|
||||
|
||||
```text
|
||||
app/
|
||||
├── package.json
|
||||
├── main.js
|
||||
└── index.html
|
||||
```
|
||||
|
||||
The format of `package.json` is exactly the same with node's modules, and the script specified by the `main` field is the startup script of your app, which will run under the browser side. An example of your `package.json` is like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"name" : "atom",
|
||||
"version" : "0.1.0",
|
||||
"main" : "main.js"
|
||||
}
|
||||
```
|
||||
|
||||
The `main.js` will be executed, and in which you should do the initialization work. To give the developers more power, atom-shell works by exposing necessary Content APIs in javascript, so developers can precisely control every piece of the app. An example of `main.js` is:
|
||||
|
||||
```javascript
|
||||
var app = require('app'); // Module to control application life.
|
||||
var delegate = require('atom_delegate'); // Delegate of Content API.
|
||||
var Window = require('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;
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function() {
|
||||
app.terminate();
|
||||
});
|
||||
|
||||
// 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 Window({ width: 800, height: 600 });
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||
|
||||
// Catch the event when web page in the window changes its title.
|
||||
mainWindow.on('page-title-updated', function(event, title) {
|
||||
// Prevent the default behaviour of 'page-title-updated' event.
|
||||
event.preventDefault();
|
||||
|
||||
// Add a prefix for the window's original title.
|
||||
this.setTitle('Atom Shell - ' + title);
|
||||
});
|
||||
|
||||
// Hook to when the window is closed.
|
||||
mainWindow.on('closed', function() {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Finally the `index.html` is the web page you want to show, in fact you actually don't need to provide it, you can just make the window load url of a remote page.
|
||||
|
||||
## Package your app in atom-shell
|
||||
|
||||
To make atom-shell run your app, you should name the folder of your app as `app`, and put it under `Atom.app/Contents/Resources/`, like this:
|
||||
|
||||
```text
|
||||
Atom.app/Contents/Resources/app/
|
||||
├── package.json
|
||||
├── main.js
|
||||
└── index.html
|
||||
```
|
||||
|
||||
Then atom-shell will automatically read your `package.json`. If there is no `Atom.app/Contents/Resources/app/`, atom-shell will load the default empty app, which is `Atom.app/Contents/Resources/browser/default_app/`.
|
||||
|
||||
## IPC between browser and renderer
|
||||
|
||||
Atom-shell provides a set of javascript APIs for developers to communicate between browser and renderers. There are two types of message: asynchronous messages and synchronous messages, the former one is quite similar with node's IPC APIs, while the latter one is mainly used for implement the RPC API. Details can be found in the `ipc` module reference.
|
38
docs/README.md
Normal file
38
docs/README.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Atom-Shell Documentations
|
||||
|
||||
## Guides
|
||||
|
||||
* [[Quick start]]
|
||||
* [[Build native modules]]
|
||||
|
||||
## Development
|
||||
|
||||
* [[Coding style]]
|
||||
* [[Source code directory structure]]
|
||||
* [[Build instructions (Mac)]]
|
||||
* [[Build instructions (Windows)]]
|
||||
|
||||
## API References
|
||||
|
||||
Renderer side modules:
|
||||
|
||||
* [[ipc (renderer)]]
|
||||
* [[remote]]
|
||||
|
||||
Browser side modules:
|
||||
|
||||
* [[app]]
|
||||
* [[atom-delegate]]
|
||||
* [[auto-updater]]
|
||||
* [[browser-window]]
|
||||
* [[crash-reporter]]
|
||||
* [[dialog]]
|
||||
* [[ipc (browser)]]
|
||||
* [[menu]]
|
||||
* [[menu-item]]
|
||||
* [[power-monitor]]
|
||||
|
||||
Common modules:
|
||||
|
||||
* [[clipboard]]
|
||||
* [[shell]]
|
38
docs/Shell.md
Normal file
38
docs/Shell.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
32
docs/Source-Code-Directory-Structure.md
Normal file
32
docs/Source-Code-Directory-Structure.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
## Overview
|
||||
|
||||
The source code of atom-shell is separated into a few parts, and we are mostly following Chromium on the separation conventions.
|
||||
|
||||
You may need to become familiar with [Chromium's multi-process architecture](http://dev.chromium.org/developers/design-documents/multi-process-architecture) to understand the source code better.
|
||||
|
||||
## Structure of source code
|
||||
|
||||
* **app** - Contains system entry code, this is the most basic level of the program.
|
||||
* **browser** - The frontend including the main window, UI, and all browser side things. This talks to the renderer to manage web pages.
|
||||
* **atom** - Initializes the javascript environment of browser.
|
||||
* **default_app** - The default page to show when atom-shell is started without providing an app.
|
||||
* **api** - The implementation of browser side APIs.
|
||||
* **lib** - Javascript part of the API implementation.
|
||||
* **renderer** - Code that runs in renderer.
|
||||
* **api** - The implementation of renderer side APIs.
|
||||
* **lib** - Javascript part of the API implementation.
|
||||
* **common** - Code that used by both browser and renderer, including some utility functions and code to integrate node's message loop into Chromium's message loop.
|
||||
* **api** - The implementation of common APIs, and foundations of atom-shell's built-in modules.
|
||||
* **lib** - Javascript part of the API implementation.
|
||||
* **spec** - Automatic tests.
|
||||
* **script** - Scripts for building atom-shell.
|
||||
|
||||
## Structure of other directories
|
||||
|
||||
* **vendor** - Build dependencies.
|
||||
* **tools** - Helper scripts to build atom-shell.
|
||||
* **node_modules** - Third party node modules used for building or running specs.
|
||||
* **out** - Output directory for `ninja`.
|
||||
* **dist** - Temporary directory created by `script/create-dist.py` script when creating an distribution.
|
||||
* **node** - Downloaded node binary, it's built from https://github.com/atom/node/tree/chromium-v8.
|
||||
* **frameworks** - Downloaded third-party binaries of frameworks (only on Mac).
|
112
docs/app.md
Normal file
112
docs/app.md
Normal file
|
@ -0,0 +1,112 @@
|
|||
## Synopsis
|
||||
|
||||
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 dock’s 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.
|
27
docs/atom-delegate.md
Normal file
27
docs/atom-delegate.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
37
docs/auto-updater.md
Normal file
37
docs/auto-updater.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
## Synopsis
|
||||
|
||||
`auto-upater` 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()
|
328
docs/browser-window.md
Normal file
328
docs/browser-window.md
Normal file
|
@ -0,0 +1,328 @@
|
|||
## Synopsis
|
||||
|
||||
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();
|
||||
```
|
||||
|
||||
**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
|
||||
|
||||
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: '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.
|
38
docs/clipboard.md
Normal file
38
docs/clipboard.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
22
docs/crash-reporter.md
Normal file
22
docs/crash-reporter.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
## Synopsis
|
||||
|
||||
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
|
47
docs/dialog.md
Normal file
47
docs/dialog.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
20
docs/menu-item.md
Normal file
20
docs/menu-item.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
## 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`.
|
192
docs/menu.md
Normal file
192
docs/menu.md
Normal file
|
@ -0,0 +1,192 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
19
docs/power-monitor.md
Normal file
19
docs/power-monitor.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
59
docs/remote.md
Normal file
59
docs/remote.md
Normal file
|
@ -0,0 +1,59 @@
|
|||
## Synopsis
|
||||
|
||||
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.
|
Loading…
Reference in a new issue