diff --git a/index.d.ts b/index.d.ts index cf84001..b1e79e9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,7 +5,7 @@ declare namespace electronDebug { /** Default: [Only in development](https://github.com/sindresorhus/electron-is-dev) */ - readonly enabled?: boolean; + readonly isEnabled?: boolean; /** Show DevTools on each created `BrowserWindow`. diff --git a/index.js b/index.js index a46d8d9..30626b4 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,8 @@ 'use strict'; -const electron = require('electron'); +const {app, BrowserWindow} = require('electron'); const localShortcut = require('electron-localshortcut'); const isDev = require('electron-is-dev'); -const {app, BrowserWindow} = electron; const isMacOS = process.platform === 'darwin'; const devToolsOptions = {}; @@ -67,13 +66,14 @@ const addExtensionIfInstalled = (name, getPath) => { }; module.exports = options => { - options = Object.assign({ - enabled: null, + options = { + isEnabled: null, showDevTools: true, - devToolsMode: 'undocked' - }, options); + devToolsMode: 'undocked', + ...options + }; - if (options.enabled === false || (options.enabled === null && !isDev)) { + if (options.isEnabled === false || (options.isEnabled === null && !isDev)) { return; } @@ -97,7 +97,9 @@ module.exports = options => { } }); - app.on('ready', () => { + (async () => { + await app.whenReady(); + addExtensionIfInstalled('devtron', name => require(name).path); addExtensionIfInstalled('electron-react-devtools', name => require(name).path); @@ -107,7 +109,7 @@ module.exports = options => { localShortcut.register('CmdOrCtrl+R', refresh); localShortcut.register('F5', refresh); - }); + })(); }; // TODO: Remove this for the next major release diff --git a/index.test-d.ts b/index.test-d.ts index ef3354b..39d64d5 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -7,7 +7,7 @@ import {refresh, devTools, openDevTools} from '.'; expectType( electronDebug({ - enabled: true, + isEnabled: true, showDevTools: true }) ); diff --git a/readme.md b/readme.md index 7361d88..ace9d01 100644 --- a/readme.md +++ b/readme.md @@ -43,7 +43,7 @@ Just install any of these extension and they'll be activated for you: $ npm install electron-debug ``` -*Requires Electron 2.0.0 or later.* +*Requires Electron 4 or later.* @@ -68,7 +68,7 @@ let win; ## API -Only runs when in [development](https://github.com/sindresorhus/electron-is-dev), unless overridden by the `enabled` option. So no need to guard it for production. +Only runs when in [development](https://github.com/sindresorhus/electron-is-dev), unless overridden by the `isEnabled` option. So no need to guard it for production. ### electronDebug([options]) @@ -78,7 +78,7 @@ Install keyboard shortcuts and optionally activate DevTools on each created `Bro Type: `Object` -##### enabled +##### isEnabled Type: `boolean`