standardize docs-translations by hand
This commit is contained in:
parent
3e4a0705e9
commit
253a383168
52 changed files with 318 additions and 315 deletions
|
@ -19,7 +19,7 @@ está comenzando a cargar la página web o el script principal.
|
|||
Puede ser usado por el script precargado para añadir de nuevo los símbolos globales
|
||||
de Node eliminados, al alcance global cuando la integración de Node está apagada:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// preload.js
|
||||
var _setImmediate = setImmediate
|
||||
var _clearImmediate = clearImmediate
|
||||
|
|
|
@ -63,12 +63,14 @@ Para establecer tu menú dock, puedes utilizar la API `app.dock.setMenu`, la cua
|
|||
var app = require('app')
|
||||
var Menu = require('menu')
|
||||
var dockMenu = Menu.buildFromTemplate([
|
||||
{ label: 'New Window', click: function () { console.log('New Window') } },
|
||||
{ label: 'New Window with Settings', submenu: [
|
||||
{ label: 'Basic' },
|
||||
{ label: 'Pro'}
|
||||
]},
|
||||
{ label: 'New Command...'}
|
||||
{label: 'New Window', click: function () { console.log('New Window') }},
|
||||
{label: 'New Window with Settings',
|
||||
submenu: [
|
||||
{label: 'Basic'},
|
||||
{label: 'Pro'}
|
||||
]
|
||||
},
|
||||
{label: 'New Command...'}
|
||||
])
|
||||
app.dock.setMenu(dockMenu)
|
||||
```
|
||||
|
@ -157,8 +159,8 @@ Para establecer la barra de progreso de una ventana, puedes utilizar
|
|||
[BrowserWindow.setProgressBar][setprogressbar] API:
|
||||
|
||||
```javascript
|
||||
var window = new BrowserWindow({...});
|
||||
window.setProgressBar(0.5);
|
||||
var window = new BrowserWindow()
|
||||
window.setProgressBar(0.5)
|
||||
```
|
||||
|
||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath
|
||||
|
|
|
@ -12,7 +12,7 @@ var onlineStatusWindow
|
|||
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -50,7 +50,7 @@ var onlineStatusWindow
|
|||
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
|
||||
ipc.on('online-status-changed', function (event, status) {
|
||||
|
|
|
@ -54,7 +54,7 @@ El formato de `package.json` es exactamente el mismo que cualquier módulo Node,
|
|||
y el script especificado en el campo `main` será el script de arranque de tu aplicación,
|
||||
a ser ejecutado por el proceso principal. Un ejemplo de `package.json` podría verse así:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "your-app",
|
||||
"version" : "0.1.0",
|
||||
|
@ -77,7 +77,7 @@ app.on('window-all-closed', function () {
|
|||
// En macOS es común que las aplicaciones y su barra de menú
|
||||
// se mantengan activas hasta que el usuario cierre la aplicación
|
||||
// explícitamente utilizando Cmd + Q
|
||||
if (process.platform != 'darwin') {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
@ -89,7 +89,7 @@ app.on('ready', function () {
|
|||
mainWindow = new BrowserWindow({width: 800, height: 600})
|
||||
|
||||
// cargar el index.html de nuestra aplicación.
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
|
||||
// Desplegar devtools.
|
||||
mainWindow.openDevTools()
|
||||
|
|
|
@ -21,7 +21,7 @@ var mainWindow = null
|
|||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function () {
|
||||
if (process.platform != 'darwin') {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
@ -43,7 +43,7 @@ app.on('ready', function () {
|
|||
'plugins': true
|
||||
}
|
||||
})
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
// Something else
|
||||
})
|
||||
```
|
||||
|
|
|
@ -135,7 +135,7 @@ Windowsでは、ファイルパスを取得するために、 `process.argv` を
|
|||
|
||||
```javascript
|
||||
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
||||
if (url == 'https://github.com') {
|
||||
if (url === 'https://github.com') {
|
||||
// Verification logic.
|
||||
event.preventDefault()
|
||||
callback(true)
|
||||
|
@ -325,26 +325,25 @@ macOSは、ユーザーがFinderで2つ目のアプリインスタンスを開
|
|||
|
||||
2つ目のインスタンスを起動するとき、メインのインスタンスのウィンドウをアクティブにする例
|
||||
|
||||
```js
|
||||
var myWindow = null;
|
||||
```javascript
|
||||
var myWindow = null
|
||||
|
||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
|
||||
// Someone tried to run a second instance, we should focus our window
|
||||
if (myWindow) {
|
||||
if (myWindow.isMinimized()) myWindow.restore();
|
||||
myWindow.focus();
|
||||
if (myWindow.isMinimized()) myWindow.restore()
|
||||
myWindow.focus()
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true
|
||||
})
|
||||
|
||||
if (shouldQuit) {
|
||||
app.quit();
|
||||
return;
|
||||
app.quit()
|
||||
}
|
||||
|
||||
// Create myWindow, load the rest of the app, etc...
|
||||
app.on('ready', function() {
|
||||
});
|
||||
app.on('ready', function () {
|
||||
// Create myWindow, load the rest of the app, etc...
|
||||
})
|
||||
```
|
||||
|
||||
### `app.setAppUserModelId(id)` _Windows_
|
||||
|
@ -359,7 +358,7 @@ app.on('ready', function() {
|
|||
|
||||
使用例:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
let browserOptions = {width: 1000, height: 800}
|
||||
|
||||
// Make the window transparent only if the platform supports it.
|
||||
|
@ -373,10 +372,10 @@ win = new BrowserWindow(browserOptions)
|
|||
|
||||
// Navigate.
|
||||
if (browserOptions.transparent) {
|
||||
win.loadURL('file://' + __dirname + '/index.html')
|
||||
win.loadURL(`file://${__dirname}/index.html`)
|
||||
} else {
|
||||
// No transparency, so we load a fallback that uses basic styles.
|
||||
win.loadURL('file://' + __dirname + '/fallback.html')
|
||||
win.loadURL(`file://${__dirname}/fallback.html`)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ var desktopCapturer = require('electron').desktopCapturer
|
|||
desktopCapturer.getSources({types: ['window', 'screen']}, function (error, sources) {
|
||||
if (error) throw error
|
||||
for (var i = 0; i < sources.length; ++i) {
|
||||
if (sources[i].name == 'Electron') {
|
||||
if (sources[i].name === 'Electron') {
|
||||
navigator.webkitGetUserMedia({
|
||||
audio: false,
|
||||
video: {
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
複数のファイルやディレクトリを選択するためのダイアログを表示する例です:
|
||||
|
||||
```javascript
|
||||
var win = ...; // BrowserWindow in which to show the dialog
|
||||
const dialog = require('electron').dialog;
|
||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||
const {dialog} = require('electron')
|
||||
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}))
|
||||
```
|
||||
|
||||
**Note for macOS**: シートとしてダイアログを表示したい場合、唯一しなければならないことは、`browserWindow`パラメーターを参照する`BrowserWindow`を提供することです。
|
||||
|
|
|
@ -4,22 +4,31 @@
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
win.webContents.session.on('will-download', function(event, item, webContents) {
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.webContents.session.on('will-download', (event, item, webContents) => {
|
||||
// Set the save path, making Electron not to prompt a save dialog.
|
||||
item.setSavePath('/tmp/save.pdf');
|
||||
console.log(item.getMimeType());
|
||||
console.log(item.getFilename());
|
||||
console.log(item.getTotalBytes());
|
||||
item.on('updated', function() {
|
||||
console.log('Received bytes: ' + item.getReceivedBytes());
|
||||
});
|
||||
item.on('done', function(e, state) {
|
||||
if (state == "completed") {
|
||||
console.log("Download successfully");
|
||||
} else {
|
||||
console.log("Download is cancelled or interrupted that can't be resumed");
|
||||
item.setSavePath('/tmp/save.pdf')
|
||||
|
||||
item.on('updated', (event, state) => {
|
||||
if (state === 'interrupted') {
|
||||
console.log('Download is interrupted but can be resumed')
|
||||
} else if (state === 'progressing') {
|
||||
if (item.isPaused()) {
|
||||
console.log('Download is paused')
|
||||
} else {
|
||||
console.log(`Received bytes: ${item.getReceivedBytes()}`)
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
item.once('done', (event, state) => {
|
||||
if (state === 'completed') {
|
||||
console.log('Download successfully')
|
||||
} else {
|
||||
console.log(`Download failed: ${state}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
## イベント
|
||||
|
|
|
@ -74,34 +74,35 @@ var template = [
|
|||
label: 'Reload',
|
||||
accelerator: 'CmdOrCtrl+R',
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.reload()
|
||||
if (focusedWindow) focusedWindow.reload()
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Full Screen',
|
||||
accelerator: (function () {
|
||||
if (process.platform == 'darwin')
|
||||
if (process.platform === 'darwin') {
|
||||
return 'Ctrl+Command+F'
|
||||
else
|
||||
} else {
|
||||
return 'F11'
|
||||
}
|
||||
})(),
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
if (focusedWindow) {
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: (function () {
|
||||
if (process.platform == 'darwin')
|
||||
if (process.platform === 'darwin') {
|
||||
return 'Alt+Command+I'
|
||||
else
|
||||
} else {
|
||||
return 'Ctrl+Shift+I'
|
||||
}
|
||||
})(),
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.toggleDevTools()
|
||||
if (focusedWindow) focusedWindow.toggleDevTools()
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -134,7 +135,7 @@ var template = [
|
|||
}
|
||||
]
|
||||
|
||||
if (process.platform == 'darwin') {
|
||||
if (process.platform === 'darwin') {
|
||||
var name = require('electron').remote.app.getName()
|
||||
template.unshift({
|
||||
label: name,
|
||||
|
|
|
@ -12,7 +12,7 @@ Electronの`process`オブジェクトは次のようなAPIで拡張されてい
|
|||
|
||||
Node統合がオフになっているとき、削除したNodeグローバルシンボルをグローバルスコープへ戻すために、プリロードスクリプトで使用できます。
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// preload.js
|
||||
var _setImmediate = setImmediate
|
||||
var _clearImmediate = clearImmediate
|
||||
|
|
|
@ -5,18 +5,16 @@
|
|||
`file://`プロトコルの同様の効果をもつプロトコルを実装した例です。
|
||||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const {app} = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
app.on('ready', function () {
|
||||
var protocol = electron.protocol
|
||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
||||
var url = request.url.substr(7)
|
||||
callback({path: path.normalize(__dirname + '/' + url)})
|
||||
callback({path: path.join(__dirname, url)})
|
||||
}, function (error) {
|
||||
if (error)
|
||||
console.error('Failed to register protocol')
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
@ -80,8 +78,7 @@ app.on('ready', function () {
|
|||
protocol.registerBufferProtocol('atom', function (request, callback) {
|
||||
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')})
|
||||
}, function (error) {
|
||||
if (error)
|
||||
console.error('Failed to register protocol')
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ app.on('ready', function () {
|
|||
var displays = electronScreen.getAllDisplays()
|
||||
var externalDisplay = null
|
||||
for (var i in displays) {
|
||||
if (displays[i].bounds.x != 0 || displays[i].bounds.y != 0) {
|
||||
if (displays[i].bounds.x !== 0 || displays[i].bounds.y !== 0) {
|
||||
externalDisplay = displays[i]
|
||||
break
|
||||
}
|
||||
|
|
|
@ -77,11 +77,13 @@ session.defaultSession.on('will-download', function (event, item, webContents) {
|
|||
```javascript
|
||||
// Query all cookies.
|
||||
session.defaultSession.cookies.get({}, function (error, cookies) {
|
||||
if (error) console.error(error)
|
||||
console.log(cookies)
|
||||
})
|
||||
|
||||
// Query all cookies associated with a specific url.
|
||||
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (error, cookies) {
|
||||
if (error) console.error(error)
|
||||
console.log(cookies)
|
||||
})
|
||||
|
||||
|
@ -89,8 +91,7 @@ session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (e
|
|||
// may overwrite equivalent cookies if they exist.
|
||||
var cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
|
||||
session.defaultSession.cookies.set(cookie, function (error) {
|
||||
if (error)
|
||||
console.error(error)
|
||||
if (error) console.error(error)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -255,10 +256,7 @@ Calling `setCertificateVerifyProc(null)`をコールして、既定の証明書
|
|||
|
||||
```javascript
|
||||
myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert, callback) {
|
||||
if (hostname == 'github.com')
|
||||
callback(true)
|
||||
else
|
||||
callback(false)
|
||||
callback(hostname === 'github.com')
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
@ -577,8 +577,7 @@ webview.addEventListener('console-message', (e) => {
|
|||
|
||||
```javascript
|
||||
webview.addEventListener('found-in-page', (e) => {
|
||||
if (e.result.finalUpdate)
|
||||
webview.stopFindInPage('keepSelection')
|
||||
if (e.result.finalUpdate) webview.stopFindInPage('keepSelection')
|
||||
})
|
||||
|
||||
const requestId = webview.findInPage('test')
|
||||
|
|
|
@ -87,21 +87,21 @@ __Dock menu of Terminal.app:__
|
|||
カスタムドックメニューを設定するために、macOSのみに提供されている `app.dock.setMenu` APIを使用できます。
|
||||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const Menu = electron.Menu
|
||||
const {app, Menu} = require('electron')
|
||||
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
{ label: 'New Window', click () { console.log('New Window') } },
|
||||
{ label: 'New Window with Settings', submenu: [
|
||||
{ label: 'Basic' },
|
||||
{ label: 'Pro'}
|
||||
{label: 'New Window', click () { console.log('New Window') }},
|
||||
{label: 'New Window with Settings',
|
||||
submenu: [
|
||||
{label: 'Basic'},
|
||||
{label: 'Pro'}
|
||||
]},
|
||||
{ label: 'New Command...'}
|
||||
{label: 'New Command...'}
|
||||
])
|
||||
app.dock.setMenu(dockMenu)
|
||||
```
|
||||
|
||||
|
||||
## ユーザータスク (Windows)
|
||||
|
||||
Windowsでは、ジャンプリストの `Tasks` カテゴリでカスタムアクションを指定できます。
|
||||
|
@ -206,8 +206,8 @@ __タスクバーボタン上の進行状況バー:__
|
|||
ウィンドウに進行状況バーを設定するために、[BrowserWindow.setProgressBar][setprogressbar] APIを使えます:
|
||||
|
||||
```javascript
|
||||
let win = new BrowserWindow({...});
|
||||
win.setProgressBar(0.5);
|
||||
let win = new BrowserWindow()
|
||||
win.setProgressBar(0.5)
|
||||
```
|
||||
|
||||
## タスクバーでアイコンをオーバーレイする (Windows)
|
||||
|
@ -223,8 +223,8 @@ __タスクバーボタンでのオーバーレイ:__
|
|||
ウィンドウでオーバーレイアイコンを設定するために、[BrowserWindow.setOverlayIcon][setoverlayicon] APIを使用できます。
|
||||
|
||||
```javascript
|
||||
let win = new BrowserWindow({...});
|
||||
win.setOverlayIcon('path/to/overlay.png', 'Description for overlay');
|
||||
let win = new BrowserWindow()
|
||||
win.setOverlayIcon('path/to/overlay.png', 'Description for overlay')
|
||||
```
|
||||
|
||||
## Windowのファイル表示 (macOS)
|
||||
|
@ -240,9 +240,9 @@ __Represented file ポップアップメニュー:__
|
|||
ウィンドウにrepresented fileを設定するために、[BrowserWindow.setRepresentedFilename][setrepresentedfilename] と [BrowserWindow.setDocumentEdited][setdocumentedited] APIsを使えます:
|
||||
|
||||
```javascript
|
||||
let win = new BrowserWindow({...});
|
||||
win.setRepresentedFilename('/etc/passwd');
|
||||
win.setDocumentEdited(true);
|
||||
let win = new BrowserWindow()
|
||||
win.setRepresentedFilename('/etc/passwd')
|
||||
win.setDocumentEdited(true)
|
||||
```
|
||||
|
||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows
|
||||
|
|
|
@ -39,7 +39,7 @@ your-app/
|
|||
|
||||
`package.json` の形式は Node モジュールとまったく同じです。 `main` フィールドで指定するスクリプトはアプリの起動スクリプトであり、メインプロセスを実行します。 `package.json` の例は次のようになります:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "your-app",
|
||||
"version" : "0.1.0",
|
||||
|
@ -74,8 +74,8 @@ function createWindow () {
|
|||
|
||||
// ウィンドウが閉じられた時に発行される
|
||||
win.on('closed', () => {
|
||||
// ウィンドウオブジェクトを参照から外す。
|
||||
// もし何個かウィンドウがあるならば、配列として持っておいて、対応するウィンドウのオブジェクトを消去するべき。
|
||||
// ウィンドウオブジェクトを参照から外す。
|
||||
// もし何個かウィンドウがあるならば、配列として持っておいて、対応するウィンドウのオブジェクトを消去するべき。
|
||||
win = null
|
||||
})
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ app.on('ready', function () {
|
|||
'plugins': true
|
||||
}
|
||||
})
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
// Something else
|
||||
})
|
||||
```
|
||||
|
|
|
@ -15,7 +15,7 @@ Electronで `chromedriver` を使用するために、Electronがどこにある
|
|||
$ npm install --save-dev spectron
|
||||
```
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// 可視のウィンドウがタイトル付きで開かれているかを調べる簡単なテスト
|
||||
var Application = require('spectron').Application
|
||||
var assert = require('assert')
|
||||
|
|
|
@ -645,15 +645,21 @@ app.setJumpList([
|
|||
name: 'Tools',
|
||||
items: [
|
||||
{
|
||||
type: 'task', title: 'Tool A',
|
||||
program: process.execPath, args: '--run-tool-a',
|
||||
icon: process.execPath, iconIndex: 0,
|
||||
type: 'task',
|
||||
title: 'Tool A',
|
||||
program: process.execPath,
|
||||
args: '--run-tool-a',
|
||||
icon: process.execPath,
|
||||
iconIndex: 0,
|
||||
description: 'Runs Tool A'
|
||||
},
|
||||
{
|
||||
type: 'task', title: 'Tool B',
|
||||
program: process.execPath, args: '--run-tool-b',
|
||||
icon: process.execPath, iconIndex: 0,
|
||||
type: 'task',
|
||||
title: 'Tool B',
|
||||
program: process.execPath,
|
||||
args: '--run-tool-b',
|
||||
icon: process.execPath,
|
||||
iconIndex: 0,
|
||||
description: 'Runs Tool B'
|
||||
}
|
||||
]
|
||||
|
@ -662,14 +668,18 @@ app.setJumpList([
|
|||
{ // has no name and no type so `type` is assumed to be "tasks"
|
||||
items: [
|
||||
{
|
||||
type: 'task', title: 'New Project',
|
||||
program: process.execPath, args: '--new-project',
|
||||
type: 'task',
|
||||
title: 'New Project',
|
||||
program: process.execPath,
|
||||
args: '--new-project',
|
||||
description: 'Create a new project.'
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
type: 'task', title: 'Recover Project',
|
||||
program: process.execPath, args: '--recover-project',
|
||||
type: 'task',
|
||||
title: 'Recover Project',
|
||||
program: process.execPath,
|
||||
args: '--recover-project',
|
||||
description: 'Recover Project'
|
||||
}
|
||||
]
|
||||
|
|
|
@ -97,7 +97,7 @@ Returns `Object`:
|
|||
**참고:** 윈도우의 대부분의 앱은 북마크 붙여넣기를 지원하지 않습니다.
|
||||
`clipboard.write` 를 통해 북마크와 대체 텍스트를 클립보드에 쓸 수 있습니다.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
clipboard.write({
|
||||
text: 'http://electron.atom.io',
|
||||
bookmark: 'Electron Homepage'
|
||||
|
|
|
@ -147,7 +147,7 @@ if (browserOptions.transparent) {
|
|||
|
||||
사용자의 현재 시스템 전체 색상 환경설정을 RGBA 16진 문자열 형태로 반환합니다.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
const color = systemPreferences.getAccentColor() // `"aabbccdd"`
|
||||
const red = color.substr(0, 2) // "aa"
|
||||
const green = color.substr(2, 2) // "bb"
|
||||
|
|
|
@ -9,7 +9,7 @@ $ code electron-quick-start
|
|||
|
||||
### 2. 다음 설정으로 `.vscode/launch.json` 파일 추가하기:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
|
|
@ -116,7 +116,8 @@ const {app, Menu} = require('electron')
|
|||
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
{label: 'New Window', click () { console.log('New Window') }},
|
||||
{label: 'New Window with Settings', submenu: [
|
||||
{label: 'New Window with Settings',
|
||||
submenu: [
|
||||
{label: 'Basic'},
|
||||
{label: 'Pro'}
|
||||
]},
|
||||
|
|
|
@ -61,7 +61,7 @@ your-app/
|
|||
파일을 지정하면 메인 프로세스의 엔트리 포인트로 사용합니다. 예를 들어 사용할 수 있는
|
||||
`package.json`은 다음과 같습니다:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "your-app",
|
||||
"version" : "0.1.0",
|
||||
|
|
|
@ -153,7 +153,7 @@ para confiar no certificado, você deve impedir o comportamento padrão com
|
|||
|
||||
```javascript
|
||||
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
||||
if (url == 'https://github.com') {
|
||||
if (url === 'https://github.com') {
|
||||
// Lógica de verificação.
|
||||
event.preventDefault()
|
||||
callback(true)
|
||||
|
@ -365,26 +365,23 @@ No macOS o sistema enforça instância única automaticamente quando usuários t
|
|||
|
||||
Um exemplo de ativação da janela de primeira instância quando uma segunda instância inicializa:
|
||||
|
||||
```js
|
||||
var myWindow = null;
|
||||
```javascript
|
||||
let myWindow = null
|
||||
|
||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||
let shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
|
||||
// Alguém tentou rodar uma segunda instância, devemos focar nossa janela
|
||||
if (myWindow) {
|
||||
if (myWindow.isMinimized()) myWindow.restore();
|
||||
myWindow.focus();
|
||||
if (myWindow.isMinimized()) myWindow.restore()
|
||||
myWindow.focus()
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true
|
||||
})
|
||||
|
||||
if (shouldQuit) {
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
if (shouldQuit) app.quit()
|
||||
|
||||
// Cria myWindow, carrega o resto do aplicativo, etc...
|
||||
app.on('ready', function() {
|
||||
});
|
||||
app.on('ready', function () {
|
||||
// Cria myWindow, carrega o resto do aplicativo, etc...
|
||||
})
|
||||
```
|
||||
|
||||
### `app.setAppUserModelId(id)` _Windows_
|
||||
|
|
|
@ -191,7 +191,7 @@ Emitido quando a janela sai do estado de tela cheia, ocasionado por uma api de h
|
|||
|
||||
Emitido quando um [App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx) é invocado. Estes estão tipicamente relacionado às teclas de mídia do teclado, ou comandos do browser, assim como o botão "Voltar" existente em alguns modelos de mouse no Windows.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
someWindow.on('app-command', function (e, cmd) {
|
||||
// Navega a janela 'para trás' quando o usuário pressiona o botão voltar do mouse
|
||||
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
||||
|
|
|
@ -16,7 +16,7 @@ Emitido quando o Electron carregou seu script de inicialização interno e está
|
|||
|
||||
Pode ser utilizado pelo script pré-carregamento (preload.js abaixo) para adicionar símbolos globais do Node removidos para o escopo global quando a integração do node é desligada:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// preload.js
|
||||
var _setImmediate = setImmediate
|
||||
var _clearImmediate = clearImmediate
|
||||
|
|
|
@ -67,15 +67,16 @@ Para criar seu Dock Menu customizado, você pode usar a API `app.dock.setMenu`,
|
|||
ela está disponível apenas no macOS:
|
||||
|
||||
```javascript
|
||||
var app = require('app')
|
||||
var Menu = require('menu')
|
||||
var dockMenu = Menu.buildFromTemplate([
|
||||
{ label: 'New Window', click: function () { console.log('New Window') } },
|
||||
{ label: 'New Window with Settings', submenu: [
|
||||
{ label: 'Basic' },
|
||||
{ label: 'Pro'}
|
||||
const {app, Menu} = require('electron')
|
||||
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
{label: 'New Window', click () { console.log('New Window') }},
|
||||
{label: 'New Window with Settings',
|
||||
submenu: [
|
||||
{label: 'Basic'},
|
||||
{label: 'Pro'}
|
||||
]},
|
||||
{ label: 'New Command...'}
|
||||
{label: 'New Command...'}
|
||||
])
|
||||
app.dock.setMenu(dockMenu)
|
||||
```
|
||||
|
@ -163,26 +164,26 @@ __Miniaturas da barra de tarefas do Windows Media Player:__
|
|||
Você pode usar [BrowserWindow.setThumbarButtons][setthumbarbuttons] para criar
|
||||
miniaturas na barra de ferramentas para sua aplicação.
|
||||
|
||||
```
|
||||
var BrowserWindow = require('browser-window');
|
||||
var path = require('path');
|
||||
```javascript
|
||||
var BrowserWindow = require('browser-window')
|
||||
var path = require('path')
|
||||
var win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600
|
||||
});
|
||||
})
|
||||
win.setThumbarButtons([
|
||||
{
|
||||
tooltip: "button1",
|
||||
tooltip: 'button1',
|
||||
icon: path.join(__dirname, 'button1.png'),
|
||||
click: function() { console.log("button2 clicked"); }
|
||||
click: function () { console.log('button2 clicked') }
|
||||
},
|
||||
{
|
||||
tooltip: "button2",
|
||||
tooltip: 'button2',
|
||||
icon: path.join(__dirname, 'button2.png'),
|
||||
flags:['enabled', 'dismissonclick'],
|
||||
click: function() { console.log("button2 clicked."); }
|
||||
flags: ['enabled', 'dismissonclick'],
|
||||
click: function () { console.log('button2 clicked.') }
|
||||
}
|
||||
]);
|
||||
])
|
||||
```
|
||||
|
||||
Para limpar os botões na miniatura da barra de ferramentas, apenas chame
|
||||
|
@ -222,8 +223,8 @@ Para adicionar uma barra de progresso para uma janela, você pode ver a API:
|
|||
[BrowserWindow.setProgressBar][setprogressbar]:
|
||||
|
||||
```javascript
|
||||
var window = new BrowserWindow({...});
|
||||
window.setProgressBar(0.5);
|
||||
var window = new BrowserWindow()
|
||||
window.setProgressBar(0.5)
|
||||
```
|
||||
|
||||
## Representação do arquivo na janela (macOS)
|
||||
|
@ -244,9 +245,9 @@ Para inserir o arquivo de representacão da janela, você pode usar as API
|
|||
[BrowserWindow.setDocumentEdited][setdocumentedited]:
|
||||
|
||||
```javascript
|
||||
var window = new BrowserWindow({...});
|
||||
window.setRepresentedFilename('/etc/passwd');
|
||||
window.setDocumentEdited(true);
|
||||
var window = new BrowserWindow()
|
||||
window.setRepresentedFilename('/etc/passwd')
|
||||
window.setDocumentEdited(true)
|
||||
```
|
||||
|
||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath
|
||||
|
|
|
@ -13,7 +13,7 @@ var onlineStatusWindow
|
|||
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -53,7 +53,7 @@ var onlineStatusWindow
|
|||
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
|
||||
ipc.on('online-status-changed', function (event, status) {
|
||||
|
@ -66,18 +66,18 @@ _online-status.html_
|
|||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script>
|
||||
var ipc = require('ipc');
|
||||
var updateOnlineStatus = function() {
|
||||
ipc.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
||||
};
|
||||
<body>
|
||||
<script>
|
||||
const {ipcRenderer} = require('electron')
|
||||
const updateOnlineStatus = () => {
|
||||
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline')
|
||||
}
|
||||
|
||||
window.addEventListener('online', updateOnlineStatus);
|
||||
window.addEventListener('offline', updateOnlineStatus);
|
||||
window.addEventListener('online', updateOnlineStatus)
|
||||
window.addEventListener('offline', updateOnlineStatus)
|
||||
|
||||
updateOnlineStatus();
|
||||
</script>
|
||||
</body>
|
||||
updateOnlineStatus()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
|
|
@ -63,7 +63,7 @@ e o script especificado pelo campo `main` é o script de inicialização do seu
|
|||
que irá executar o processo principal. Um exemplo do seu `package.json` deve parecer
|
||||
com isso:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "seu-app",
|
||||
"version" : "0.1.0",
|
||||
|
|
|
@ -20,18 +20,15 @@ para a linha de comando do Electron ou usando o método
|
|||
Por exemplo:
|
||||
|
||||
```javascript
|
||||
var app = require('app')
|
||||
var BrowserWindow = require('browser-window')
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
|
||||
// Mantém uma referência global da janela, se não manter, a janela irá fechar
|
||||
// automaticamente quando o objeto javascript for GCed.
|
||||
var mainWindow = null
|
||||
let mainWindow = null
|
||||
|
||||
// Sai assim que todas as janelas forem fechadas.
|
||||
app.on('window-all-closed', function () {
|
||||
if (process.platform != 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
|
||||
// Epecifica o caminho do flash.
|
||||
|
@ -51,7 +48,7 @@ app.on('ready', function () {
|
|||
'plugins': true
|
||||
}
|
||||
})
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
// Algo mais
|
||||
})
|
||||
```
|
||||
|
|
|
@ -60,7 +60,7 @@ your-app/
|
|||
как `main`, будет выполняться при запуске вашего приложения, работая в
|
||||
главном процессе. Например, Ваш `package.json` может выглядеть вот так:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "your-app",
|
||||
"version" : "0.1.0",
|
||||
|
@ -91,7 +91,7 @@ function createWindow () {
|
|||
mainWindow = new BrowserWindow({width: 800, height: 600})
|
||||
|
||||
// и загружаем index.html приложения.
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
|
||||
// Открываем DevTools.
|
||||
mainWindow.webContents.openDevTools()
|
||||
|
|
|
@ -144,7 +144,7 @@ app.on('window-all-closed', function () {
|
|||
|
||||
```javascript
|
||||
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
||||
if (url == 'https://github.com') {
|
||||
if (url === 'https://github.com') {
|
||||
// 验证逻辑。
|
||||
event.preventDefault()
|
||||
callback(true)
|
||||
|
@ -363,29 +363,26 @@ app.on('login', function (event, webContents, request, authInfo, callback) {
|
|||
|
||||
下面是一个简单的例子。我们可以通过这个例子了解如何确保应用为单实例运行状态。
|
||||
|
||||
```js
|
||||
var myWindow = null;
|
||||
```javascript
|
||||
let myWindow = null
|
||||
|
||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||
let shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
|
||||
// 当另一个实例运行的时候,这里将会被调用,我们需要激活应用的窗口
|
||||
if (myWindow) {
|
||||
if (myWindow.isMinimized()) myWindow.restore();
|
||||
myWindow.focus();
|
||||
if (myWindow.isMinimized()) myWindow.restore()
|
||||
myWindow.focus()
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true
|
||||
})
|
||||
|
||||
// 这个实例是多余的实例,需要退出
|
||||
if (shouldQuit) {
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建窗口、继续加载应用、应用逻辑等……
|
||||
app.on('ready', function() {
|
||||
});
|
||||
if (shouldQuit) app.quit()
|
||||
|
||||
app.on('ready', function () {
|
||||
// 创建窗口、继续加载应用、应用逻辑等……
|
||||
})
|
||||
```
|
||||
|
||||
### `app.setAppUserModelId(id)` _Windows_
|
||||
|
||||
* `id` String
|
||||
|
@ -400,7 +397,7 @@ app.on('ready', function() {
|
|||
|
||||
举个例子:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
let browserOptions = {width: 1000, height: 800}
|
||||
|
||||
// 只有平台支持的时候才使用透明窗口
|
||||
|
@ -414,10 +411,10 @@ win = new BrowserWindow(browserOptions)
|
|||
|
||||
// 转到某个网页
|
||||
if (browserOptions.transparent) {
|
||||
win.loadURL('file://' + __dirname + '/index.html')
|
||||
win.loadURL(`file://${__dirname}/index.html`)
|
||||
} else {
|
||||
// 没有透明特效,我们应该用某个只包含基本样式的替代解决方案。
|
||||
win.loadURL('file://' + __dirname + '/fallback.html')
|
||||
win.loadURL(`file://${__dirname}/fallback.html`)
|
||||
}
|
||||
```
|
||||
### `app.commandLine.appendSwitch(switch[, value])`
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
const BrowserWindow = require('electron').BrowserWindow
|
||||
|
||||
// Or in the renderer process.
|
||||
const BrowserWindow = require('electron').remote.BrowserWindow
|
||||
// const BrowserWindow = require('electron').remote.BrowserWindow
|
||||
|
||||
var win = new BrowserWindow({ width: 800, height: 600, show: false })
|
||||
win.on('closed', function () {
|
||||
|
@ -233,7 +233,7 @@ window.onbeforeunload = function (e) {
|
|||
在请求一个[App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx)的时候触发.
|
||||
典型的是键盘媒体或浏览器命令, Windows上的 "Back" 按钮用作鼠标也会触发.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
someWindow.on('app-command', function (e, cmd) {
|
||||
// Navigate the window back when the user hits their mouse back button
|
||||
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
||||
|
|
|
@ -9,7 +9,7 @@ var desktopCapturer = require('electron').desktopCapturer
|
|||
desktopCapturer.getSources({types: ['window', 'screen']}, function (error, sources) {
|
||||
if (error) throw error
|
||||
for (var i = 0; i < sources.length; ++i) {
|
||||
if (sources[i].name == 'Electron') {
|
||||
if (sources[i].name === 'Electron') {
|
||||
navigator.webkitGetUserMedia({
|
||||
audio: false,
|
||||
video: {
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
对话框例子,展示了选择文件和目录:
|
||||
|
||||
```javascript
|
||||
var win = ...; // BrowserWindow in which to show the dialog
|
||||
const dialog = require('electron').dialog;
|
||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
||||
const {dialog} = require('electron')
|
||||
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}))
|
||||
```
|
||||
|
||||
**macOS 上的注意事项**: 如果你想像sheets一样展示对话框,只需要在`browserWindow` 参数中提供一个 `BrowserWindow` 的引用对象.
|
||||
|
|
|
@ -6,22 +6,31 @@
|
|||
|
||||
```javascript
|
||||
// In the main process.
|
||||
win.webContents.session.on('will-download', function(event, item, webContents) {
|
||||
const {BrowserWindow} = require('electron')
|
||||
let win = new BrowserWindow()
|
||||
win.webContents.session.on('will-download', (event, item, webContents) => {
|
||||
// Set the save path, making Electron not to prompt a save dialog.
|
||||
item.setSavePath('/tmp/save.pdf');
|
||||
console.log(item.getMimeType());
|
||||
console.log(item.getFilename());
|
||||
console.log(item.getTotalBytes());
|
||||
item.on('updated', function() {
|
||||
console.log('Received bytes: ' + item.getReceivedBytes());
|
||||
});
|
||||
item.on('done', function(e, state) {
|
||||
if (state == "completed") {
|
||||
console.log("Download successfully");
|
||||
} else {
|
||||
console.log("Download is cancelled or interrupted that can't be resumed");
|
||||
item.setSavePath('/tmp/save.pdf')
|
||||
|
||||
item.on('updated', (event, state) => {
|
||||
if (state === 'interrupted') {
|
||||
console.log('Download is interrupted but can be resumed')
|
||||
} else if (state === 'progressing') {
|
||||
if (item.isPaused()) {
|
||||
console.log('Download is paused')
|
||||
} else {
|
||||
console.log(`Received bytes: ${item.getReceivedBytes()}`)
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
item.once('done', (event, state) => {
|
||||
if (state === 'completed') {
|
||||
console.log('Download successfully')
|
||||
} else {
|
||||
console.log(`Download failed: ${state}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
## 事件
|
||||
|
|
|
@ -77,34 +77,29 @@ var template = [
|
|||
label: 'Reload',
|
||||
accelerator: 'CmdOrCtrl+R',
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.reload()
|
||||
if (focusedWindow) focusedWindow.reload()
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Full Screen',
|
||||
accelerator: (function () {
|
||||
if (process.platform == 'darwin')
|
||||
return 'Ctrl+Command+F'
|
||||
else
|
||||
return 'F11'
|
||||
return (process.platform === 'darwin') ? 'Ctrl+Command+F' : 'F11'
|
||||
})(),
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
||||
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: (function () {
|
||||
if (process.platform == 'darwin')
|
||||
if (process.platform === 'darwin') {
|
||||
return 'Alt+Command+I'
|
||||
else
|
||||
} else {
|
||||
return 'Ctrl+Shift+I'
|
||||
}
|
||||
})(),
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow)
|
||||
focusedWindow.toggleDevTools()
|
||||
if (focusedWindow) focusedWindow.toggleDevTools()
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -137,7 +132,7 @@ var template = [
|
|||
}
|
||||
]
|
||||
|
||||
if (process.platform == 'darwin') {
|
||||
if (process.platform === 'darwin') {
|
||||
var name = require('electron').remote.app.getName()
|
||||
template.unshift({
|
||||
label: name,
|
||||
|
|
|
@ -17,7 +17,7 @@ Electron 中的 `process` 对象 与 upstream node 中的有以下的不同点:
|
|||
|
||||
当node被完全关闭的时候,它可以被预加载脚本使用来添加(原文: removed)与node无关的全局符号来回退到全局范围:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// preload.js
|
||||
var _setImmediate = setImmediate
|
||||
var _clearImmediate = clearImmediate
|
||||
|
|
|
@ -5,18 +5,15 @@
|
|||
例子,使用一个与 `file://` 功能相似的协议 :
|
||||
|
||||
```javascript
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const {app, protocol} = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
app.on('ready', function () {
|
||||
var protocol = electron.protocol
|
||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
||||
var url = request.url.substr(7)
|
||||
callback({path: path.normalize(__dirname + '/' + url)})
|
||||
}, function (error) {
|
||||
if (error)
|
||||
console.error('Failed to register protocol')
|
||||
app.on('ready', () => {
|
||||
protocol.registerFileProtocol('atom', (request, callback) => {
|
||||
const url = request.url.substr(7)
|
||||
callback({path: path.normalize(`${__dirname}/${url}`)})
|
||||
}, (error) => {
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
@ -85,8 +82,7 @@ app.on('ready', function () {
|
|||
protocol.registerBufferProtocol('atom', function (request, callback) {
|
||||
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')})
|
||||
}, function (error) {
|
||||
if (error)
|
||||
console.error('Failed to register protocol')
|
||||
if (error) console.error('Failed to register protocol')
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ app.on('ready', function () {
|
|||
var displays = electronScreen.getAllDisplays()
|
||||
var externalDisplay = null
|
||||
for (var i in displays) {
|
||||
if (displays[i].bounds.x != 0 || displays[i].bounds.y != 0) {
|
||||
if (displays[i].bounds.x !== 0 || displays[i].bounds.y !== 0) {
|
||||
externalDisplay = displays[i]
|
||||
break
|
||||
}
|
||||
|
|
|
@ -77,11 +77,13 @@ session.defaultSession.on('will-download', function (event, item, webContents) {
|
|||
```javascript
|
||||
// 查询所有 cookies.
|
||||
session.defaultSession.cookies.get({}, function (error, cookies) {
|
||||
if (error) console.error(error)
|
||||
console.log(cookies)
|
||||
})
|
||||
|
||||
// 查询与指定 url 相关的所有 cookies.
|
||||
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (error, cookies) {
|
||||
if (error) console.error(error)
|
||||
console.log(cookies)
|
||||
})
|
||||
|
||||
|
@ -89,8 +91,7 @@ session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (e
|
|||
// may overwrite equivalent cookies if they exist.
|
||||
var cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
|
||||
session.defaultSession.cookies.set(cookie, function (error) {
|
||||
if (error)
|
||||
console.error(error)
|
||||
if (error) console.error(error)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -262,10 +263,7 @@ window.webContents.session.enableNetworkEmulation({offline: true})
|
|||
|
||||
```javascript
|
||||
myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert, callback) {
|
||||
if (hostname == 'github.com')
|
||||
callback(true)
|
||||
else
|
||||
callback(false)
|
||||
callback(hostname === 'github.com')
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -281,7 +279,7 @@ myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert,
|
|||
```javascript
|
||||
session.fromPartition(partition).setPermissionRequestHandler(function (webContents, permission, callback) {
|
||||
if (webContents.getURL() === host) {
|
||||
if (permission == 'notifications') {
|
||||
if (permission === 'notifications') {
|
||||
callback(false) // denied.
|
||||
return
|
||||
}
|
||||
|
|
|
@ -508,8 +508,7 @@ var currentURL = win.webContents.getURL()
|
|||
|
||||
```javascript
|
||||
webContents.on('found-in-page', function (event, result) {
|
||||
if (result.finalUpdate)
|
||||
webContents.stopFindInPage('clearSelection')
|
||||
if (result.finalUpdate) webContents.stopFindInPage('clearSelection')
|
||||
})
|
||||
|
||||
const requestId = webContents.findInPage('api')
|
||||
|
@ -577,8 +576,7 @@ win.webContents.on('did-finish-load', function () {
|
|||
win.webContents.printToPDF({}, function (error, data) {
|
||||
if (error) throw error
|
||||
fs.writeFile('/tmp/print.pdf', data, function (error) {
|
||||
if (error)
|
||||
throw error
|
||||
if (error) throw error
|
||||
console.log('Write PDF successfully.')
|
||||
})
|
||||
})
|
||||
|
@ -653,7 +651,7 @@ Toggles 开发者工具.
|
|||
var window = null
|
||||
app.on('ready', function () {
|
||||
window = new BrowserWindow({width: 800, height: 600})
|
||||
window.loadURL('file://' + __dirname + '/index.html')
|
||||
window.loadURL(`file://${__dirname}/index.html`)
|
||||
window.webContents.on('did-finish-load', function () {
|
||||
window.webContents.send('ping', 'whoooooooh!')
|
||||
})
|
||||
|
@ -666,8 +664,8 @@ app.on('ready', function () {
|
|||
<body>
|
||||
<script>
|
||||
require('electron').ipcRenderer.on('ping', function(event, message) {
|
||||
console.log(message); // Prints "whoooooooh!"
|
||||
});
|
||||
console.log(message) // Prints "whoooooooh!"
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -773,8 +771,7 @@ win.loadURL('https://github.com')
|
|||
|
||||
win.webContents.on('did-finish-load', function () {
|
||||
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', function (error) {
|
||||
if (!error)
|
||||
console.log('Save page successfully')
|
||||
if (!error) console.log('Save page successfully')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
@ -806,16 +803,17 @@ try {
|
|||
win.webContents.debugger.attach('1.1')
|
||||
} catch (err) {
|
||||
console.log('Debugger attach failed : ', err)
|
||||
};
|
||||
}
|
||||
|
||||
win.webContents.debugger.on('detach', function (event, reason) {
|
||||
console.log('Debugger detached due to : ', reason)
|
||||
})
|
||||
|
||||
win.webContents.debugger.on('message', function (event, method, params) {
|
||||
if (method == 'Network.requestWillBeSent') {
|
||||
if (params.request.url == 'https://www.github.com')
|
||||
if (method === 'Network.requestWillBeSent') {
|
||||
if (params.request.url === 'https://www.github.com') {
|
||||
win.webContents.debugger.detach()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -537,8 +537,7 @@ webview.addEventListener('console-message', function (e) {
|
|||
|
||||
```javascript
|
||||
webview.addEventListener('found-in-page', function (e) {
|
||||
if (e.result.finalUpdate)
|
||||
webview.stopFindInPage('keepSelection')
|
||||
if (e.result.finalUpdate) webview.stopFindInPage('keepSelection')
|
||||
})
|
||||
|
||||
const rquestId = webview.findInPage('test')
|
||||
|
|
|
@ -75,16 +75,18 @@ macOS 可以让开发者定制自己的菜单,通常会包含一些常用特
|
|||
![Dock menu of Terminal.app][6]
|
||||
|
||||
使用 `app.dock.setMenu` API 来设置你的菜单,这仅在 macOS 上可行:
|
||||
|
||||
```javascript
|
||||
var app = require('app')
|
||||
var Menu = require('menu')
|
||||
var dockMenu = Menu.buildFromTemplate([
|
||||
{ label: 'New Window', click: function () { console.log('New Window') } },
|
||||
{ label: 'New Window with Settings', submenu: [
|
||||
{ label: 'Basic' },
|
||||
{ label: 'Pro'}
|
||||
const {app, Menu} = require('electron')
|
||||
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
{label: 'New Window', click () { console.log('New Window') }},
|
||||
{label: 'New Window with Settings',
|
||||
submenu: [
|
||||
{label: 'Basic'},
|
||||
{label: 'Pro'}
|
||||
]},
|
||||
{ label: 'New Command...'}
|
||||
{label: 'New Command...'}
|
||||
])
|
||||
app.dock.setMenu(dockMenu)
|
||||
```
|
||||
|
@ -174,8 +176,8 @@ Unity DE 也具有同样的特性,在运行器上显示进度条。
|
|||
|
||||
给一个窗口设置进度条,你可以调用 [BrowserWindow.setProgressBar][15] API:
|
||||
```javascript
|
||||
var window = new BrowserWindow({...});
|
||||
window.setProgressBar(0.5);
|
||||
var window = new BrowserWindow()
|
||||
window.setProgressBar(0.5)
|
||||
```
|
||||
在 macOS,一个窗口可以设置它展示的文件,文件的图标可以出现在标题栏,当用户 Command-Click 或者 Control-Click 标题栏,文件路径弹窗将会出现。
|
||||
### 展示文件弹窗菜单:
|
||||
|
@ -183,9 +185,9 @@ window.setProgressBar(0.5);
|
|||
|
||||
你可以调用 [BrowserWindow.setRepresentedFilename][17] 和 [BrowserWindow.setDocumentEdited][18] APIs:
|
||||
```javascript
|
||||
var window = new BrowserWindow({...});
|
||||
window.setRepresentedFilename('/etc/passwd');
|
||||
window.setDocumentEdited(true);
|
||||
var window = new BrowserWindow()
|
||||
window.setRepresentedFilename('/etc/passwd')
|
||||
window.setDocumentEdited(true)
|
||||
```
|
||||
|
||||
[1]:https://camo.githubusercontent.com/3310597e01f138b1d687e07aa618c50908a88dec/687474703a2f2f692e6d73646e2e6d6963726f736f66742e636f6d2f64796e696d672f49433432303533382e706e67
|
||||
|
|
|
@ -10,7 +10,7 @@ const BrowserWindow = electron.BrowserWindow
|
|||
var onlineStatusWindow
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -45,7 +45,7 @@ const BrowserWindow = electron.BrowserWindow
|
|||
var onlineStatusWindow
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
|
||||
ipcMain.on('online-status-changed', function (event, status) {
|
||||
|
|
|
@ -30,7 +30,7 @@ your-app/
|
|||
└── index.html
|
||||
````
|
||||
`package.json `的格式和 Node 的完全一致,并且那个被 `main` 字段声明的脚本文件是你的应用的启动脚本,它运行在主进程上。你应用里的 `package.json` 看起来应该像:
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "your-app",
|
||||
"version" : "0.1.0",
|
||||
|
|
|
@ -34,7 +34,7 @@ app.on('ready', function () {
|
|||
'plugins': true
|
||||
}
|
||||
})
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
// Something else
|
||||
})
|
||||
```
|
||||
|
|
|
@ -12,7 +12,7 @@ var onlineStatusWindow
|
|||
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -50,7 +50,7 @@ var onlineStatusWindow
|
|||
|
||||
app.on('ready', function () {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL('file://' + __dirname + '/online-status.html')
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
})
|
||||
|
||||
ipc.on('online-status-changed', function (event, status) {
|
||||
|
|
|
@ -46,7 +46,7 @@ your-app/
|
|||
`package.json` 的格式與 Node 的模組完全一樣,並且有個腳本被指定為 `main` 是用來啟動你的應用程式,它運行在主行程上。
|
||||
你應用裡的 一個範例在你的 `package.json` 看起來可能像這樣:
|
||||
|
||||
```json
|
||||
```javascripton
|
||||
{
|
||||
"name" : "your-app",
|
||||
"version" : "0.1.0",
|
||||
|
@ -70,7 +70,7 @@ var mainWindow = null;
|
|||
app.on('window-all-closed', function() {
|
||||
// 在macOS 上,通常使用者在明確地按下 Cmd + Q 之前
|
||||
// 應用會保持活動狀態
|
||||
if (process.platform != 'darwin') {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
@ -82,7 +82,7 @@ app.on('ready', function() {
|
|||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||
|
||||
// 載入應用程式的 index.html
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||
|
||||
// 打開開發者工具
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
|
|
@ -31,7 +31,7 @@ app.on('ready', function () {
|
|||
'plugins': true
|
||||
}
|
||||
})
|
||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
// Something else
|
||||
})
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue