Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 28, 2019
1 parent a1ac261 commit 142b2de
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- 'node'
- '10'
12 changes: 9 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ export default function electronDebug(options?: Options): void;

/**
* Reload the specified `BrowserWindow` instance or the focused one.
*
* @param window - Default: `BrowserWindow.getFocusedWindow()`
*/
export function refresh(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;
export function refresh(window?: BrowserWindow): void;

/**
* Toggle DevTools for the specified `BrowserWindow` instance or the focused one.
*
* @param window - Default: `BrowserWindow.getFocusedWindow()`
*/
export function devTools(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;
export function devTools(window?: BrowserWindow): void;

/**
* Open DevTools for the specified `BrowserWindow` instance or the focused one.
*
* @param window - Default: `BrowserWindow.getFocusedWindow()`
*/
export function openDevTools(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;
export function openDevTools(window?: BrowserWindow): void;
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ const addExtensionIfInstalled = (name, getPath) => {
} catch (_) {}
};

module.exports = opts => {
opts = Object.assign({
module.exports = options => {
options = Object.assign({
enabled: null,
showDevTools: true,
devToolsMode: 'undocked'
}, opts);
}, options);

if (opts.enabled === false || (opts.enabled === null && !isDev)) {
if (options.enabled === false || (options.enabled === null && !isDev)) {
return;
}

if (opts.devToolsMode !== 'previous') {
devToolsOptions.mode = opts.devToolsMode;
if (options.devToolsMode !== 'previous') {
devToolsOptions.mode = options.devToolsMode;
}

app.on('browser-window-created', (event, win) => {
if (opts.showDevTools) {
if (options.showDevTools) {
win.webContents.once('devtools-opened', () => {
// Workaround for https://github.com/electron/electron/issues/13095
setImmediate(() => {
Expand All @@ -92,7 +92,7 @@ module.exports = opts => {

/// Workaround for https://github.com/electron/electron/issues/12438
win.webContents.once('dom-ready', () => {
openDevTools(win, opts.showDevTools);
openDevTools(win, options.showDevTools);
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {BrowserWindow} from 'electron';
import electronDebug, {refresh, devTools, openDevTools} from '.';

expectType<void>(electronDebug({
enabled: true,
showDevTools: true
enabled: true,
showDevTools: true
}));

expectType<void>(refresh(new BrowserWindow()));
Expand Down
11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ $ npm install electron-debug

```js
const {app, BrowserWindow} = require('electron');
const debug = require('electron-debug');

require('electron-debug')();
debug();

let win;

app.on('ready', () => {
(async () => {
await app.whenReady();
win = new BrowserWindow();
});
})();
```


Expand All @@ -75,6 +76,8 @@ Install keyboard shortcuts and optionally activate DevTools on each created `Bro

#### options

Type: `Object`

##### enabled

Type: `boolean`
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
const electron = require('electron');
const debug = require('.');

require('.')();
debug();

function load(url) {
const win = new electron.BrowserWindow({show: true});
Expand Down

0 comments on commit 142b2de

Please sign in to comment.