diff --git a/docs-translations/zh-CN/tutorial/online-offline-events.md b/docs-translations/zh-CN/tutorial/online-offline-events.md index c4ba40ce5b..a5d66909a0 100644 --- a/docs-translations/zh-CN/tutorial/online-offline-events.md +++ b/docs-translations/zh-CN/tutorial/online-offline-events.md @@ -1,4 +1,5 @@ # 在线/离线事件探测 + 使用标准 HTML5 APIs 可以实现在线和离线事件的探测,就像以下例子: _main.js_ @@ -37,39 +38,48 @@ _online-status.html_ 也会有人想要在主进程也有回应这些事件的实例。然后主进程没有 `navigator` 对象因此不能直接探测在线还是离线。使用 Electron 的进程间通讯工具,事件就可以在主进程被使用,就像下面的例子: *main.js* -```javascript -const electron = require('electron') -const app = electron.app -const ipcMain = electron.ipcMain -const BrowserWindow = electron.BrowserWindow -var onlineStatusWindow -app.on('ready', function () { +```javascript +const {app, BrowserWindow, ipcMain} = require('electron') +let onlineStatusWindow + +app.on('ready', () => { onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false }) onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`) }) -ipcMain.on('online-status-changed', function (event, status) { +ipcMain.on('online-status-changed', (event, status) => { console.log(status) }) ``` *online-status.html* + ```html -
- - + updateOnlineStatus() + +