Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ELECTRON_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.0.0-nightly.20210523
14.0.0-nightly.20210524
13 changes: 13 additions & 0 deletions docs/fiddles/features/online-detection/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<h1>Connection status: <strong id='status'></strong></h1>

<script src="renderer.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions docs/fiddles/features/online-detection/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { app, BrowserWindow } = require('electron')

function createWindow () {
const onlineStatusWindow = new BrowserWindow({
width: 300,
height: 200
})

onlineStatusWindow.loadFile('index.html')
}

app.whenReady().then(() => {
createWindow()

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
17 changes: 0 additions & 17 deletions docs/fiddles/features/online-detection/main/index.html

This file was deleted.

24 changes: 0 additions & 24 deletions docs/fiddles/features/online-detection/main/main.js

This file was deleted.

7 changes: 0 additions & 7 deletions docs/fiddles/features/online-detection/main/renderer.js

This file was deleted.

8 changes: 8 additions & 0 deletions docs/fiddles/features/online-detection/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function onlineStatusIndicator () {
document.getElementById('status').innerHTML = navigator.onLine ? 'online' : 'offline'
}

window.addEventListener('online', onlineStatusIndicator)
window.addEventListener('offline', onlineStatusIndicator)

onlineStatusIndicator()
17 changes: 0 additions & 17 deletions docs/fiddles/features/online-detection/renderer/index.html

This file was deleted.

20 changes: 0 additions & 20 deletions docs/fiddles/features/online-detection/renderer/main.js

This file was deleted.

6 changes: 0 additions & 6 deletions docs/fiddles/features/online-detection/renderer/renderer.js

This file was deleted.

Binary file added docs/images/connection-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/tutorial/electron-timelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
| 10.0.0 | 2020-05-21 | 2020-08-25 | M85 | v12.16 |
| 11.0.0 | 2020-08-27 | 2020-11-17 | M87 | v12.18 |
| 12.0.0 | 2020-11-19 | 2021-03-02 | M89 | v14.16 |
| 13.0.0 | 2021-03-04 | 2021-05-25 | M91 | v14.x |
| 13.0.0 | 2021-03-04 | 2021-05-25 | M91 | v14.16 |
| 14.0.0 | 2021-05-27 | 2021-08-31 | M93 | TBD |
123 changes: 47 additions & 76 deletions docs/tutorial/online-offline-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,98 +21,69 @@ status of Electron, you should develop additional means for this check.

## Example

### Event detection in the Renderer process

Starting with a working application from the
[Quick Start Guide](quick-start.md), update the `main.js` file
with the following lines:

```javascript
const { app, BrowserWindow } = require('electron')

let onlineStatusWindow

app.whenReady().then(() => {
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
onlineStatusWindow.loadURL(`file://${__dirname}/index.html`)
})
```

in the `index.html` file, add the following line before the
closing `</body>` tag:

```html
<script src="renderer.js"></script>
Starting with an HTML file `index.html`, this example will demonstrate how the `navigator.onLine` API can be used to build a connection status indicator.

```html title="index.html"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<h1>Connection status: <strong id='status'></strong></h1>
<script src="renderer.js"></script>
</body>
</html>
```

and add the `renderer.js` file:
In order to mutate the DOM, create a `renderer.js` file that adds event listeners to the `'online'` and `'offline'` `window` events. The event handler sets the content of the `<strong id='status'>` element depending on the result of `navigator.onLine`.

```javascript fiddle='docs/fiddles/features/online-detection/renderer'
const alertOnlineStatus = () => { window.alert(navigator.onLine ? 'online' : 'offline') }
```js title='renderer.js'
function updateOnlineStatus () {
document.getElementById('status').innerHTML = navigator.onLine ? 'online' : 'offline'
}

window.addEventListener('online', alertOnlineStatus)
window.addEventListener('offline', alertOnlineStatus)
window.addEventListener('online', updateOnlineStatus)
window.addEventListener('offline', updateOnlineStatus)

alertOnlineStatus()
updateOnlineStatus()
```

After launching the Electron application, you should see the notification:

![Online-offline-event detection](../images/online-event-detection.png)

### Event detection in the Main process
Finally, create a `main.js` file for main process that creates the window.

There may be situations when you want to respond to online/offline events in
the Main process as well. The Main process, however, does not have a
`navigator` object and cannot detect these events directly. In this case, you
need to forward the events to the Main process using Electron's inter-process
communication (IPC) utilities.
```js title='main.js'
const { app, BrowserWindow } = require('electron')

Starting with a working application from the
[Quick Start Guide](quick-start.md), update the `main.js` file
with the following lines:
function createWindow () {
const onlineStatusWindow = new BrowserWindow({
width: 400,
height: 100
})

```javascript
const { app, BrowserWindow, ipcMain } = require('electron')
let onlineStatusWindow
onlineStatusWindow.loadFile('index.html')
}

app.whenReady().then(() => {
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false, webPreferences: { nodeIntegration: true } })
onlineStatusWindow.loadURL(`file://${__dirname}/index.html`)
})
createWindow()

ipcMain.on('online-status-changed', (event, status) => {
console.log(status)
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
```

in the `index.html` file, add the following line before the
closing `</body>` tag:

```html
<script src="renderer.js"></script>
```

and add the `renderer.js` file:

```javascript fiddle='docs/fiddles/features/online-detection/main'
const { ipcRenderer } = require('electron')
const updateOnlineStatus = () => { ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline') }

window.addEventListener('online', updateOnlineStatus)
window.addEventListener('offline', updateOnlineStatus)

updateOnlineStatus()
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
```

After launching the Electron application, you should see the notification in the
Console:

```sh
npm start
After launching the Electron application, you should see the notification:

> electron@1.0.0 start /electron
> electron .
![Connection status](../images/connection-status.png)

online
```
> Note: If you need to communicate the connection status to the main process, use the [IPC renderer](../api/ipc-renderer.md) API.
2 changes: 1 addition & 1 deletion docs/tutorial/support.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ until the maintainers feel the maintenance burden is too high to continue doing

### Currently supported versions

* 13.x.y
* 12.x.y
* 11.x.y
* 10.x.y

### End-of-life

Expand Down
4 changes: 0 additions & 4 deletions lib/renderer/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ require('@electron/internal/common/init');
// The global variable will be used by ipc for event dispatching
const v8Util = process._linkedBinding('electron_common_v8_util');

// Expose process.contextId
const contextId = v8Util.getHiddenValue<string>(global, 'contextId');
Object.defineProperty(process, 'contextId', { enumerable: true, value: contextId });

const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal') as typeof ipcRendererInternalModule;
const ipcRenderer = require('@electron/internal/renderer/api/ipc-renderer').default;

Expand Down
4 changes: 0 additions & 4 deletions lib/sandboxed_renderer/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ Object.defineProperty(preloadProcess, 'noDeprecation', {
}
});

// Expose process.contextId
const contextId = v8Util.getHiddenValue<string>(global, 'contextId');
Object.defineProperty(preloadProcess, 'contextId', { enumerable: true, value: contextId });

process.on('loaded', () => (preloadProcess as events.EventEmitter).emit('loaded'));
process.on('exit', () => (preloadProcess as events.EventEmitter).emit('exit'));
(process as events.EventEmitter).on('document-start', () => (preloadProcess as events.EventEmitter).emit('document-start'));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron",
"version": "14.0.0-nightly.20210523",
"version": "14.0.0-nightly.20210524",
"repository": "https://github.com/electron/electron",
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions shell/browser/resources/win/electron.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 14,0,0,20210523
PRODUCTVERSION 14,0,0,20210523
FILEVERSION 14,0,0,20210524
PRODUCTVERSION 14,0,0,20210524
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand Down
2 changes: 0 additions & 2 deletions shell/renderer/electron_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ void ElectronRendererClient::RunScriptsAtDocumentEnd(
void ElectronRendererClient::DidCreateScriptContext(
v8::Handle<v8::Context> renderer_context,
content::RenderFrame* render_frame) {
RendererClientBase::DidCreateScriptContext(renderer_context, render_frame);

// TODO(zcbenz): Do not create Node environment if node integration is not
// enabled.

Expand Down
2 changes: 0 additions & 2 deletions shell/renderer/electron_sandboxed_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ void ElectronSandboxedRendererClient::RunScriptsAtDocumentEnd(
void ElectronSandboxedRendererClient::DidCreateScriptContext(
v8::Handle<v8::Context> context,
content::RenderFrame* render_frame) {
RendererClientBase::DidCreateScriptContext(context, render_frame);

// Only allow preload for the main frame or
// For devtools we still want to run the preload_bundle script
// Or when nodeSupport is explicitly enabled in sub frames
Expand Down
Loading