Skip to content

Commit fc1d878

Browse files
fix: only allow installs from the main process
BREAKING CHANGE
1 parent a5dfe4c commit fc1d878

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,24 @@ yarn add electron-devtools-installer -D
2323
```
2424

2525
## Usage
26-
In your `electron-starter.js` file, add the following callback to `app.on('ready', ... )`,
26+
All you have to do now is this in the **main** process of your application.
2727

2828
```js
29-
const { default: installExtension, REDUX_DEVTOOLS } = require('electron-devtools-installer');
30-
const { app, BrowserWindow } = require('electron');
29+
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer';
30+
// Or if you can not use ES6 imports
31+
/**
32+
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
33+
*/
34+
const { app } = require('electron');
3135

32-
app.on('ready', () => {
36+
app.whenReady().then(() => {
3337
installExtension(REDUX_DEVTOOLS)
3438
.then((name) => console.log(`Added Extension: ${name}`))
3539
.catch((err) => console.log('An error occurred: ', err));
3640
});
3741
```
3842
To install multiple extensions, `installExtension` takes an array.
3943

40-
Alternatively, using `require()` and destructuring (node v6 or higher) you can
41-
42-
```js
43-
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
44-
45-
installExtension(REACT_DEVELOPER_TOOLS)
46-
.then((name) => console.log(`Added Extension: ${name}`))
47-
.catch((err) => console.log('An error occurred: ', err));
48-
```
49-
5044
## What extensions can I use?
5145

5246
Technically you can use whatever extension you want. Simply find the ChromeStore ID

src/utils.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import electron, { remote } from 'electron';
1+
import { net } from 'electron';
22
import fs from 'fs';
33
import path from 'path';
44
import https from 'https';
@@ -9,22 +9,26 @@ export const getPath = () => {
99
};
1010

1111
// Use https.get fallback for Electron < 1.4.5
12-
const { net } = remote || electron;
1312
const request = net ? net.request : https.get;
1413

15-
export const downloadFile = (from, to) =>
16-
new Promise((resolve, reject) => {
14+
export const downloadFile = (from, to) => {
15+
if (process.type !== 'browser') {
16+
return Promise.reject(new Error('electron-devtools-installer can only be used from the main process'));
17+
}
18+
return new Promise((resolve, reject) => {
1719
const req = request(from);
1820
req.on('response', (res) => {
1921
// Shouldn't handle redirect with `electron.net`, this is for https.get fallback
2022
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
2123
return downloadFile(res.headers.location, to).then(resolve).catch(reject);
2224
}
2325
res.pipe(fs.createWriteStream(to)).on('close', resolve);
26+
res.on('error', reject);
2427
});
2528
req.on('error', reject);
2629
req.end();
2730
});
31+
}
2832

2933
export const changePermissions = (dir, mode) => {
3034
const files = fs.readdirSync(dir);

0 commit comments

Comments
 (0)