add api doc begin 2.5
This commit is contained in:
parent
11f64b714d
commit
89328c873c
3 changed files with 277 additions and 0 deletions
71
docs-translations/zh-CN/api/synopsis.md
Normal file
71
docs-translations/zh-CN/api/synopsis.md
Normal file
|
@ -0,0 +1,71 @@
|
|||
# 简介
|
||||
|
||||
所有的[Node.js's built-in modules][1]在Electron中都可用,并且所有的node的第三方组件也可以放心使用(包括[自身的模块][2])。
|
||||
|
||||
Electron也提供了一些额外的内置组件来开发传统桌面应用。一些组件只可以在主进程中使用,一些只可以在渲染进程中使用,但是也有部分可以在这2种进程中都可使用。
|
||||
|
||||
基本规则:GUI模块或者系统底层的模块只可以在主进程中使用。要使用这些模块,你应当很熟悉[主进程vs渲染进程][3]脚本的概念。
|
||||
|
||||
主进程脚本看起来像个普通的nodejs脚本
|
||||
|
||||
```javascript
|
||||
const electron = require('electron');
|
||||
const app = electron.app;
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
|
||||
var window = null;
|
||||
|
||||
app.on('ready', function() {
|
||||
window = new BrowserWindow({width: 800, height: 600});
|
||||
window.loadURL('https://github.com');
|
||||
});
|
||||
```
|
||||
|
||||
渲染进程和传统的web界面一样,除了它具有使用node模块的能力:
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script>
|
||||
const remote = require('electron').remote;
|
||||
console.log(remote.app.getVersion());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
如果想运行应用,参考 `Run your app` 。
|
||||
|
||||
## 解构任务
|
||||
|
||||
如果你使用的是CoffeeScript或Babel,你可以使用[destructuring assignment][4]来让使用内置模块更简单:
|
||||
|
||||
```javascript
|
||||
const {app, BrowserWindow} = require('electron');
|
||||
```
|
||||
|
||||
然而如果你使用的是普通的JavaScript,你就需要等到Chrome支持ES6了。
|
||||
|
||||
##使用内置模块时禁用旧样式
|
||||
|
||||
在版本v0.35.0之前,所有的内置模块都需要按造 `require('module-name')` 形式来使用,虽然它有很多[弊端][5],我们仍然在老的应用中友好的支持它。
|
||||
|
||||
为了完整的禁用旧样式,你可以设置环境变量 `ELECTRON_HIDE_INTERNAL_MODULES ` :
|
||||
|
||||
```javascript
|
||||
process.env.ELECTRON_HIDE_INTERNAL_MODULES = 'true'
|
||||
```
|
||||
|
||||
或者调用 `hideInternalModules` API:
|
||||
|
||||
```javascript
|
||||
require('electron').hideInternalModules()
|
||||
```
|
||||
|
||||
|
||||
[1]:http://nodejs.org/api/
|
||||
[2]:https://github.com/heyunjiang/electron/blob/master/docs/tutorial/using-native-node-modules.md
|
||||
[3]:https://github.com/heyunjiang/electron/blob/master/docs/tutorial/quick-start.md#the-main-process
|
||||
[4]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
|
||||
[5]:https://github.com/atom/electron/issues/387
|
158
docs-translations/zh-CN/tutorial/chrome-command-line-switches.md
Normal file
158
docs-translations/zh-CN/tutorial/chrome-command-line-switches.md
Normal file
|
@ -0,0 +1,158 @@
|
|||
# 支持的 Chrome 命令行开关
|
||||
|
||||
这页列出了Chrome浏览器和Electron支持的命令行开关. 你也可以在[app][app]模块的[ready][ready]事件发出之前使用[app.commandLine.appendSwitch][append-switch] 来添加它们到你应用的main脚本里面:
|
||||
|
||||
```javascript
|
||||
const app = require('electron').app;
|
||||
app.commandLine.appendSwitch('remote-debugging-port', '8315');
|
||||
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1');
|
||||
|
||||
app.on('ready', function() {
|
||||
// Your code here
|
||||
});
|
||||
```
|
||||
|
||||
## --client-certificate=`path`
|
||||
|
||||
设置客户端的证书文件 `path` .
|
||||
|
||||
## --ignore-connections-limit=`domains`
|
||||
|
||||
忽略用 `,` 分隔的 `domains` 列表的连接限制.
|
||||
|
||||
## --disable-http-cache
|
||||
|
||||
禁用 HTTP 请求的 磁盘缓存.
|
||||
|
||||
## --remote-debugging-port=`port`
|
||||
|
||||
在指定的 `端口` 通过 HTTP 开启远程调试.
|
||||
|
||||
## --js-flags=`flags`
|
||||
|
||||
Specifies the flags passed to JS engine. It has to be passed when starting
|
||||
Electron if you want to enable the `flags` in the main process.
|
||||
|
||||
```bash
|
||||
$ electron --js-flags="--harmony_proxies --harmony_collections" your-app
|
||||
```
|
||||
|
||||
## --proxy-server=`address:port`
|
||||
|
||||
Use a specified proxy server, which overrides the system setting. This switch
|
||||
only affects requests with HTTP protocol, including HTTPS and WebSocket
|
||||
requests. It is also noteworthy that not all proxy servers support HTTPS and
|
||||
WebSocket requests.
|
||||
|
||||
## --proxy-bypass-list=`hosts`
|
||||
|
||||
Instructs Electron to bypass the proxy server for the given semi-colon-separated
|
||||
list of hosts. This flag has an effect only if used in tandem with
|
||||
`--proxy-server`.
|
||||
|
||||
For example:
|
||||
|
||||
```javascript
|
||||
app.commandLine.appendSwitch('proxy-bypass-list', '<local>;*.google.com;*foo.com;1.2.3.4:5678')
|
||||
```
|
||||
|
||||
Will use the proxy server for all hosts except for local addresses (`localhost`,
|
||||
`127.0.0.1` etc.), `google.com` subdomains, hosts that contain the suffix
|
||||
`foo.com` and anything at `1.2.3.4:5678`.
|
||||
|
||||
## --proxy-pac-url=`url`
|
||||
|
||||
Uses the PAC script at the specified `url`.
|
||||
|
||||
## --no-proxy-server
|
||||
|
||||
Don't use a proxy server and always make direct connections. Overrides any other
|
||||
proxy server flags that are passed.
|
||||
|
||||
## --host-rules=`rules`
|
||||
|
||||
A comma-separated list of `rules` that control how hostnames are mapped.
|
||||
|
||||
For example:
|
||||
|
||||
* `MAP * 127.0.0.1` Forces all hostnames to be mapped to 127.0.0.1
|
||||
* `MAP *.google.com proxy` Forces all google.com subdomains to be resolved to
|
||||
"proxy".
|
||||
* `MAP test.com [::1]:77` Forces "test.com" to resolve to IPv6 loopback. Will
|
||||
also force the port of the resulting socket address to be 77.
|
||||
* `MAP * baz, EXCLUDE www.google.com` Remaps everything to "baz", except for
|
||||
"www.google.com".
|
||||
|
||||
These mappings apply to the endpoint host in a net request (the TCP connect
|
||||
and host resolver in a direct connection, and the `CONNECT` in an HTTP proxy
|
||||
connection, and the endpoint host in a `SOCKS` proxy connection).
|
||||
|
||||
## --host-resolver-rules=`rules`
|
||||
|
||||
Like `--host-rules` but these `rules` only apply to the host resolver.
|
||||
|
||||
## --ignore-certificate-errors
|
||||
|
||||
Ignores certificate related errors.
|
||||
|
||||
## --ppapi-flash-path=`path`
|
||||
|
||||
Sets the `path` of the pepper flash plugin.
|
||||
|
||||
## --ppapi-flash-version=`version`
|
||||
|
||||
Sets the `version` of the pepper flash plugin.
|
||||
|
||||
## --log-net-log=`path`
|
||||
|
||||
Enables net log events to be saved and writes them to `path`.
|
||||
|
||||
## --ssl-version-fallback-min=`version`
|
||||
|
||||
Sets the minimum SSL/TLS version ("tls1", "tls1.1" or "tls1.2") that TLS
|
||||
fallback will accept.
|
||||
|
||||
## --cipher-suite-blacklist=`cipher_suites`
|
||||
|
||||
Specifies comma-separated list of SSL cipher suites to disable.
|
||||
|
||||
## --disable-renderer-backgrounding
|
||||
|
||||
Prevents Chromium from lowering the priority of invisible pages' renderer
|
||||
processes.
|
||||
|
||||
This flag is global to all renderer processes, if you only want to disable
|
||||
throttling in one window, you can take the hack of
|
||||
[playing silent audio][play-silent-audio].
|
||||
|
||||
## --enable-logging
|
||||
|
||||
Prints Chromium's logging into console.
|
||||
|
||||
This switch can not be used in `app.commandLine.appendSwitch` since it is parsed
|
||||
earlier than user's app is loaded, but you can set the `ELECTRON_ENABLE_LOGGING`
|
||||
environment variable to achieve the same effect.
|
||||
|
||||
## --v=`log_level`
|
||||
|
||||
Gives the default maximal active V-logging level; 0 is the default. Normally
|
||||
positive values are used for V-logging levels.
|
||||
|
||||
This switch only works when `--enable-logging` is also passed.
|
||||
|
||||
## --vmodule=`pattern`
|
||||
|
||||
Gives the per-module maximal V-logging levels to override the value given by
|
||||
`--v`. E.g. `my_module=2,foo*=3` would change the logging level for all code in
|
||||
source files `my_module.*` and `foo*.*`.
|
||||
|
||||
Any pattern containing a forward or backward slash will be tested against the
|
||||
whole pathname and not just the module. E.g. `*/foo/bar/*=2` would change the
|
||||
logging level for all code in the source files under a `foo/bar` directory.
|
||||
|
||||
This switch only works when `--enable-logging` is also passed.
|
||||
|
||||
[app]: app.md
|
||||
[append-switch]: app.md#appcommandlineappendswitchswitch-value
|
||||
[ready]: app.md#event-ready
|
||||
[play-silent-audio]: https://github.com/atom/atom/pull/9485/files
|
48
docs-translations/zh-CN/tutorial/process.md
Normal file
48
docs-translations/zh-CN/tutorial/process.md
Normal file
|
@ -0,0 +1,48 @@
|
|||
# 进程
|
||||
|
||||
Electron 中的 `process` 对象 与 upstream node 中的有以下的不同点:
|
||||
|
||||
* `process.type` String - 进程类型, 可以是 `browser` (i.e. main process)
|
||||
或 `renderer`.
|
||||
* `process.versions['electron']` String - Electron的版本.
|
||||
* `process.versions['chrome']` String - Chromium的版本.
|
||||
* `process.resourcesPath` String - JavaScript源代码路径.
|
||||
* `process.mas` Boolean - 在Mac App Store 创建, 它的值为 `true`, 在其它的地方值为 `undefined`.
|
||||
|
||||
## 事件
|
||||
|
||||
### 事件: 'loaded'
|
||||
|
||||
在Electron已经加载了其内部预置脚本和它准备加载主进程或渲染进程的时候触发.
|
||||
|
||||
当node被完全关闭的时候,它可以被预加载脚本使用来添加(原文: removed)与node无关的全局符号来回退到全局范围:
|
||||
|
||||
```js
|
||||
// preload.js
|
||||
var _setImmediate = setImmediate;
|
||||
var _clearImmediate = clearImmediate;
|
||||
process.once('loaded', function() {
|
||||
global.setImmediate = _setImmediate;
|
||||
global.clearImmediate = _clearImmediate;
|
||||
});
|
||||
```
|
||||
|
||||
## 属性
|
||||
|
||||
### `process.noAsar`
|
||||
|
||||
设置它为 `true` 可以使 `asar` 文件在node的内置模块中实效.
|
||||
|
||||
## 方法
|
||||
|
||||
`process` 对象有如下方法:
|
||||
|
||||
### `process.hang()`
|
||||
|
||||
使当前进程的主线成挂起.
|
||||
|
||||
### `process.setFdLimit(maxDescriptors)` _OS X_ _Linux_
|
||||
|
||||
* `maxDescriptors` Integer
|
||||
|
||||
设置文件描述符软限制于 `maxDescriptors` 或硬限制与os, 无论它是否低于当前进程.
|
Loading…
Reference in a new issue