Merge pull request #5169 from Stone-Jay/patch-4
Update sample code in online-offline-events.md
This commit is contained in:
commit
16de30dd04
1 changed files with 12 additions and 10 deletions
|
@ -3,10 +3,11 @@
|
||||||
|
|
||||||
*main.js*
|
*main.js*
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var BrowserWindow = require('browser-window');
|
const app = electron.app;
|
||||||
var onlineStatusWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
|
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');
|
||||||
|
@ -36,17 +37,18 @@ app.on('ready', function() {
|
||||||
|
|
||||||
*main.js*
|
*main.js*
|
||||||
```javascript
|
```javascript
|
||||||
var app = require('app');
|
const electron = require('electron');
|
||||||
var ipc = require('ipc');
|
const app = electron.app;
|
||||||
var BrowserWindow = require('browser-window');
|
const ipcMain = electron.ipcMain;
|
||||||
var onlineStatusWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
|
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) {
|
ipcMain.on('online-status-changed', function(event, status) {
|
||||||
console.log(status);
|
console.log(status);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -57,9 +59,9 @@ ipc.on('online-status-changed', function(event, status) {
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var ipc = require('ipc');
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
var updateOnlineStatus = function() {
|
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);
|
window.addEventListener('online', updateOnlineStatus);
|
||||||
|
|
Loading…
Reference in a new issue