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
|
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:
|
de Node eliminados, al alcance global cuando la integración de Node está apagada:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
// preload.js
|
// preload.js
|
||||||
var _setImmediate = setImmediate
|
var _setImmediate = setImmediate
|
||||||
var _clearImmediate = clearImmediate
|
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 app = require('app')
|
||||||
var Menu = require('menu')
|
var Menu = require('menu')
|
||||||
var dockMenu = Menu.buildFromTemplate([
|
var dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click: function () { console.log('New Window') } },
|
{label: 'New Window', click: function () { console.log('New Window') }},
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{label: 'New Window with Settings',
|
||||||
{ label: 'Basic' },
|
submenu: [
|
||||||
{ label: 'Pro'}
|
{label: 'Basic'},
|
||||||
]},
|
{label: 'Pro'}
|
||||||
{ label: 'New Command...'}
|
]
|
||||||
|
},
|
||||||
|
{label: 'New Command...'}
|
||||||
])
|
])
|
||||||
app.dock.setMenu(dockMenu)
|
app.dock.setMenu(dockMenu)
|
||||||
```
|
```
|
||||||
|
@ -157,8 +159,8 @@ Para establecer la barra de progreso de una ventana, puedes utilizar
|
||||||
[BrowserWindow.setProgressBar][setprogressbar] API:
|
[BrowserWindow.setProgressBar][setprogressbar] API:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
var window = new BrowserWindow()
|
||||||
window.setProgressBar(0.5);
|
window.setProgressBar(0.5)
|
||||||
```
|
```
|
||||||
|
|
||||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath
|
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath
|
||||||
|
|
|
@ -12,7 +12,7 @@ var onlineStatusWindow
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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 () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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) {
|
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,
|
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í:
|
a ser ejecutado por el proceso principal. Un ejemplo de `package.json` podría verse así:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "your-app",
|
"name" : "your-app",
|
||||||
"version" : "0.1.0",
|
"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ú
|
// En macOS es común que las aplicaciones y su barra de menú
|
||||||
// se mantengan activas hasta que el usuario cierre la aplicación
|
// se mantengan activas hasta que el usuario cierre la aplicación
|
||||||
// explícitamente utilizando Cmd + Q
|
// explícitamente utilizando Cmd + Q
|
||||||
if (process.platform != 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -89,7 +89,7 @@ app.on('ready', function () {
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600})
|
mainWindow = new BrowserWindow({width: 800, height: 600})
|
||||||
|
|
||||||
// cargar el index.html de nuestra aplicación.
|
// cargar el index.html de nuestra aplicación.
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
|
|
||||||
// Desplegar devtools.
|
// Desplegar devtools.
|
||||||
mainWindow.openDevTools()
|
mainWindow.openDevTools()
|
||||||
|
|
|
@ -21,7 +21,7 @@ var mainWindow = null
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function () {
|
||||||
if (process.platform != 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -43,7 +43,7 @@ app.on('ready', function () {
|
||||||
'plugins': true
|
'plugins': true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
// Something else
|
// Something else
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -135,7 +135,7 @@ Windowsでは、ファイルパスを取得するために、 `process.argv` を
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
||||||
if (url == 'https://github.com') {
|
if (url === 'https://github.com') {
|
||||||
// Verification logic.
|
// Verification logic.
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
callback(true)
|
callback(true)
|
||||||
|
@ -325,26 +325,25 @@ macOSは、ユーザーがFinderで2つ目のアプリインスタンスを開
|
||||||
|
|
||||||
2つ目のインスタンスを起動するとき、メインのインスタンスのウィンドウをアクティブにする例
|
2つ目のインスタンスを起動するとき、メインのインスタンスのウィンドウをアクティブにする例
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
var myWindow = null;
|
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
|
// Someone tried to run a second instance, we should focus our window
|
||||||
if (myWindow) {
|
if (myWindow) {
|
||||||
if (myWindow.isMinimized()) myWindow.restore();
|
if (myWindow.isMinimized()) myWindow.restore()
|
||||||
myWindow.focus();
|
myWindow.focus()
|
||||||
}
|
}
|
||||||
return true;
|
return true
|
||||||
});
|
})
|
||||||
|
|
||||||
if (shouldQuit) {
|
if (shouldQuit) {
|
||||||
app.quit();
|
app.quit()
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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_
|
### `app.setAppUserModelId(id)` _Windows_
|
||||||
|
@ -359,7 +358,7 @@ app.on('ready', function() {
|
||||||
|
|
||||||
使用例:
|
使用例:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
let browserOptions = {width: 1000, height: 800}
|
let browserOptions = {width: 1000, height: 800}
|
||||||
|
|
||||||
// Make the window transparent only if the platform supports it.
|
// Make the window transparent only if the platform supports it.
|
||||||
|
@ -373,10 +372,10 @@ win = new BrowserWindow(browserOptions)
|
||||||
|
|
||||||
// Navigate.
|
// Navigate.
|
||||||
if (browserOptions.transparent) {
|
if (browserOptions.transparent) {
|
||||||
win.loadURL('file://' + __dirname + '/index.html')
|
win.loadURL(`file://${__dirname}/index.html`)
|
||||||
} else {
|
} else {
|
||||||
// No transparency, so we load a fallback that uses basic styles.
|
// 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) {
|
desktopCapturer.getSources({types: ['window', 'screen']}, function (error, sources) {
|
||||||
if (error) throw error
|
if (error) throw error
|
||||||
for (var i = 0; i < sources.length; ++i) {
|
for (var i = 0; i < sources.length; ++i) {
|
||||||
if (sources[i].name == 'Electron') {
|
if (sources[i].name === 'Electron') {
|
||||||
navigator.webkitGetUserMedia({
|
navigator.webkitGetUserMedia({
|
||||||
audio: false,
|
audio: false,
|
||||||
video: {
|
video: {
|
||||||
|
|
|
@ -5,9 +5,8 @@
|
||||||
複数のファイルやディレクトリを選択するためのダイアログを表示する例です:
|
複数のファイルやディレクトリを選択するためのダイアログを表示する例です:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = ...; // BrowserWindow in which to show the dialog
|
const {dialog} = require('electron')
|
||||||
const dialog = require('electron').dialog;
|
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}))
|
||||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note for macOS**: シートとしてダイアログを表示したい場合、唯一しなければならないことは、`browserWindow`パラメーターを参照する`BrowserWindow`を提供することです。
|
**Note for macOS**: シートとしてダイアログを表示したい場合、唯一しなければならないことは、`browserWindow`パラメーターを参照する`BrowserWindow`を提供することです。
|
||||||
|
|
|
@ -4,22 +4,31 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// 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.
|
// Set the save path, making Electron not to prompt a save dialog.
|
||||||
item.setSavePath('/tmp/save.pdf');
|
item.setSavePath('/tmp/save.pdf')
|
||||||
console.log(item.getMimeType());
|
|
||||||
console.log(item.getFilename());
|
item.on('updated', (event, state) => {
|
||||||
console.log(item.getTotalBytes());
|
if (state === 'interrupted') {
|
||||||
item.on('updated', function() {
|
console.log('Download is interrupted but can be resumed')
|
||||||
console.log('Received bytes: ' + item.getReceivedBytes());
|
} else if (state === 'progressing') {
|
||||||
});
|
if (item.isPaused()) {
|
||||||
item.on('done', function(e, state) {
|
console.log('Download is paused')
|
||||||
if (state == "completed") {
|
} else {
|
||||||
console.log("Download successfully");
|
console.log(`Received bytes: ${item.getReceivedBytes()}`)
|
||||||
} else {
|
}
|
||||||
console.log("Download is cancelled or interrupted that can't be resumed");
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
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',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: function (item, focusedWindow) {
|
click: function (item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.reload()
|
||||||
focusedWindow.reload()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: (function () {
|
accelerator: (function () {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform === 'darwin') {
|
||||||
return 'Ctrl+Command+F'
|
return 'Ctrl+Command+F'
|
||||||
else
|
} else {
|
||||||
return 'F11'
|
return 'F11'
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click: function (item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow) {
|
||||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: (function () {
|
accelerator: (function () {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform === 'darwin') {
|
||||||
return 'Alt+Command+I'
|
return 'Alt+Command+I'
|
||||||
else
|
} else {
|
||||||
return 'Ctrl+Shift+I'
|
return 'Ctrl+Shift+I'
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click: function (item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.toggleDevTools()
|
||||||
focusedWindow.toggleDevTools()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -134,7 +135,7 @@ var template = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
var name = require('electron').remote.app.getName()
|
var name = require('electron').remote.app.getName()
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: name,
|
label: name,
|
||||||
|
|
|
@ -12,7 +12,7 @@ Electronの`process`オブジェクトは次のようなAPIで拡張されてい
|
||||||
|
|
||||||
Node統合がオフになっているとき、削除したNodeグローバルシンボルをグローバルスコープへ戻すために、プリロードスクリプトで使用できます。
|
Node統合がオフになっているとき、削除したNodeグローバルシンボルをグローバルスコープへ戻すために、プリロードスクリプトで使用できます。
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
// preload.js
|
// preload.js
|
||||||
var _setImmediate = setImmediate
|
var _setImmediate = setImmediate
|
||||||
var _clearImmediate = clearImmediate
|
var _clearImmediate = clearImmediate
|
||||||
|
|
|
@ -5,18 +5,16 @@
|
||||||
`file://`プロトコルの同様の効果をもつプロトコルを実装した例です。
|
`file://`プロトコルの同様の効果をもつプロトコルを実装した例です。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron')
|
const {app} = require('electron')
|
||||||
const app = electron.app
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
var protocol = electron.protocol
|
var protocol = electron.protocol
|
||||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
protocol.registerFileProtocol('atom', function (request, callback) {
|
||||||
var url = request.url.substr(7)
|
var url = request.url.substr(7)
|
||||||
callback({path: path.normalize(__dirname + '/' + url)})
|
callback({path: path.join(__dirname, url)})
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
if (error)
|
if (error) console.error('Failed to register protocol')
|
||||||
console.error('Failed to register protocol')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -80,8 +78,7 @@ app.on('ready', function () {
|
||||||
protocol.registerBufferProtocol('atom', function (request, callback) {
|
protocol.registerBufferProtocol('atom', function (request, callback) {
|
||||||
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')})
|
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')})
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
if (error)
|
if (error) console.error('Failed to register protocol')
|
||||||
console.error('Failed to register protocol')
|
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ app.on('ready', function () {
|
||||||
var displays = electronScreen.getAllDisplays()
|
var displays = electronScreen.getAllDisplays()
|
||||||
var externalDisplay = null
|
var externalDisplay = null
|
||||||
for (var i in displays) {
|
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]
|
externalDisplay = displays[i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,11 +77,13 @@ session.defaultSession.on('will-download', function (event, item, webContents) {
|
||||||
```javascript
|
```javascript
|
||||||
// Query all cookies.
|
// Query all cookies.
|
||||||
session.defaultSession.cookies.get({}, function (error, cookies) {
|
session.defaultSession.cookies.get({}, function (error, cookies) {
|
||||||
|
if (error) console.error(error)
|
||||||
console.log(cookies)
|
console.log(cookies)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Query all cookies associated with a specific url.
|
// Query all cookies associated with a specific url.
|
||||||
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (error, cookies) {
|
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (error, cookies) {
|
||||||
|
if (error) console.error(error)
|
||||||
console.log(cookies)
|
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.
|
// may overwrite equivalent cookies if they exist.
|
||||||
var cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
|
var cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
|
||||||
session.defaultSession.cookies.set(cookie, function (error) {
|
session.defaultSession.cookies.set(cookie, function (error) {
|
||||||
if (error)
|
if (error) console.error(error)
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -255,10 +256,7 @@ Calling `setCertificateVerifyProc(null)`をコールして、既定の証明書
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert, callback) {
|
myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert, callback) {
|
||||||
if (hostname == 'github.com')
|
callback(hostname === 'github.com')
|
||||||
callback(true)
|
|
||||||
else
|
|
||||||
callback(false)
|
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ webview.addEventListener('dom-ready', () => {
|
||||||
|
|
||||||
* `url` URL
|
* `url` URL
|
||||||
* `options` Object (optional)
|
* `options` Object (optional)
|
||||||
* `httpReferrer` String - リファラURL
|
* `httpReferrer` String - リファラURL
|
||||||
* `userAgent` String - リクエストに使用されるUser agent
|
* `userAgent` String - リクエストに使用されるUser agent
|
||||||
* `extraHeaders` String - 追加のヘッダを"\n"で区切って指定します。
|
* `extraHeaders` String - 追加のヘッダを"\n"で区切って指定します。
|
||||||
|
|
||||||
|
@ -577,8 +577,7 @@ webview.addEventListener('console-message', (e) => {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('found-in-page', (e) => {
|
webview.addEventListener('found-in-page', (e) => {
|
||||||
if (e.result.finalUpdate)
|
if (e.result.finalUpdate) webview.stopFindInPage('keepSelection')
|
||||||
webview.stopFindInPage('keepSelection')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const requestId = webview.findInPage('test')
|
const requestId = webview.findInPage('test')
|
||||||
|
|
|
@ -87,21 +87,21 @@ __Dock menu of Terminal.app:__
|
||||||
カスタムドックメニューを設定するために、macOSのみに提供されている `app.dock.setMenu` APIを使用できます。
|
カスタムドックメニューを設定するために、macOSのみに提供されている `app.dock.setMenu` APIを使用できます。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron')
|
const {app, Menu} = require('electron')
|
||||||
const app = electron.app
|
|
||||||
const Menu = electron.Menu
|
|
||||||
|
|
||||||
const dockMenu = Menu.buildFromTemplate([
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click () { console.log('New Window') } },
|
{label: 'New Window', click () { console.log('New Window') }},
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{label: 'New Window with Settings',
|
||||||
{ label: 'Basic' },
|
submenu: [
|
||||||
{ label: 'Pro'}
|
{label: 'Basic'},
|
||||||
|
{label: 'Pro'}
|
||||||
]},
|
]},
|
||||||
{ label: 'New Command...'}
|
{label: 'New Command...'}
|
||||||
])
|
])
|
||||||
app.dock.setMenu(dockMenu)
|
app.dock.setMenu(dockMenu)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## ユーザータスク (Windows)
|
## ユーザータスク (Windows)
|
||||||
|
|
||||||
Windowsでは、ジャンプリストの `Tasks` カテゴリでカスタムアクションを指定できます。
|
Windowsでは、ジャンプリストの `Tasks` カテゴリでカスタムアクションを指定できます。
|
||||||
|
@ -206,8 +206,8 @@ __タスクバーボタン上の進行状況バー:__
|
||||||
ウィンドウに進行状況バーを設定するために、[BrowserWindow.setProgressBar][setprogressbar] APIを使えます:
|
ウィンドウに進行状況バーを設定するために、[BrowserWindow.setProgressBar][setprogressbar] APIを使えます:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let win = new BrowserWindow({...});
|
let win = new BrowserWindow()
|
||||||
win.setProgressBar(0.5);
|
win.setProgressBar(0.5)
|
||||||
```
|
```
|
||||||
|
|
||||||
## タスクバーでアイコンをオーバーレイする (Windows)
|
## タスクバーでアイコンをオーバーレイする (Windows)
|
||||||
|
@ -223,8 +223,8 @@ __タスクバーボタンでのオーバーレイ:__
|
||||||
ウィンドウでオーバーレイアイコンを設定するために、[BrowserWindow.setOverlayIcon][setoverlayicon] APIを使用できます。
|
ウィンドウでオーバーレイアイコンを設定するために、[BrowserWindow.setOverlayIcon][setoverlayicon] APIを使用できます。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let win = new BrowserWindow({...});
|
let win = new BrowserWindow()
|
||||||
win.setOverlayIcon('path/to/overlay.png', 'Description for overlay');
|
win.setOverlayIcon('path/to/overlay.png', 'Description for overlay')
|
||||||
```
|
```
|
||||||
|
|
||||||
## Windowのファイル表示 (macOS)
|
## Windowのファイル表示 (macOS)
|
||||||
|
@ -240,9 +240,9 @@ __Represented file ポップアップメニュー:__
|
||||||
ウィンドウにrepresented fileを設定するために、[BrowserWindow.setRepresentedFilename][setrepresentedfilename] と [BrowserWindow.setDocumentEdited][setdocumentedited] APIsを使えます:
|
ウィンドウにrepresented fileを設定するために、[BrowserWindow.setRepresentedFilename][setrepresentedfilename] と [BrowserWindow.setDocumentEdited][setdocumentedited] APIsを使えます:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let win = new BrowserWindow({...});
|
let win = new BrowserWindow()
|
||||||
win.setRepresentedFilename('/etc/passwd');
|
win.setRepresentedFilename('/etc/passwd')
|
||||||
win.setDocumentEdited(true);
|
win.setDocumentEdited(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows
|
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows
|
||||||
|
|
|
@ -39,7 +39,7 @@ your-app/
|
||||||
|
|
||||||
`package.json` の形式は Node モジュールとまったく同じです。 `main` フィールドで指定するスクリプトはアプリの起動スクリプトであり、メインプロセスを実行します。 `package.json` の例は次のようになります:
|
`package.json` の形式は Node モジュールとまったく同じです。 `main` フィールドで指定するスクリプトはアプリの起動スクリプトであり、メインプロセスを実行します。 `package.json` の例は次のようになります:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "your-app",
|
"name" : "your-app",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.0",
|
||||||
|
@ -74,8 +74,8 @@ function createWindow () {
|
||||||
|
|
||||||
// ウィンドウが閉じられた時に発行される
|
// ウィンドウが閉じられた時に発行される
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
// ウィンドウオブジェクトを参照から外す。
|
// ウィンドウオブジェクトを参照から外す。
|
||||||
// もし何個かウィンドウがあるならば、配列として持っておいて、対応するウィンドウのオブジェクトを消去するべき。
|
// もし何個かウィンドウがあるならば、配列として持っておいて、対応するウィンドウのオブジェクトを消去するべき。
|
||||||
win = null
|
win = null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ app.on('ready', function () {
|
||||||
'plugins': true
|
'plugins': true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
// Something else
|
// Something else
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -15,7 +15,7 @@ Electronで `chromedriver` を使用するために、Electronがどこにある
|
||||||
$ npm install --save-dev spectron
|
$ npm install --save-dev spectron
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
// 可視のウィンドウがタイトル付きで開かれているかを調べる簡単なテスト
|
// 可視のウィンドウがタイトル付きで開かれているかを調べる簡単なテスト
|
||||||
var Application = require('spectron').Application
|
var Application = require('spectron').Application
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
|
|
|
@ -645,15 +645,21 @@ app.setJumpList([
|
||||||
name: 'Tools',
|
name: 'Tools',
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'task', title: 'Tool A',
|
type: 'task',
|
||||||
program: process.execPath, args: '--run-tool-a',
|
title: 'Tool A',
|
||||||
icon: process.execPath, iconIndex: 0,
|
program: process.execPath,
|
||||||
|
args: '--run-tool-a',
|
||||||
|
icon: process.execPath,
|
||||||
|
iconIndex: 0,
|
||||||
description: 'Runs Tool A'
|
description: 'Runs Tool A'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'task', title: 'Tool B',
|
type: 'task',
|
||||||
program: process.execPath, args: '--run-tool-b',
|
title: 'Tool B',
|
||||||
icon: process.execPath, iconIndex: 0,
|
program: process.execPath,
|
||||||
|
args: '--run-tool-b',
|
||||||
|
icon: process.execPath,
|
||||||
|
iconIndex: 0,
|
||||||
description: 'Runs Tool B'
|
description: 'Runs Tool B'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -662,14 +668,18 @@ app.setJumpList([
|
||||||
{ // has no name and no type so `type` is assumed to be "tasks"
|
{ // has no name and no type so `type` is assumed to be "tasks"
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'task', title: 'New Project',
|
type: 'task',
|
||||||
program: process.execPath, args: '--new-project',
|
title: 'New Project',
|
||||||
|
program: process.execPath,
|
||||||
|
args: '--new-project',
|
||||||
description: 'Create a new project.'
|
description: 'Create a new project.'
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
type: 'task', title: 'Recover Project',
|
type: 'task',
|
||||||
program: process.execPath, args: '--recover-project',
|
title: 'Recover Project',
|
||||||
|
program: process.execPath,
|
||||||
|
args: '--recover-project',
|
||||||
description: 'Recover Project'
|
description: 'Recover Project'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -97,7 +97,7 @@ Returns `Object`:
|
||||||
**참고:** 윈도우의 대부분의 앱은 북마크 붙여넣기를 지원하지 않습니다.
|
**참고:** 윈도우의 대부분의 앱은 북마크 붙여넣기를 지원하지 않습니다.
|
||||||
`clipboard.write` 를 통해 북마크와 대체 텍스트를 클립보드에 쓸 수 있습니다.
|
`clipboard.write` 를 통해 북마크와 대체 텍스트를 클립보드에 쓸 수 있습니다.
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
clipboard.write({
|
clipboard.write({
|
||||||
text: 'http://electron.atom.io',
|
text: 'http://electron.atom.io',
|
||||||
bookmark: 'Electron Homepage'
|
bookmark: 'Electron Homepage'
|
||||||
|
|
|
@ -147,7 +147,7 @@ if (browserOptions.transparent) {
|
||||||
|
|
||||||
사용자의 현재 시스템 전체 색상 환경설정을 RGBA 16진 문자열 형태로 반환합니다.
|
사용자의 현재 시스템 전체 색상 환경설정을 RGBA 16진 문자열 형태로 반환합니다.
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
const color = systemPreferences.getAccentColor() // `"aabbccdd"`
|
const color = systemPreferences.getAccentColor() // `"aabbccdd"`
|
||||||
const red = color.substr(0, 2) // "aa"
|
const red = color.substr(0, 2) // "aa"
|
||||||
const green = color.substr(2, 2) // "bb"
|
const green = color.substr(2, 2) // "bb"
|
||||||
|
|
|
@ -9,7 +9,7 @@ $ code electron-quick-start
|
||||||
|
|
||||||
### 2. 다음 설정으로 `.vscode/launch.json` 파일 추가하기:
|
### 2. 다음 설정으로 `.vscode/launch.json` 파일 추가하기:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
|
@ -116,7 +116,8 @@ const {app, Menu} = require('electron')
|
||||||
|
|
||||||
const dockMenu = Menu.buildFromTemplate([
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
{label: 'New Window', click () { console.log('New Window') }},
|
{label: 'New Window', click () { console.log('New Window') }},
|
||||||
{label: 'New Window with Settings', submenu: [
|
{label: 'New Window with Settings',
|
||||||
|
submenu: [
|
||||||
{label: 'Basic'},
|
{label: 'Basic'},
|
||||||
{label: 'Pro'}
|
{label: 'Pro'}
|
||||||
]},
|
]},
|
||||||
|
|
|
@ -61,7 +61,7 @@ your-app/
|
||||||
파일을 지정하면 메인 프로세스의 엔트리 포인트로 사용합니다. 예를 들어 사용할 수 있는
|
파일을 지정하면 메인 프로세스의 엔트리 포인트로 사용합니다. 예를 들어 사용할 수 있는
|
||||||
`package.json`은 다음과 같습니다:
|
`package.json`은 다음과 같습니다:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "your-app",
|
"name" : "your-app",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.0",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
O módulo `app` é responsável por controlar o ciclo de vida do aplicativo.
|
O módulo `app` é responsável por controlar o ciclo de vida do aplicativo.
|
||||||
|
|
||||||
O exemplo a seguir mostra como fechar o aplicativo quando a última janela é fechada:
|
O exemplo a seguir mostra como fechar o aplicativo quando a última janela é fechada:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const app = require('electron').app
|
const app = require('electron').app
|
||||||
|
@ -153,7 +153,7 @@ para confiar no certificado, você deve impedir o comportamento padrão com
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
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.
|
// Lógica de verificação.
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
callback(true)
|
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:
|
Um exemplo de ativação da janela de primeira instância quando uma segunda instância inicializa:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
var myWindow = null;
|
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
|
// Alguém tentou rodar uma segunda instância, devemos focar nossa janela
|
||||||
if (myWindow) {
|
if (myWindow) {
|
||||||
if (myWindow.isMinimized()) myWindow.restore();
|
if (myWindow.isMinimized()) myWindow.restore()
|
||||||
myWindow.focus();
|
myWindow.focus()
|
||||||
}
|
}
|
||||||
return true;
|
return true
|
||||||
});
|
})
|
||||||
|
|
||||||
if (shouldQuit) {
|
if (shouldQuit) app.quit()
|
||||||
app.quit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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_
|
### `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.
|
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) {
|
someWindow.on('app-command', function (e, cmd) {
|
||||||
// Navega a janela 'para trás' quando o usuário pressiona o botão voltar do mouse
|
// Navega a janela 'para trás' quando o usuário pressiona o botão voltar do mouse
|
||||||
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
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:
|
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
|
// preload.js
|
||||||
var _setImmediate = setImmediate
|
var _setImmediate = setImmediate
|
||||||
var _clearImmediate = clearImmediate
|
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:
|
ela está disponível apenas no macOS:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app')
|
const {app, Menu} = require('electron')
|
||||||
var Menu = require('menu')
|
|
||||||
var dockMenu = Menu.buildFromTemplate([
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click: function () { console.log('New Window') } },
|
{label: 'New Window', click () { console.log('New Window') }},
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{label: 'New Window with Settings',
|
||||||
{ label: 'Basic' },
|
submenu: [
|
||||||
{ label: 'Pro'}
|
{label: 'Basic'},
|
||||||
|
{label: 'Pro'}
|
||||||
]},
|
]},
|
||||||
{ label: 'New Command...'}
|
{label: 'New Command...'}
|
||||||
])
|
])
|
||||||
app.dock.setMenu(dockMenu)
|
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
|
Você pode usar [BrowserWindow.setThumbarButtons][setthumbarbuttons] para criar
|
||||||
miniaturas na barra de ferramentas para sua aplicação.
|
miniaturas na barra de ferramentas para sua aplicação.
|
||||||
|
|
||||||
```
|
```javascript
|
||||||
var BrowserWindow = require('browser-window');
|
var BrowserWindow = require('browser-window')
|
||||||
var path = require('path');
|
var path = require('path')
|
||||||
var win = new BrowserWindow({
|
var win = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600
|
height: 600
|
||||||
});
|
})
|
||||||
win.setThumbarButtons([
|
win.setThumbarButtons([
|
||||||
{
|
{
|
||||||
tooltip: "button1",
|
tooltip: 'button1',
|
||||||
icon: path.join(__dirname, 'button1.png'),
|
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'),
|
icon: path.join(__dirname, 'button2.png'),
|
||||||
flags:['enabled', 'dismissonclick'],
|
flags: ['enabled', 'dismissonclick'],
|
||||||
click: function() { console.log("button2 clicked."); }
|
click: function () { console.log('button2 clicked.') }
|
||||||
}
|
}
|
||||||
]);
|
])
|
||||||
```
|
```
|
||||||
|
|
||||||
Para limpar os botões na miniatura da barra de ferramentas, apenas chame
|
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]:
|
[BrowserWindow.setProgressBar][setprogressbar]:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
var window = new BrowserWindow()
|
||||||
window.setProgressBar(0.5);
|
window.setProgressBar(0.5)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Representação do arquivo na janela (macOS)
|
## 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]:
|
[BrowserWindow.setDocumentEdited][setdocumentedited]:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
var window = new BrowserWindow()
|
||||||
window.setRepresentedFilename('/etc/passwd');
|
window.setRepresentedFilename('/etc/passwd')
|
||||||
window.setDocumentEdited(true);
|
window.setDocumentEdited(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath
|
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath
|
||||||
|
|
|
@ -13,7 +13,7 @@ var onlineStatusWindow
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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 () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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) {
|
ipc.on('online-status-changed', function (event, status) {
|
||||||
|
@ -66,18 +66,18 @@ _online-status.html_
|
||||||
```html
|
```html
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var ipc = require('ipc');
|
const {ipcRenderer} = require('electron')
|
||||||
var updateOnlineStatus = function() {
|
const updateOnlineStatus = () => {
|
||||||
ipc.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
|
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline')
|
||||||
};
|
}
|
||||||
|
|
||||||
window.addEventListener('online', updateOnlineStatus);
|
window.addEventListener('online', updateOnlineStatus)
|
||||||
window.addEventListener('offline', updateOnlineStatus);
|
window.addEventListener('offline', updateOnlineStatus)
|
||||||
|
|
||||||
updateOnlineStatus();
|
updateOnlineStatus()
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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
|
que irá executar o processo principal. Um exemplo do seu `package.json` deve parecer
|
||||||
com isso:
|
com isso:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "seu-app",
|
"name" : "seu-app",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.0",
|
||||||
|
|
|
@ -20,18 +20,15 @@ para a linha de comando do Electron ou usando o método
|
||||||
Por exemplo:
|
Por exemplo:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app')
|
const {app, BrowserWindow} = require('electron')
|
||||||
var BrowserWindow = require('browser-window')
|
|
||||||
|
|
||||||
// Mantém uma referência global da janela, se não manter, a janela irá fechar
|
// Mantém uma referência global da janela, se não manter, a janela irá fechar
|
||||||
// automaticamente quando o objeto javascript for GCed.
|
// automaticamente quando o objeto javascript for GCed.
|
||||||
var mainWindow = null
|
let mainWindow = null
|
||||||
|
|
||||||
// Sai assim que todas as janelas forem fechadas.
|
// Sai assim que todas as janelas forem fechadas.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function () {
|
||||||
if (process.platform != 'darwin') {
|
if (process.platform !== 'darwin') app.quit()
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Epecifica o caminho do flash.
|
// Epecifica o caminho do flash.
|
||||||
|
@ -51,7 +48,7 @@ app.on('ready', function () {
|
||||||
'plugins': true
|
'plugins': true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
// Algo mais
|
// Algo mais
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -60,7 +60,7 @@ your-app/
|
||||||
как `main`, будет выполняться при запуске вашего приложения, работая в
|
как `main`, будет выполняться при запуске вашего приложения, работая в
|
||||||
главном процессе. Например, Ваш `package.json` может выглядеть вот так:
|
главном процессе. Например, Ваш `package.json` может выглядеть вот так:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "your-app",
|
"name" : "your-app",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.0",
|
||||||
|
@ -91,7 +91,7 @@ function createWindow () {
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600})
|
mainWindow = new BrowserWindow({width: 800, height: 600})
|
||||||
|
|
||||||
// и загружаем index.html приложения.
|
// и загружаем index.html приложения.
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
|
|
||||||
// Открываем DevTools.
|
// Открываем DevTools.
|
||||||
mainWindow.webContents.openDevTools()
|
mainWindow.webContents.openDevTools()
|
||||||
|
|
|
@ -144,7 +144,7 @@ app.on('window-all-closed', function () {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
session.on('certificate-error', function (event, webContents, url, error, certificate, callback) {
|
||||||
if (url == 'https://github.com') {
|
if (url === 'https://github.com') {
|
||||||
// 验证逻辑。
|
// 验证逻辑。
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
callback(true)
|
callback(true)
|
||||||
|
@ -363,29 +363,26 @@ app.on('login', function (event, webContents, request, authInfo, callback) {
|
||||||
|
|
||||||
下面是一个简单的例子。我们可以通过这个例子了解如何确保应用为单实例运行状态。
|
下面是一个简单的例子。我们可以通过这个例子了解如何确保应用为单实例运行状态。
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
var myWindow = null;
|
let myWindow = null
|
||||||
|
|
||||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
let shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
|
||||||
// 当另一个实例运行的时候,这里将会被调用,我们需要激活应用的窗口
|
// 当另一个实例运行的时候,这里将会被调用,我们需要激活应用的窗口
|
||||||
if (myWindow) {
|
if (myWindow) {
|
||||||
if (myWindow.isMinimized()) myWindow.restore();
|
if (myWindow.isMinimized()) myWindow.restore()
|
||||||
myWindow.focus();
|
myWindow.focus()
|
||||||
}
|
}
|
||||||
return true;
|
return true
|
||||||
});
|
})
|
||||||
|
|
||||||
// 这个实例是多余的实例,需要退出
|
// 这个实例是多余的实例,需要退出
|
||||||
if (shouldQuit) {
|
if (shouldQuit) app.quit()
|
||||||
app.quit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建窗口、继续加载应用、应用逻辑等……
|
|
||||||
app.on('ready', function() {
|
|
||||||
});
|
|
||||||
|
|
||||||
|
app.on('ready', function () {
|
||||||
|
// 创建窗口、继续加载应用、应用逻辑等……
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### `app.setAppUserModelId(id)` _Windows_
|
### `app.setAppUserModelId(id)` _Windows_
|
||||||
|
|
||||||
* `id` String
|
* `id` String
|
||||||
|
@ -400,7 +397,7 @@ app.on('ready', function() {
|
||||||
|
|
||||||
举个例子:
|
举个例子:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
let browserOptions = {width: 1000, height: 800}
|
let browserOptions = {width: 1000, height: 800}
|
||||||
|
|
||||||
// 只有平台支持的时候才使用透明窗口
|
// 只有平台支持的时候才使用透明窗口
|
||||||
|
@ -414,10 +411,10 @@ win = new BrowserWindow(browserOptions)
|
||||||
|
|
||||||
// 转到某个网页
|
// 转到某个网页
|
||||||
if (browserOptions.transparent) {
|
if (browserOptions.transparent) {
|
||||||
win.loadURL('file://' + __dirname + '/index.html')
|
win.loadURL(`file://${__dirname}/index.html`)
|
||||||
} else {
|
} else {
|
||||||
// 没有透明特效,我们应该用某个只包含基本样式的替代解决方案。
|
// 没有透明特效,我们应该用某个只包含基本样式的替代解决方案。
|
||||||
win.loadURL('file://' + __dirname + '/fallback.html')
|
win.loadURL(`file://${__dirname}/fallback.html`)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### `app.commandLine.appendSwitch(switch[, value])`
|
### `app.commandLine.appendSwitch(switch[, value])`
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
const BrowserWindow = require('electron').BrowserWindow
|
const BrowserWindow = require('electron').BrowserWindow
|
||||||
|
|
||||||
// Or in the renderer process.
|
// 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 })
|
var win = new BrowserWindow({ width: 800, height: 600, show: false })
|
||||||
win.on('closed', function () {
|
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)的时候触发.
|
在请求一个[App Command](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx)的时候触发.
|
||||||
典型的是键盘媒体或浏览器命令, Windows上的 "Back" 按钮用作鼠标也会触发.
|
典型的是键盘媒体或浏览器命令, Windows上的 "Back" 按钮用作鼠标也会触发.
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
someWindow.on('app-command', function (e, cmd) {
|
someWindow.on('app-command', function (e, cmd) {
|
||||||
// Navigate the window back when the user hits their mouse back button
|
// Navigate the window back when the user hits their mouse back button
|
||||||
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
if (cmd === 'browser-backward' && someWindow.webContents.canGoBack()) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ var desktopCapturer = require('electron').desktopCapturer
|
||||||
desktopCapturer.getSources({types: ['window', 'screen']}, function (error, sources) {
|
desktopCapturer.getSources({types: ['window', 'screen']}, function (error, sources) {
|
||||||
if (error) throw error
|
if (error) throw error
|
||||||
for (var i = 0; i < sources.length; ++i) {
|
for (var i = 0; i < sources.length; ++i) {
|
||||||
if (sources[i].name == 'Electron') {
|
if (sources[i].name === 'Electron') {
|
||||||
navigator.webkitGetUserMedia({
|
navigator.webkitGetUserMedia({
|
||||||
audio: false,
|
audio: false,
|
||||||
video: {
|
video: {
|
||||||
|
@ -61,4 +61,4 @@ function getUserMediaError (e) {
|
||||||
* `name` String - 捕获窗口或屏幕的描述名 . 如果资源为屏幕,名字为 `Entire Screen` 或 `Screen <index>`; 如果资源为窗口, 名字为窗口的标题.
|
* `name` String - 捕获窗口或屏幕的描述名 . 如果资源为屏幕,名字为 `Entire Screen` 或 `Screen <index>`; 如果资源为窗口, 名字为窗口的标题.
|
||||||
* `thumbnail` [NativeImage](NativeImage.md) - 缩略图.
|
* `thumbnail` [NativeImage](NativeImage.md) - 缩略图.
|
||||||
|
|
||||||
**注意:** 不能保证 `source.thumbnail` 的 size 和 `options` 中的 `thumnbailSize` 一直一致. 它也取决于屏幕或窗口的缩放比例.
|
**注意:** 不能保证 `source.thumbnail` 的 size 和 `options` 中的 `thumnbailSize` 一直一致. 它也取决于屏幕或窗口的缩放比例.
|
||||||
|
|
|
@ -5,9 +5,8 @@
|
||||||
对话框例子,展示了选择文件和目录:
|
对话框例子,展示了选择文件和目录:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var win = ...; // BrowserWindow in which to show the dialog
|
const {dialog} = require('electron')
|
||||||
const dialog = require('electron').dialog;
|
console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}))
|
||||||
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**macOS 上的注意事项**: 如果你想像sheets一样展示对话框,只需要在`browserWindow` 参数中提供一个 `BrowserWindow` 的引用对象.
|
**macOS 上的注意事项**: 如果你想像sheets一样展示对话框,只需要在`browserWindow` 参数中提供一个 `BrowserWindow` 的引用对象.
|
||||||
|
@ -91,4 +90,4 @@ console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', '
|
||||||
|
|
||||||
展示一个传统的包含错误信息的对话框.
|
展示一个传统的包含错误信息的对话框.
|
||||||
|
|
||||||
在 `app` 模块触发 `ready` 事件之前,这个 api 可以被安全调用,通常它被用来在启动的早期阶段报告错误. 在 Linux 上,如果在 `app` 模块触发 `ready` 事件之前调用,message 将会被触发显示stderr,并且没有实际GUI 框显示.
|
在 `app` 模块触发 `ready` 事件之前,这个 api 可以被安全调用,通常它被用来在启动的早期阶段报告错误. 在 Linux 上,如果在 `app` 模块触发 `ready` 事件之前调用,message 将会被触发显示stderr,并且没有实际GUI 框显示.
|
||||||
|
|
|
@ -6,22 +6,31 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In the main process.
|
// 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.
|
// Set the save path, making Electron not to prompt a save dialog.
|
||||||
item.setSavePath('/tmp/save.pdf');
|
item.setSavePath('/tmp/save.pdf')
|
||||||
console.log(item.getMimeType());
|
|
||||||
console.log(item.getFilename());
|
item.on('updated', (event, state) => {
|
||||||
console.log(item.getTotalBytes());
|
if (state === 'interrupted') {
|
||||||
item.on('updated', function() {
|
console.log('Download is interrupted but can be resumed')
|
||||||
console.log('Received bytes: ' + item.getReceivedBytes());
|
} else if (state === 'progressing') {
|
||||||
});
|
if (item.isPaused()) {
|
||||||
item.on('done', function(e, state) {
|
console.log('Download is paused')
|
||||||
if (state == "completed") {
|
} else {
|
||||||
console.log("Download successfully");
|
console.log(`Received bytes: ${item.getReceivedBytes()}`)
|
||||||
} else {
|
}
|
||||||
console.log("Download is cancelled or interrupted that can't be resumed");
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
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',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: function (item, focusedWindow) {
|
click: function (item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.reload()
|
||||||
focusedWindow.reload()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: (function () {
|
accelerator: (function () {
|
||||||
if (process.platform == 'darwin')
|
return (process.platform === 'darwin') ? 'Ctrl+Command+F' : 'F11'
|
||||||
return 'Ctrl+Command+F'
|
|
||||||
else
|
|
||||||
return 'F11'
|
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click: function (item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
||||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: (function () {
|
accelerator: (function () {
|
||||||
if (process.platform == 'darwin')
|
if (process.platform === 'darwin') {
|
||||||
return 'Alt+Command+I'
|
return 'Alt+Command+I'
|
||||||
else
|
} else {
|
||||||
return 'Ctrl+Shift+I'
|
return 'Ctrl+Shift+I'
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click: function (item, focusedWindow) {
|
||||||
if (focusedWindow)
|
if (focusedWindow) focusedWindow.toggleDevTools()
|
||||||
focusedWindow.toggleDevTools()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -137,7 +132,7 @@ var template = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
var name = require('electron').remote.app.getName()
|
var name = require('electron').remote.app.getName()
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: name,
|
label: name,
|
||||||
|
@ -352,4 +347,4 @@ Property List Files][AboutInformationPropertyListFiles] .
|
||||||
|
|
||||||
[AboutInformationPropertyListFiles]: https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html
|
[AboutInformationPropertyListFiles]: https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html
|
||||||
[setMenu]:
|
[setMenu]:
|
||||||
https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetmenumenu-linux-windows
|
https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetmenumenu-linux-windows
|
||||||
|
|
|
@ -17,7 +17,7 @@ Electron 中的 `process` 对象 与 upstream node 中的有以下的不同点:
|
||||||
|
|
||||||
当node被完全关闭的时候,它可以被预加载脚本使用来添加(原文: removed)与node无关的全局符号来回退到全局范围:
|
当node被完全关闭的时候,它可以被预加载脚本使用来添加(原文: removed)与node无关的全局符号来回退到全局范围:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
// preload.js
|
// preload.js
|
||||||
var _setImmediate = setImmediate
|
var _setImmediate = setImmediate
|
||||||
var _clearImmediate = clearImmediate
|
var _clearImmediate = clearImmediate
|
||||||
|
|
|
@ -5,18 +5,15 @@
|
||||||
例子,使用一个与 `file://` 功能相似的协议 :
|
例子,使用一个与 `file://` 功能相似的协议 :
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const electron = require('electron')
|
const {app, protocol} = require('electron')
|
||||||
const app = electron.app
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', () => {
|
||||||
var protocol = electron.protocol
|
protocol.registerFileProtocol('atom', (request, callback) => {
|
||||||
protocol.registerFileProtocol('atom', function (request, callback) {
|
const url = request.url.substr(7)
|
||||||
var url = request.url.substr(7)
|
callback({path: path.normalize(`${__dirname}/${url}`)})
|
||||||
callback({path: path.normalize(__dirname + '/' + url)})
|
}, (error) => {
|
||||||
}, function (error) {
|
if (error) console.error('Failed to register protocol')
|
||||||
if (error)
|
|
||||||
console.error('Failed to register protocol')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -63,7 +60,7 @@ app.on('ready', function () {
|
||||||
为了处理请求,调用 `callback` 时需要使用文件路径或者一个带 `path` 参数的对象, 例如 `callback(filePath)` 或
|
为了处理请求,调用 `callback` 时需要使用文件路径或者一个带 `path` 参数的对象, 例如 `callback(filePath)` 或
|
||||||
`callback({path: filePath})`.
|
`callback({path: filePath})`.
|
||||||
|
|
||||||
当不使用任何参数调用 `callback` 时,你可以指定一个数字或一个带有 `error` 参数的对象,来标识 `request` 失败.你可以使用的 error number 可以参考
|
当不使用任何参数调用 `callback` 时,你可以指定一个数字或一个带有 `error` 参数的对象,来标识 `request` 失败.你可以使用的 error number 可以参考
|
||||||
[net error list][net-error].
|
[net error list][net-error].
|
||||||
|
|
||||||
默认 `scheme` 会被注册为一个 `http:` 协议,它与遵循 "generic URI syntax" 规则的协议解析不同,例如 `file:` ,所以你或许应该调用 `protocol.registerStandardSchemes` 来创建一个标准的 scheme.
|
默认 `scheme` 会被注册为一个 `http:` 协议,它与遵循 "generic URI syntax" 规则的协议解析不同,例如 `file:` ,所以你或许应该调用 `protocol.registerStandardSchemes` 来创建一个标准的 scheme.
|
||||||
|
@ -85,8 +82,7 @@ app.on('ready', function () {
|
||||||
protocol.registerBufferProtocol('atom', function (request, callback) {
|
protocol.registerBufferProtocol('atom', function (request, callback) {
|
||||||
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')})
|
callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')})
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
if (error)
|
if (error) console.error('Failed to register protocol')
|
||||||
console.error('Failed to register protocol')
|
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -180,4 +176,4 @@ which sends a new HTTP request as a response.
|
||||||
* `completion` Function
|
* `completion` Function
|
||||||
取消对 `scheme` 的拦截,使用它的原始句柄进行处理.
|
取消对 `scheme` 的拦截,使用它的原始句柄进行处理.
|
||||||
|
|
||||||
[net-error]: https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h
|
[net-error]: https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h
|
||||||
|
|
|
@ -37,7 +37,7 @@ app.on('ready', function () {
|
||||||
var displays = electronScreen.getAllDisplays()
|
var displays = electronScreen.getAllDisplays()
|
||||||
var externalDisplay = null
|
var externalDisplay = null
|
||||||
for (var i in displays) {
|
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]
|
externalDisplay = displays[i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,11 +77,13 @@ session.defaultSession.on('will-download', function (event, item, webContents) {
|
||||||
```javascript
|
```javascript
|
||||||
// 查询所有 cookies.
|
// 查询所有 cookies.
|
||||||
session.defaultSession.cookies.get({}, function (error, cookies) {
|
session.defaultSession.cookies.get({}, function (error, cookies) {
|
||||||
|
if (error) console.error(error)
|
||||||
console.log(cookies)
|
console.log(cookies)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 查询与指定 url 相关的所有 cookies.
|
// 查询与指定 url 相关的所有 cookies.
|
||||||
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (error, cookies) {
|
session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (error, cookies) {
|
||||||
|
if (error) console.error(error)
|
||||||
console.log(cookies)
|
console.log(cookies)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -89,15 +91,14 @@ session.defaultSession.cookies.get({ url: 'http://www.github.com' }, function (e
|
||||||
// may overwrite equivalent cookies if they exist.
|
// may overwrite equivalent cookies if they exist.
|
||||||
var cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
|
var cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' }
|
||||||
session.defaultSession.cookies.set(cookie, function (error) {
|
session.defaultSession.cookies.set(cookie, function (error) {
|
||||||
if (error)
|
if (error) console.error(error)
|
||||||
console.error(error)
|
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `ses.cookies.get(filter, callback)`
|
#### `ses.cookies.get(filter, callback)`
|
||||||
|
|
||||||
* `filter` Object
|
* `filter` Object
|
||||||
* `url` String (可选) - 与获取 cookies 相关的
|
* `url` String (可选) - 与获取 cookies 相关的
|
||||||
`url`.不设置的话就是从所有 url 获取 cookies .
|
`url`.不设置的话就是从所有 url 获取 cookies .
|
||||||
* `name` String (可选) - 通过 name 过滤 cookies.
|
* `name` String (可选) - 通过 name 过滤 cookies.
|
||||||
* `domain` String (可选) - 获取对应域名或子域名的 cookies .
|
* `domain` String (可选) - 获取对应域名或子域名的 cookies .
|
||||||
|
@ -106,7 +107,7 @@ session.defaultSession.cookies.set(cookie, function (error) {
|
||||||
* `session` Boolean (可选) - 过滤掉 session 或 持久的 cookies.
|
* `session` Boolean (可选) - 过滤掉 session 或 持久的 cookies.
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
|
||||||
发送一个请求,希望获得所有匹配 `details` 的 cookies,
|
发送一个请求,希望获得所有匹配 `details` 的 cookies,
|
||||||
在完成的时候,将通过 `callback(error, cookies)` 调用 `callback`.
|
在完成的时候,将通过 `callback(error, cookies)` 调用 `callback`.
|
||||||
|
|
||||||
`cookies`是一个 `cookie` 对象.
|
`cookies`是一个 `cookie` 对象.
|
||||||
|
@ -126,7 +127,7 @@ session.defaultSession.cookies.set(cookie, function (error) {
|
||||||
#### `ses.cookies.set(details, callback)`
|
#### `ses.cookies.set(details, callback)`
|
||||||
|
|
||||||
* `details` Object
|
* `details` Object
|
||||||
* `url` String - 与获取 cookies 相关的
|
* `url` String - 与获取 cookies 相关的
|
||||||
`url`.
|
`url`.
|
||||||
* `name` String - cookie 名. 忽略默认为空.
|
* `name` String - cookie 名. 忽略默认为空.
|
||||||
* `value` String - cookie 值. 忽略默认为空.
|
* `value` String - cookie 值. 忽略默认为空.
|
||||||
|
@ -142,7 +143,7 @@ session.defaultSession.cookies.set(cookie, function (error) {
|
||||||
|
|
||||||
#### `ses.cookies.remove(url, name, callback)`
|
#### `ses.cookies.remove(url, name, callback)`
|
||||||
|
|
||||||
* `url` String - 与 cookies 相关的
|
* `url` String - 与 cookies 相关的
|
||||||
`url`.
|
`url`.
|
||||||
* `name` String - 需要删除的 cookie 名.
|
* `name` String - 需要删除的 cookie 名.
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
@ -203,7 +204,7 @@ proxyURL = [<proxyScheme>"://"]<proxyHost>[":"<proxyPort>]
|
||||||
|
|
||||||
例子:
|
例子:
|
||||||
|
|
||||||
* `http=foopy:80;ftp=foopy2` - 为 `http://` URL 使用 HTTP 代理 `foopy:80` , 和为 `ftp://` URL
|
* `http=foopy:80;ftp=foopy2` - 为 `http://` URL 使用 HTTP 代理 `foopy:80` , 和为 `ftp://` URL
|
||||||
HTTP 代理 `foopy2:80` .
|
HTTP 代理 `foopy2:80` .
|
||||||
* `foopy:80` - 为所有 URL 使用 HTTP 代理 `foopy:80` .
|
* `foopy:80` - 为所有 URL 使用 HTTP 代理 `foopy:80` .
|
||||||
* `foopy:80,bar,direct://` - 为所有 URL 使用 HTTP 代理 `foopy:80` , 如果 `foopy:80` 不可用,则切换使用 `bar`, 再往后就不使用代理了.
|
* `foopy:80,bar,direct://` - 为所有 URL 使用 HTTP 代理 `foopy:80` , 如果 `foopy:80` 不可用,则切换使用 `bar`, 再往后就不使用代理了.
|
||||||
|
@ -229,7 +230,7 @@ proxyURL = [<proxyScheme>"://"]<proxyHost>[":"<proxyPort>]
|
||||||
|
|
||||||
* `options` Object
|
* `options` Object
|
||||||
* `offline` Boolean - 是否模拟网络故障.
|
* `offline` Boolean - 是否模拟网络故障.
|
||||||
* `latency` Double - 每毫秒的 RTT
|
* `latency` Double - 每毫秒的 RTT
|
||||||
* `downloadThroughput` Double - 每 Bps 的下载速率.
|
* `downloadThroughput` Double - 每 Bps 的下载速率.
|
||||||
* `uploadThroughput` Double - 每 Bps 的上载速率.
|
* `uploadThroughput` Double - 每 Bps 的上载速率.
|
||||||
|
|
||||||
|
@ -262,10 +263,7 @@ window.webContents.session.enableNetworkEmulation({offline: true})
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert, callback) {
|
myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert, callback) {
|
||||||
if (hostname == 'github.com')
|
callback(hostname === 'github.com')
|
||||||
callback(true)
|
|
||||||
else
|
|
||||||
callback(false)
|
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -281,7 +279,7 @@ myWindow.webContents.session.setCertificateVerifyProc(function (hostname, cert,
|
||||||
```javascript
|
```javascript
|
||||||
session.fromPartition(partition).setPermissionRequestHandler(function (webContents, permission, callback) {
|
session.fromPartition(partition).setPermissionRequestHandler(function (webContents, permission, callback) {
|
||||||
if (webContents.getURL() === host) {
|
if (webContents.getURL() === host) {
|
||||||
if (permission == 'notifications') {
|
if (permission === 'notifications') {
|
||||||
callback(false) // denied.
|
callback(false) // denied.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -478,4 +476,4 @@ session.defaultSession.webRequest.onBeforeSendHeaders(filter, function (details,
|
||||||
* `resourceType` String
|
* `resourceType` String
|
||||||
* `timestamp` Double
|
* `timestamp` Double
|
||||||
* `fromCache` Boolean
|
* `fromCache` Boolean
|
||||||
* `error` String - 错误描述.
|
* `error` String - 错误描述.
|
||||||
|
|
|
@ -428,51 +428,51 @@ var currentURL = win.webContents.getURL()
|
||||||
|
|
||||||
### `webContents.undo()`
|
### `webContents.undo()`
|
||||||
|
|
||||||
执行网页的编辑命令 `undo` .
|
执行网页的编辑命令 `undo` .
|
||||||
|
|
||||||
### `webContents.redo()`
|
### `webContents.redo()`
|
||||||
|
|
||||||
执行网页的编辑命令 `redo` .
|
执行网页的编辑命令 `redo` .
|
||||||
|
|
||||||
### `webContents.cut()`
|
### `webContents.cut()`
|
||||||
|
|
||||||
执行网页的编辑命令 `cut` .
|
执行网页的编辑命令 `cut` .
|
||||||
|
|
||||||
### `webContents.copy()`
|
### `webContents.copy()`
|
||||||
|
|
||||||
执行网页的编辑命令 `copy` .
|
执行网页的编辑命令 `copy` .
|
||||||
|
|
||||||
### `webContents.paste()`
|
### `webContents.paste()`
|
||||||
|
|
||||||
执行网页的编辑命令 `paste` .
|
执行网页的编辑命令 `paste` .
|
||||||
|
|
||||||
### `webContents.pasteAndMatchStyle()`
|
### `webContents.pasteAndMatchStyle()`
|
||||||
|
|
||||||
执行网页的编辑命令 `pasteAndMatchStyle` .
|
执行网页的编辑命令 `pasteAndMatchStyle` .
|
||||||
|
|
||||||
### `webContents.delete()`
|
### `webContents.delete()`
|
||||||
|
|
||||||
执行网页的编辑命令 `delete` .
|
执行网页的编辑命令 `delete` .
|
||||||
|
|
||||||
### `webContents.selectAll()`
|
### `webContents.selectAll()`
|
||||||
|
|
||||||
执行网页的编辑命令 `selectAll` .
|
执行网页的编辑命令 `selectAll` .
|
||||||
|
|
||||||
### `webContents.unselect()`
|
### `webContents.unselect()`
|
||||||
|
|
||||||
执行网页的编辑命令 `unselect` .
|
执行网页的编辑命令 `unselect` .
|
||||||
|
|
||||||
### `webContents.replace(text)`
|
### `webContents.replace(text)`
|
||||||
|
|
||||||
* `text` String
|
* `text` String
|
||||||
|
|
||||||
执行网页的编辑命令 `replace` .
|
执行网页的编辑命令 `replace` .
|
||||||
|
|
||||||
### `webContents.replaceMisspelling(text)`
|
### `webContents.replaceMisspelling(text)`
|
||||||
|
|
||||||
* `text` String
|
* `text` String
|
||||||
|
|
||||||
执行网页的编辑命令 `replaceMisspelling` .
|
执行网页的编辑命令 `replaceMisspelling` .
|
||||||
|
|
||||||
### `webContents.insertText(text)`
|
### `webContents.insertText(text)`
|
||||||
|
|
||||||
|
@ -508,8 +508,7 @@ var currentURL = win.webContents.getURL()
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webContents.on('found-in-page', function (event, result) {
|
webContents.on('found-in-page', function (event, result) {
|
||||||
if (result.finalUpdate)
|
if (result.finalUpdate) webContents.stopFindInPage('clearSelection')
|
||||||
webContents.stopFindInPage('clearSelection')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const requestId = webContents.findInPage('api')
|
const requestId = webContents.findInPage('api')
|
||||||
|
@ -577,8 +576,7 @@ win.webContents.on('did-finish-load', function () {
|
||||||
win.webContents.printToPDF({}, function (error, data) {
|
win.webContents.printToPDF({}, function (error, data) {
|
||||||
if (error) throw error
|
if (error) throw error
|
||||||
fs.writeFile('/tmp/print.pdf', data, function (error) {
|
fs.writeFile('/tmp/print.pdf', data, function (error) {
|
||||||
if (error)
|
if (error) throw error
|
||||||
throw error
|
|
||||||
console.log('Write PDF successfully.')
|
console.log('Write PDF successfully.')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -653,7 +651,7 @@ Toggles 开发者工具.
|
||||||
var window = null
|
var window = null
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
window = new BrowserWindow({width: 800, height: 600})
|
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.on('did-finish-load', function () {
|
||||||
window.webContents.send('ping', 'whoooooooh!')
|
window.webContents.send('ping', 'whoooooooh!')
|
||||||
})
|
})
|
||||||
|
@ -666,8 +664,8 @@ app.on('ready', function () {
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
require('electron').ipcRenderer.on('ping', function(event, message) {
|
require('electron').ipcRenderer.on('ping', function(event, message) {
|
||||||
console.log(message); // Prints "whoooooooh!"
|
console.log(message) // Prints "whoooooooh!"
|
||||||
});
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -686,8 +684,8 @@ app.on('ready', function () {
|
||||||
* `height` Integer - 设置模拟屏幕 height
|
* `height` Integer - 设置模拟屏幕 height
|
||||||
* `viewPosition` Object - 在屏幕放置 view
|
* `viewPosition` Object - 在屏幕放置 view
|
||||||
(screenPosition == mobile) (默认: `{x: 0, y: 0}`)
|
(screenPosition == mobile) (默认: `{x: 0, y: 0}`)
|
||||||
* `x` Integer - 设置偏移左上角的x轴
|
* `x` Integer - 设置偏移左上角的x轴
|
||||||
* `y` Integer - 设置偏移左上角的y轴
|
* `y` Integer - 设置偏移左上角的y轴
|
||||||
* `deviceScaleFactor` Integer - 设置设备比例因子 (如果为0,默认为原始屏幕比例) (默认: `0`)
|
* `deviceScaleFactor` Integer - 设置设备比例因子 (如果为0,默认为原始屏幕比例) (默认: `0`)
|
||||||
* `viewSize` Object - 设置模拟视图 size (空表示不覆盖)
|
* `viewSize` Object - 设置模拟视图 size (空表示不覆盖)
|
||||||
* `width` Integer - 设置模拟视图 width
|
* `width` Integer - 设置模拟视图 width
|
||||||
|
@ -773,8 +771,7 @@ win.loadURL('https://github.com')
|
||||||
|
|
||||||
win.webContents.on('did-finish-load', function () {
|
win.webContents.on('did-finish-load', function () {
|
||||||
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', function (error) {
|
win.webContents.savePage('/tmp/test.html', 'HTMLComplete', function (error) {
|
||||||
if (!error)
|
if (!error) console.log('Save page successfully')
|
||||||
console.log('Save page successfully')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -806,16 +803,17 @@ try {
|
||||||
win.webContents.debugger.attach('1.1')
|
win.webContents.debugger.attach('1.1')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Debugger attach failed : ', err)
|
console.log('Debugger attach failed : ', err)
|
||||||
};
|
}
|
||||||
|
|
||||||
win.webContents.debugger.on('detach', function (event, reason) {
|
win.webContents.debugger.on('detach', function (event, reason) {
|
||||||
console.log('Debugger detached due to : ', reason)
|
console.log('Debugger detached due to : ', reason)
|
||||||
})
|
})
|
||||||
|
|
||||||
win.webContents.debugger.on('message', function (event, method, params) {
|
win.webContents.debugger.on('message', function (event, method, params) {
|
||||||
if (method == 'Network.requestWillBeSent') {
|
if (method === 'Network.requestWillBeSent') {
|
||||||
if (params.request.url == 'https://www.github.com')
|
if (params.request.url === 'https://www.github.com') {
|
||||||
win.webContents.debugger.detach()
|
win.webContents.debugger.detach()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -537,8 +537,7 @@ webview.addEventListener('console-message', function (e) {
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
webview.addEventListener('found-in-page', function (e) {
|
webview.addEventListener('found-in-page', function (e) {
|
||||||
if (e.result.finalUpdate)
|
if (e.result.finalUpdate) webview.stopFindInPage('keepSelection')
|
||||||
webview.stopFindInPage('keepSelection')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const rquestId = webview.findInPage('test')
|
const rquestId = webview.findInPage('test')
|
||||||
|
@ -670,7 +669,7 @@ ipcRenderer.on('ping', function () {
|
||||||
|
|
||||||
### Event: 'did-change-theme-color'
|
### Event: 'did-change-theme-color'
|
||||||
|
|
||||||
在页面的主体色改变的时候触发.
|
在页面的主体色改变的时候触发.
|
||||||
在使用 meta 标签的时候这就很常见了:
|
在使用 meta 标签的时候这就很常见了:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
|
@ -689,4 +688,4 @@ ipcRenderer.on('ping', function () {
|
||||||
|
|
||||||
在开发者工具获取焦点的时候触发.
|
在开发者工具获取焦点的时候触发.
|
||||||
|
|
||||||
[blink-feature-string]: https://code.google.com/p/chromium/codesearch#chromium/src/out/Debug/gen/blink/platform/RuntimeEnabledFeatures.cpp&sq=package:chromium&type=cs&l=527
|
[blink-feature-string]: https://code.google.com/p/chromium/codesearch#chromium/src/out/Debug/gen/blink/platform/RuntimeEnabledFeatures.cpp&sq=package:chromium&type=cs&l=527
|
||||||
|
|
|
@ -75,16 +75,18 @@ macOS 可以让开发者定制自己的菜单,通常会包含一些常用特
|
||||||
![Dock menu of Terminal.app][6]
|
![Dock menu of Terminal.app][6]
|
||||||
|
|
||||||
使用 `app.dock.setMenu` API 来设置你的菜单,这仅在 macOS 上可行:
|
使用 `app.dock.setMenu` API 来设置你的菜单,这仅在 macOS 上可行:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app')
|
const {app, Menu} = require('electron')
|
||||||
var Menu = require('menu')
|
|
||||||
var dockMenu = Menu.buildFromTemplate([
|
const dockMenu = Menu.buildFromTemplate([
|
||||||
{ label: 'New Window', click: function () { console.log('New Window') } },
|
{label: 'New Window', click () { console.log('New Window') }},
|
||||||
{ label: 'New Window with Settings', submenu: [
|
{label: 'New Window with Settings',
|
||||||
{ label: 'Basic' },
|
submenu: [
|
||||||
{ label: 'Pro'}
|
{label: 'Basic'},
|
||||||
|
{label: 'Pro'}
|
||||||
]},
|
]},
|
||||||
{ label: 'New Command...'}
|
{label: 'New Command...'}
|
||||||
])
|
])
|
||||||
app.dock.setMenu(dockMenu)
|
app.dock.setMenu(dockMenu)
|
||||||
```
|
```
|
||||||
|
@ -174,8 +176,8 @@ Unity DE 也具有同样的特性,在运行器上显示进度条。
|
||||||
|
|
||||||
给一个窗口设置进度条,你可以调用 [BrowserWindow.setProgressBar][15] API:
|
给一个窗口设置进度条,你可以调用 [BrowserWindow.setProgressBar][15] API:
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
var window = new BrowserWindow()
|
||||||
window.setProgressBar(0.5);
|
window.setProgressBar(0.5)
|
||||||
```
|
```
|
||||||
在 macOS,一个窗口可以设置它展示的文件,文件的图标可以出现在标题栏,当用户 Command-Click 或者 Control-Click 标题栏,文件路径弹窗将会出现。
|
在 macOS,一个窗口可以设置它展示的文件,文件的图标可以出现在标题栏,当用户 Command-Click 或者 Control-Click 标题栏,文件路径弹窗将会出现。
|
||||||
### 展示文件弹窗菜单:
|
### 展示文件弹窗菜单:
|
||||||
|
@ -183,9 +185,9 @@ window.setProgressBar(0.5);
|
||||||
|
|
||||||
你可以调用 [BrowserWindow.setRepresentedFilename][17] 和 [BrowserWindow.setDocumentEdited][18] APIs:
|
你可以调用 [BrowserWindow.setRepresentedFilename][17] 和 [BrowserWindow.setDocumentEdited][18] APIs:
|
||||||
```javascript
|
```javascript
|
||||||
var window = new BrowserWindow({...});
|
var window = new BrowserWindow()
|
||||||
window.setRepresentedFilename('/etc/passwd');
|
window.setRepresentedFilename('/etc/passwd')
|
||||||
window.setDocumentEdited(true);
|
window.setDocumentEdited(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
[1]:https://camo.githubusercontent.com/3310597e01f138b1d687e07aa618c50908a88dec/687474703a2f2f692e6d73646e2e6d6963726f736f66742e636f6d2f64796e696d672f49433432303533382e706e67
|
[1]:https://camo.githubusercontent.com/3310597e01f138b1d687e07aa618c50908a88dec/687474703a2f2f692e6d73646e2e6d6963726f736f66742e636f6d2f64796e696d672f49433432303533382e706e67
|
||||||
|
@ -206,7 +208,7 @@ window.setDocumentEdited(true);
|
||||||
[16]: https://cloud.githubusercontent.com/assets/639601/5082061/670a949a-6f14-11e4-987a-9aaa04b23c1d.png
|
[16]: https://cloud.githubusercontent.com/assets/639601/5082061/670a949a-6f14-11e4-987a-9aaa04b23c1d.png
|
||||||
[17]: https://github.com/electron/electron/blob/master/docs-translations/zh-CN/api/browser-window.md
|
[17]: https://github.com/electron/electron/blob/master/docs-translations/zh-CN/api/browser-window.md
|
||||||
[18]: https://github.com/electron/electron/blob/master/docs-translations/zh-CN/api/browser-window.md
|
[18]: https://github.com/electron/electron/blob/master/docs-translations/zh-CN/api/browser-window.md
|
||||||
|
|
||||||
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows
|
[addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows
|
||||||
[clearrecentdocuments]: ../api/app.md#appclearrecentdocuments-os-x-windows
|
[clearrecentdocuments]: ../api/app.md#appclearrecentdocuments-os-x-windows
|
||||||
[setusertaskstasks]: ../api/app.md#appsetusertaskstasks-windows
|
[setusertaskstasks]: ../api/app.md#appsetusertaskstasks-windows
|
||||||
|
|
|
@ -10,7 +10,7 @@ const BrowserWindow = electron.BrowserWindow
|
||||||
var onlineStatusWindow
|
var onlineStatusWindow
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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
|
var onlineStatusWindow
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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) {
|
ipcMain.on('online-status-changed', function (event, status) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ your-app/
|
||||||
└── index.html
|
└── index.html
|
||||||
````
|
````
|
||||||
`package.json `的格式和 Node 的完全一致,并且那个被 `main` 字段声明的脚本文件是你的应用的启动脚本,它运行在主进程上。你应用里的 `package.json` 看起来应该像:
|
`package.json `的格式和 Node 的完全一致,并且那个被 `main` 字段声明的脚本文件是你的应用的启动脚本,它运行在主进程上。你应用里的 `package.json` 看起来应该像:
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "your-app",
|
"name" : "your-app",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.0",
|
||||||
|
|
|
@ -34,7 +34,7 @@ app.on('ready', function () {
|
||||||
'plugins': true
|
'plugins': true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
// Something else
|
// Something else
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -12,7 +12,7 @@ var onlineStatusWindow
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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 () {
|
app.on('ready', function () {
|
||||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
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) {
|
ipc.on('online-status-changed', function (event, status) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ your-app/
|
||||||
`package.json` 的格式與 Node 的模組完全一樣,並且有個腳本被指定為 `main` 是用來啟動你的應用程式,它運行在主行程上。
|
`package.json` 的格式與 Node 的模組完全一樣,並且有個腳本被指定為 `main` 是用來啟動你的應用程式,它運行在主行程上。
|
||||||
你應用裡的 一個範例在你的 `package.json` 看起來可能像這樣:
|
你應用裡的 一個範例在你的 `package.json` 看起來可能像這樣:
|
||||||
|
|
||||||
```json
|
```javascripton
|
||||||
{
|
{
|
||||||
"name" : "your-app",
|
"name" : "your-app",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.0",
|
||||||
|
@ -70,7 +70,7 @@ var mainWindow = null;
|
||||||
app.on('window-all-closed', function() {
|
app.on('window-all-closed', function() {
|
||||||
// 在macOS 上,通常使用者在明確地按下 Cmd + Q 之前
|
// 在macOS 上,通常使用者在明確地按下 Cmd + Q 之前
|
||||||
// 應用會保持活動狀態
|
// 應用會保持活動狀態
|
||||||
if (process.platform != 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -82,7 +82,7 @@ app.on('ready', function() {
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||||
|
|
||||||
// 載入應用程式的 index.html
|
// 載入應用程式的 index.html
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||||
|
|
||||||
// 打開開發者工具
|
// 打開開發者工具
|
||||||
mainWindow.webContents.openDevTools();
|
mainWindow.webContents.openDevTools();
|
||||||
|
|
|
@ -31,7 +31,7 @@ app.on('ready', function () {
|
||||||
'plugins': true
|
'plugins': true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
||||||
// Something else
|
// Something else
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue