Merge pull request #5169 from Stone-Jay/patch-4

Update sample code in online-offline-events.md
This commit is contained in:
Cheng Zhao 2016-04-15 22:16:07 +09:00
commit 16de30dd04

View file

@ -3,10 +3,11 @@
*main.js*
```javascript
var app = require('app');
var BrowserWindow = require('browser-window');
var onlineStatusWindow;
const electron = require('electron');
const app = electron.app;
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');
@ -36,17 +37,18 @@ app.on('ready', function() {
*main.js*
```javascript
var app = require('app');
var ipc = require('ipc');
var BrowserWindow = require('browser-window');
var onlineStatusWindow;
const electron = require('electron');
const app = electron.app;
const ipcMain = electron.ipcMain;
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');
});
ipc.on('online-status-changed', function(event, status) {
ipcMain.on('online-status-changed', function(event, status) {
console.log(status);
});
```
@ -57,9 +59,9 @@ ipc.on('online-status-changed', function(event, status) {
<html>
<body>
<script>
var ipc = require('ipc');
const ipcRenderer = require('electron').ipcRenderer;
var updateOnlineStatus = function() {
ipc.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
};
window.addEventListener('online', updateOnlineStatus);