diff --git a/docs-translations/es/api/process.md b/docs-translations/es/api/process.md index 77ba017f339c..cc8b4ab2b825 100644 --- a/docs-translations/es/api/process.md +++ b/docs-translations/es/api/process.md @@ -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 diff --git a/docs-translations/es/tutorial/desktop-environment-integration.md b/docs-translations/es/tutorial/desktop-environment-integration.md index 0dce492ff2de..a0d7a08eb019 100644 --- a/docs-translations/es/tutorial/desktop-environment-integration.md +++ b/docs-translations/es/tutorial/desktop-environment-integration.md @@ -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 diff --git a/docs-translations/es/tutorial/online-offline-events.md b/docs-translations/es/tutorial/online-offline-events.md index 27768e7c2a0f..171decbe0483 100644 --- a/docs-translations/es/tutorial/online-offline-events.md +++ b/docs-translations/es/tutorial/online-offline-events.md @@ -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) { diff --git a/docs-translations/es/tutorial/quick-start.md b/docs-translations/es/tutorial/quick-start.md index edfd1a9b52c2..112b4157f0d4 100644 --- a/docs-translations/es/tutorial/quick-start.md +++ b/docs-translations/es/tutorial/quick-start.md @@ -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() diff --git a/docs-translations/es/tutorial/using-pepper-flash-plugin.md b/docs-translations/es/tutorial/using-pepper-flash-plugin.md index c4786edafbe6..10210550bac0 100644 --- a/docs-translations/es/tutorial/using-pepper-flash-plugin.md +++ b/docs-translations/es/tutorial/using-pepper-flash-plugin.md @@ -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 }) ``` diff --git a/docs-translations/jp/api/app.md b/docs-translations/jp/api/app.md index 9545722515ec..7d68731fda59 100644 --- a/docs-translations/jp/api/app.md +++ b/docs-translations/jp/api/app.md @@ -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`) } ``` diff --git a/docs-translations/jp/api/desktop-capturer.md b/docs-translations/jp/api/desktop-capturer.md index fee098fbfb17..4957857dd4f4 100644 --- a/docs-translations/jp/api/desktop-capturer.md +++ b/docs-translations/jp/api/desktop-capturer.md @@ -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: { diff --git a/docs-translations/jp/api/dialog.md b/docs-translations/jp/api/dialog.md index 48a17225bb58..cb9721b920ce 100644 --- a/docs-translations/jp/api/dialog.md +++ b/docs-translations/jp/api/dialog.md @@ -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`を提供することです。 diff --git a/docs-translations/jp/api/download-item.md b/docs-translations/jp/api/download-item.md index 1be61b2f98a5..f646faa4d713 100644 --- a/docs-translations/jp/api/download-item.md +++ b/docs-translations/jp/api/download-item.md @@ -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}`) + } + }) +}) ``` ## イベント diff --git a/docs-translations/jp/api/menu.md b/docs-translations/jp/api/menu.md index edec8a130dd7..22dd019ed1b2 100644 --- a/docs-translations/jp/api/menu.md +++ b/docs-translations/jp/api/menu.md @@ -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, diff --git a/docs-translations/jp/api/process.md b/docs-translations/jp/api/process.md index d37d1510e0f0..dc4924b4b827 100644 --- a/docs-translations/jp/api/process.md +++ b/docs-translations/jp/api/process.md @@ -12,7 +12,7 @@ Electronの`process`オブジェクトは次のようなAPIで拡張されてい Node統合がオフになっているとき、削除したNodeグローバルシンボルをグローバルスコープへ戻すために、プリロードスクリプトで使用できます。 -```js +```javascript // preload.js var _setImmediate = setImmediate var _clearImmediate = clearImmediate diff --git a/docs-translations/jp/api/protocol.md b/docs-translations/jp/api/protocol.md index f0044d6923bc..ceef3179666c 100644 --- a/docs-translations/jp/api/protocol.md +++ b/docs-translations/jp/api/protocol.md @@ -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('
Response
')}) }, function (error) { - if (error) - console.error('Failed to register protocol') + if (error) console.error('Failed to register protocol') }) ``` diff --git a/docs-translations/jp/api/screen.md b/docs-translations/jp/api/screen.md index 02b5f014a0c3..9f5a197a701f 100644 --- a/docs-translations/jp/api/screen.md +++ b/docs-translations/jp/api/screen.md @@ -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 } diff --git a/docs-translations/jp/api/session.md b/docs-translations/jp/api/session.md index 4f8140845735..9a68f23974b8 100644 --- a/docs-translations/jp/api/session.md +++ b/docs-translations/jp/api/session.md @@ -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') }) ``` diff --git a/docs-translations/jp/api/web-view-tag.md b/docs-translations/jp/api/web-view-tag.md index 707f1f7e3ae5..ece0c3052c7e 100644 --- a/docs-translations/jp/api/web-view-tag.md +++ b/docs-translations/jp/api/web-view-tag.md @@ -193,7 +193,7 @@ webview.addEventListener('dom-ready', () => { * `url` URL * `options` Object (optional) - * `httpReferrer` String - リファラURL + * `httpReferrer` String - リファラURL * `userAgent` String - リクエストに使用されるUser agent * `extraHeaders` String - 追加のヘッダを"\n"で区切って指定します。 @@ -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') diff --git a/docs-translations/jp/tutorial/desktop-environment-integration.md b/docs-translations/jp/tutorial/desktop-environment-integration.md index e8a66ee992ca..5ade1b40c07c 100644 --- a/docs-translations/jp/tutorial/desktop-environment-integration.md +++ b/docs-translations/jp/tutorial/desktop-environment-integration.md @@ -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 diff --git a/docs-translations/jp/tutorial/quick-start.md b/docs-translations/jp/tutorial/quick-start.md index 41a810545b61..2d88bef4ef8b 100644 --- a/docs-translations/jp/tutorial/quick-start.md +++ b/docs-translations/jp/tutorial/quick-start.md @@ -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 }) } diff --git a/docs-translations/jp/tutorial/using-pepper-flash-plugin.md b/docs-translations/jp/tutorial/using-pepper-flash-plugin.md index 228c119f18e7..b6adad4089c3 100644 --- a/docs-translations/jp/tutorial/using-pepper-flash-plugin.md +++ b/docs-translations/jp/tutorial/using-pepper-flash-plugin.md @@ -31,7 +31,7 @@ app.on('ready', function () { 'plugins': true } }) - mainWindow.loadURL('file://' + __dirname + '/index.html') + mainWindow.loadURL(`file://${__dirname}/index.html`) // Something else }) ``` diff --git a/docs-translations/jp/tutorial/using-selenium-and-webdriver.md b/docs-translations/jp/tutorial/using-selenium-and-webdriver.md index 4afc199a2d71..e348a0596dd6 100644 --- a/docs-translations/jp/tutorial/using-selenium-and-webdriver.md +++ b/docs-translations/jp/tutorial/using-selenium-and-webdriver.md @@ -15,7 +15,7 @@ Electronで `chromedriver` を使用するために、Electronがどこにある $ npm install --save-dev spectron ``` -```js +```javascript // 可視のウィンドウがタイトル付きで開かれているかを調べる簡単なテスト var Application = require('spectron').Application var assert = require('assert') diff --git a/docs-translations/ko-KR/api/app.md b/docs-translations/ko-KR/api/app.md index 2741c8685583..fd210a35f8a1 100644 --- a/docs-translations/ko-KR/api/app.md +++ b/docs-translations/ko-KR/api/app.md @@ -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' } ] diff --git a/docs-translations/ko-KR/api/clipboard.md b/docs-translations/ko-KR/api/clipboard.md index 46baa71a533a..0c4fbc6bb5ae 100644 --- a/docs-translations/ko-KR/api/clipboard.md +++ b/docs-translations/ko-KR/api/clipboard.md @@ -97,7 +97,7 @@ Returns `Object`: **참고:** 윈도우의 대부분의 앱은 북마크 붙여넣기를 지원하지 않습니다. `clipboard.write` 를 통해 북마크와 대체 텍스트를 클립보드에 쓸 수 있습니다. -```js +```javascript clipboard.write({ text: 'http://electron.atom.io', bookmark: 'Electron Homepage' diff --git a/docs-translations/ko-KR/api/system-preferences.md b/docs-translations/ko-KR/api/system-preferences.md index e7f7120f97c6..e32c9843ddf7 100644 --- a/docs-translations/ko-KR/api/system-preferences.md +++ b/docs-translations/ko-KR/api/system-preferences.md @@ -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" diff --git a/docs-translations/ko-KR/tutorial/debugging-main-process-node-inspector.md b/docs-translations/ko-KR/tutorial/debugging-main-process-node-inspector.md index 5e7fc4689ba4..b4d4ce13f9bf 100644 --- a/docs-translations/ko-KR/tutorial/debugging-main-process-node-inspector.md +++ b/docs-translations/ko-KR/tutorial/debugging-main-process-node-inspector.md @@ -9,7 +9,7 @@ $ code electron-quick-start ### 2. 다음 설정으로 `.vscode/launch.json` 파일 추가하기: -```json +```javascripton { "version": "0.2.0", "configurations": [ diff --git a/docs-translations/ko-KR/tutorial/desktop-environment-integration.md b/docs-translations/ko-KR/tutorial/desktop-environment-integration.md index dae61a39aaa7..71cbe0616950 100644 --- a/docs-translations/ko-KR/tutorial/desktop-environment-integration.md +++ b/docs-translations/ko-KR/tutorial/desktop-environment-integration.md @@ -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'} ]}, diff --git a/docs-translations/ko-KR/tutorial/quick-start.md b/docs-translations/ko-KR/tutorial/quick-start.md index 8943ba717339..ce8560d770f7 100644 --- a/docs-translations/ko-KR/tutorial/quick-start.md +++ b/docs-translations/ko-KR/tutorial/quick-start.md @@ -61,7 +61,7 @@ your-app/ 파일을 지정하면 메인 프로세스의 엔트리 포인트로 사용합니다. 예를 들어 사용할 수 있는 `package.json`은 다음과 같습니다: -```json +```javascripton { "name" : "your-app", "version" : "0.1.0", diff --git a/docs-translations/pt-BR/api/app.md b/docs-translations/pt-BR/api/app.md index 37fe071535a4..fb77629a7057 100644 --- a/docs-translations/pt-BR/api/app.md +++ b/docs-translations/pt-BR/api/app.md @@ -2,7 +2,7 @@ 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 const app = require('electron').app @@ -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_ diff --git a/docs-translations/pt-BR/api/browser-window.md b/docs-translations/pt-BR/api/browser-window.md index 1efcb7ee830b..1d992be63271 100644 --- a/docs-translations/pt-BR/api/browser-window.md +++ b/docs-translations/pt-BR/api/browser-window.md @@ -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()) { diff --git a/docs-translations/pt-BR/api/process.md b/docs-translations/pt-BR/api/process.md index 0840d97346dc..2240a0b7a91c 100644 --- a/docs-translations/pt-BR/api/process.md +++ b/docs-translations/pt-BR/api/process.md @@ -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 diff --git a/docs-translations/pt-BR/tutorial/desktop-environment-integration.md b/docs-translations/pt-BR/tutorial/desktop-environment-integration.md index 7e64be38e9d0..73765b8da2de 100644 --- a/docs-translations/pt-BR/tutorial/desktop-environment-integration.md +++ b/docs-translations/pt-BR/tutorial/desktop-environment-integration.md @@ -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 diff --git a/docs-translations/pt-BR/tutorial/online-offline-events.md b/docs-translations/pt-BR/tutorial/online-offline-events.md index 01f810117f68..97eca7acd8bc 100644 --- a/docs-translations/pt-BR/tutorial/online-offline-events.md +++ b/docs-translations/pt-BR/tutorial/online-offline-events.md @@ -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 - - - + updateOnlineStatus() + + ``` diff --git a/docs-translations/pt-BR/tutorial/quick-start.md b/docs-translations/pt-BR/tutorial/quick-start.md index 9934944667d2..4da563346f98 100644 --- a/docs-translations/pt-BR/tutorial/quick-start.md +++ b/docs-translations/pt-BR/tutorial/quick-start.md @@ -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", diff --git a/docs-translations/pt-BR/tutorial/using-pepper-flash-plugin.md b/docs-translations/pt-BR/tutorial/using-pepper-flash-plugin.md index dcc066b4377b..a8ee528fc3b6 100644 --- a/docs-translations/pt-BR/tutorial/using-pepper-flash-plugin.md +++ b/docs-translations/pt-BR/tutorial/using-pepper-flash-plugin.md @@ -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 }) ``` diff --git a/docs-translations/ru-RU/tutorial/quick-start.md b/docs-translations/ru-RU/tutorial/quick-start.md index 1b4012946396..a0916fc5daee 100644 --- a/docs-translations/ru-RU/tutorial/quick-start.md +++ b/docs-translations/ru-RU/tutorial/quick-start.md @@ -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() diff --git a/docs-translations/zh-CN/api/app.md b/docs-translations/zh-CN/api/app.md index 4a1e1b23c4e3..18bcd8b09254 100644 --- a/docs-translations/zh-CN/api/app.md +++ b/docs-translations/zh-CN/api/app.md @@ -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])` diff --git a/docs-translations/zh-CN/api/browser-window.md b/docs-translations/zh-CN/api/browser-window.md index a14d24e26a0e..13fe2ec52647 100644 --- a/docs-translations/zh-CN/api/browser-window.md +++ b/docs-translations/zh-CN/api/browser-window.md @@ -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()) { diff --git a/docs-translations/zh-CN/api/desktop-capturer.md b/docs-translations/zh-CN/api/desktop-capturer.md index 451798c9e95f..89709ada28dd 100644 --- a/docs-translations/zh-CN/api/desktop-capturer.md +++ b/docs-translations/zh-CN/api/desktop-capturer.md @@ -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: { @@ -61,4 +61,4 @@ function getUserMediaError (e) { * `name` String - 捕获窗口或屏幕的描述名 . 如果资源为屏幕,名字为 `Entire Screen` 或 `Screen `; 如果资源为窗口, 名字为窗口的标题. * `thumbnail` [NativeImage](NativeImage.md) - 缩略图. -**注意:** 不能保证 `source.thumbnail` 的 size 和 `options` 中的 `thumnbailSize` 一直一致. 它也取决于屏幕或窗口的缩放比例. \ No newline at end of file +**注意:** 不能保证 `source.thumbnail` 的 size 和 `options` 中的 `thumnbailSize` 一直一致. 它也取决于屏幕或窗口的缩放比例. diff --git a/docs-translations/zh-CN/api/dialog.md b/docs-translations/zh-CN/api/dialog.md index dd691fa6469d..34016c52497c 100644 --- a/docs-translations/zh-CN/api/dialog.md +++ b/docs-translations/zh-CN/api/dialog.md @@ -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` 的引用对象. @@ -91,4 +90,4 @@ console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', ' 展示一个传统的包含错误信息的对话框. -在 `app` 模块触发 `ready` 事件之前,这个 api 可以被安全调用,通常它被用来在启动的早期阶段报告错误. 在 Linux 上,如果在 `app` 模块触发 `ready` 事件之前调用,message 将会被触发显示stderr,并且没有实际GUI 框显示. \ No newline at end of file +在 `app` 模块触发 `ready` 事件之前,这个 api 可以被安全调用,通常它被用来在启动的早期阶段报告错误. 在 Linux 上,如果在 `app` 模块触发 `ready` 事件之前调用,message 将会被触发显示stderr,并且没有实际GUI 框显示. diff --git a/docs-translations/zh-CN/api/download-item.md b/docs-translations/zh-CN/api/download-item.md index e869e8f30570..b2fb99332917 100644 --- a/docs-translations/zh-CN/api/download-item.md +++ b/docs-translations/zh-CN/api/download-item.md @@ -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}`) + } + }) +}) ``` ## 事件 diff --git a/docs-translations/zh-CN/api/menu.md b/docs-translations/zh-CN/api/menu.md index bf9cf8967991..07736d4bbd2b 100644 --- a/docs-translations/zh-CN/api/menu.md +++ b/docs-translations/zh-CN/api/menu.md @@ -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, @@ -352,4 +347,4 @@ Property List Files][AboutInformationPropertyListFiles] . [AboutInformationPropertyListFiles]: https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html [setMenu]: -https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetmenumenu-linux-windows \ No newline at end of file +https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetmenumenu-linux-windows diff --git a/docs-translations/zh-CN/api/process.md b/docs-translations/zh-CN/api/process.md index 81781d105f09..b768eedf6fab 100644 --- a/docs-translations/zh-CN/api/process.md +++ b/docs-translations/zh-CN/api/process.md @@ -17,7 +17,7 @@ Electron 中的 `process` 对象 与 upstream node 中的有以下的不同点: 当node被完全关闭的时候,它可以被预加载脚本使用来添加(原文: removed)与node无关的全局符号来回退到全局范围: -```js +```javascript // preload.js var _setImmediate = setImmediate var _clearImmediate = clearImmediate diff --git a/docs-translations/zh-CN/api/protocol.md b/docs-translations/zh-CN/api/protocol.md index 93f14026e268..44c5a0a05fc1 100644 --- a/docs-translations/zh-CN/api/protocol.md +++ b/docs-translations/zh-CN/api/protocol.md @@ -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') }) }) ``` @@ -63,7 +60,7 @@ app.on('ready', function () { 为了处理请求,调用 `callback` 时需要使用文件路径或者一个带 `path` 参数的对象, 例如 `callback(filePath)` 或 `callback({path: filePath})`. -当不使用任何参数调用 `callback` 时,你可以指定一个数字或一个带有 `error` 参数的对象,来标识 `request` 失败.你可以使用的 error number 可以参考 +当不使用任何参数调用 `callback` 时,你可以指定一个数字或一个带有 `error` 参数的对象,来标识 `request` 失败.你可以使用的 error number 可以参考 [net error list][net-error]. 默认 `scheme` 会被注册为一个 `http:` 协议,它与遵循 "generic URI syntax" 规则的协议解析不同,例如 `file:` ,所以你或许应该调用 `protocol.registerStandardSchemes` 来创建一个标准的 scheme. @@ -85,8 +82,7 @@ app.on('ready', function () { protocol.registerBufferProtocol('atom', function (request, callback) { callback({mimeType: 'text/html', data: new Buffer('
Response
')}) }, function (error) { - if (error) - console.error('Failed to register protocol') + if (error) console.error('Failed to register protocol') }) ``` @@ -180,4 +176,4 @@ which sends a new HTTP request as a response. * `completion` Function 取消对 `scheme` 的拦截,使用它的原始句柄进行处理. -[net-error]: https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h \ No newline at end of file +[net-error]: https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h diff --git a/docs-translations/zh-CN/api/screen.md b/docs-translations/zh-CN/api/screen.md index e964704ac1a5..f1cd9f0ed7d5 100644 --- a/docs-translations/zh-CN/api/screen.md +++ b/docs-translations/zh-CN/api/screen.md @@ -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 } diff --git a/docs-translations/zh-CN/api/session.md b/docs-translations/zh-CN/api/session.md index adefceb1c96c..927b9c16ab68 100644 --- a/docs-translations/zh-CN/api/session.md +++ b/docs-translations/zh-CN/api/session.md @@ -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,15 +91,14 @@ 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) }) ``` #### `ses.cookies.get(filter, callback)` * `filter` Object - * `url` String (可选) - 与获取 cookies 相关的 + * `url` String (可选) - 与获取 cookies 相关的 `url`.不设置的话就是从所有 url 获取 cookies . * `name` String (可选) - 通过 name 过滤 cookies. * `domain` String (可选) - 获取对应域名或子域名的 cookies . @@ -106,7 +107,7 @@ session.defaultSession.cookies.set(cookie, function (error) { * `session` Boolean (可选) - 过滤掉 session 或 持久的 cookies. * `callback` Function -发送一个请求,希望获得所有匹配 `details` 的 cookies, +发送一个请求,希望获得所有匹配 `details` 的 cookies, 在完成的时候,将通过 `callback(error, cookies)` 调用 `callback`. `cookies`是一个 `cookie` 对象. @@ -126,7 +127,7 @@ session.defaultSession.cookies.set(cookie, function (error) { #### `ses.cookies.set(details, callback)` * `details` Object - * `url` String - 与获取 cookies 相关的 + * `url` String - 与获取 cookies 相关的 `url`. * `name` String - cookie 名. 忽略默认为空. * `value` String - cookie 值. 忽略默认为空. @@ -142,7 +143,7 @@ session.defaultSession.cookies.set(cookie, function (error) { #### `ses.cookies.remove(url, name, callback)` -* `url` String - 与 cookies 相关的 +* `url` String - 与 cookies 相关的 `url`. * `name` String - 需要删除的 cookie 名. * `callback` Function @@ -203,7 +204,7 @@ proxyURL = ["://"][":"] 例子: -* `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` . * `foopy:80` - 为所有 URL 使用 HTTP 代理 `foopy:80` . * `foopy:80,bar,direct://` - 为所有 URL 使用 HTTP 代理 `foopy:80` , 如果 `foopy:80` 不可用,则切换使用 `bar`, 再往后就不使用代理了. @@ -229,7 +230,7 @@ proxyURL = ["://"][":"] * `options` Object * `offline` Boolean - 是否模拟网络故障. - * `latency` Double - 每毫秒的 RTT + * `latency` Double - 每毫秒的 RTT * `downloadThroughput` Double - 每 Bps 的下载速率. * `uploadThroughput` Double - 每 Bps 的上载速率. @@ -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 } @@ -478,4 +476,4 @@ session.defaultSession.webRequest.onBeforeSendHeaders(filter, function (details, * `resourceType` String * `timestamp` Double * `fromCache` Boolean - * `error` String - 错误描述. \ No newline at end of file + * `error` String - 错误描述. diff --git a/docs-translations/zh-CN/api/web-contents.md b/docs-translations/zh-CN/api/web-contents.md index fb21cfb6ca0f..d82eb74f592c 100644 --- a/docs-translations/zh-CN/api/web-contents.md +++ b/docs-translations/zh-CN/api/web-contents.md @@ -428,51 +428,51 @@ var currentURL = win.webContents.getURL() ### `webContents.undo()` -执行网页的编辑命令 `undo` . +执行网页的编辑命令 `undo` . ### `webContents.redo()` -执行网页的编辑命令 `redo` . +执行网页的编辑命令 `redo` . ### `webContents.cut()` -执行网页的编辑命令 `cut` . +执行网页的编辑命令 `cut` . ### `webContents.copy()` -执行网页的编辑命令 `copy` . +执行网页的编辑命令 `copy` . ### `webContents.paste()` -执行网页的编辑命令 `paste` . +执行网页的编辑命令 `paste` . ### `webContents.pasteAndMatchStyle()` -执行网页的编辑命令 `pasteAndMatchStyle` . +执行网页的编辑命令 `pasteAndMatchStyle` . ### `webContents.delete()` -执行网页的编辑命令 `delete` . +执行网页的编辑命令 `delete` . ### `webContents.selectAll()` -执行网页的编辑命令 `selectAll` . +执行网页的编辑命令 `selectAll` . ### `webContents.unselect()` -执行网页的编辑命令 `unselect` . +执行网页的编辑命令 `unselect` . ### `webContents.replace(text)` * `text` String -执行网页的编辑命令 `replace` . +执行网页的编辑命令 `replace` . ### `webContents.replaceMisspelling(text)` * `text` String -执行网页的编辑命令 `replaceMisspelling` . +执行网页的编辑命令 `replaceMisspelling` . ### `webContents.insertText(text)` @@ -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 () { @@ -686,8 +684,8 @@ app.on('ready', function () { * `height` Integer - 设置模拟屏幕 height * `viewPosition` Object - 在屏幕放置 view (screenPosition == mobile) (默认: `{x: 0, y: 0}`) - * `x` Integer - 设置偏移左上角的x轴 - * `y` Integer - 设置偏移左上角的y轴 + * `x` Integer - 设置偏移左上角的x轴 + * `y` Integer - 设置偏移左上角的y轴 * `deviceScaleFactor` Integer - 设置设备比例因子 (如果为0,默认为原始屏幕比例) (默认: `0`) * `viewSize` Object - 设置模拟视图 size (空表示不覆盖) * `width` Integer - 设置模拟视图 width @@ -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() + } } }) diff --git a/docs-translations/zh-CN/api/web-view-tag.md b/docs-translations/zh-CN/api/web-view-tag.md index c44228d4a849..01572eae3098 100644 --- a/docs-translations/zh-CN/api/web-view-tag.md +++ b/docs-translations/zh-CN/api/web-view-tag.md @@ -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') @@ -670,7 +669,7 @@ ipcRenderer.on('ping', function () { ### Event: 'did-change-theme-color' -在页面的主体色改变的时候触发. +在页面的主体色改变的时候触发. 在使用 meta 标签的时候这就很常见了: ```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 \ No newline at end of file +[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 diff --git a/docs-translations/zh-CN/tutorial/desktop-environment-integration.md b/docs-translations/zh-CN/tutorial/desktop-environment-integration.md index bce33670a5c5..acceee6da2d8 100644 --- a/docs-translations/zh-CN/tutorial/desktop-environment-integration.md +++ b/docs-translations/zh-CN/tutorial/desktop-environment-integration.md @@ -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 @@ -206,7 +208,7 @@ window.setDocumentEdited(true); [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 [18]: https://github.com/electron/electron/blob/master/docs-translations/zh-CN/api/browser-window.md - + [addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows [clearrecentdocuments]: ../api/app.md#appclearrecentdocuments-os-x-windows [setusertaskstasks]: ../api/app.md#appsetusertaskstasks-windows diff --git a/docs-translations/zh-CN/tutorial/online-offline-events.md b/docs-translations/zh-CN/tutorial/online-offline-events.md index bb4a8fed53ce..e06bb80e89f2 100644 --- a/docs-translations/zh-CN/tutorial/online-offline-events.md +++ b/docs-translations/zh-CN/tutorial/online-offline-events.md @@ -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) { diff --git a/docs-translations/zh-CN/tutorial/quick-start.md b/docs-translations/zh-CN/tutorial/quick-start.md index 5c438c313d31..85a1672ccc4e 100644 --- a/docs-translations/zh-CN/tutorial/quick-start.md +++ b/docs-translations/zh-CN/tutorial/quick-start.md @@ -30,7 +30,7 @@ your-app/ └── index.html ```` `package.json `的格式和 Node 的完全一致,并且那个被 `main` 字段声明的脚本文件是你的应用的启动脚本,它运行在主进程上。你应用里的 `package.json` 看起来应该像: -```json +```javascripton { "name" : "your-app", "version" : "0.1.0", diff --git a/docs-translations/zh-CN/tutorial/using-pepper-flash-plugin.md b/docs-translations/zh-CN/tutorial/using-pepper-flash-plugin.md index 8b5ef8b24f69..7b3e96d35767 100644 --- a/docs-translations/zh-CN/tutorial/using-pepper-flash-plugin.md +++ b/docs-translations/zh-CN/tutorial/using-pepper-flash-plugin.md @@ -34,7 +34,7 @@ app.on('ready', function () { 'plugins': true } }) - mainWindow.loadURL('file://' + __dirname + '/index.html') + mainWindow.loadURL(`file://${__dirname}/index.html`) // Something else }) ``` diff --git a/docs-translations/zh-TW/tutorial/online-offline-events.md b/docs-translations/zh-TW/tutorial/online-offline-events.md index 507a8a1339f7..2848ed089fcf 100644 --- a/docs-translations/zh-TW/tutorial/online-offline-events.md +++ b/docs-translations/zh-TW/tutorial/online-offline-events.md @@ -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) { diff --git a/docs-translations/zh-TW/tutorial/quick-start.md b/docs-translations/zh-TW/tutorial/quick-start.md index ec1f612868cd..8b139d742b17 100644 --- a/docs-translations/zh-TW/tutorial/quick-start.md +++ b/docs-translations/zh-TW/tutorial/quick-start.md @@ -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(); diff --git a/docs-translations/zh-TW/tutorial/using-pepper-flash-plugin.md b/docs-translations/zh-TW/tutorial/using-pepper-flash-plugin.md index 7f7fdf3cdddd..d514a7ef1f21 100644 --- a/docs-translations/zh-TW/tutorial/using-pepper-flash-plugin.md +++ b/docs-translations/zh-TW/tutorial/using-pepper-flash-plugin.md @@ -31,7 +31,7 @@ app.on('ready', function () { 'plugins': true } }) - mainWindow.loadURL('file://' + __dirname + '/index.html') + mainWindow.loadURL(`file://${__dirname}/index.html`) // Something else }) ```