electron-debug
Advanced tools
Comparing version 3.2.0 to 4.0.0
115
index.d.ts
@@ -1,80 +0,67 @@ | ||
import {BrowserWindow} from 'electron'; | ||
import {type BrowserWindow} from 'electron'; | ||
declare namespace electronDebug { | ||
interface Options { | ||
/** | ||
Default: [Only in development](https://github.com/sindresorhus/electron-is-dev) | ||
*/ | ||
readonly isEnabled?: boolean; | ||
export type Options = { | ||
/** | ||
Default: [Only in development](https://github.com/sindresorhus/electron-is-dev) | ||
*/ | ||
readonly isEnabled?: boolean; | ||
/** | ||
Show DevTools on each created `BrowserWindow`. | ||
/** | ||
Show DevTools on each created `BrowserWindow`. | ||
@default true | ||
*/ | ||
readonly showDevTools?: boolean; | ||
@default true | ||
*/ | ||
readonly showDevTools?: boolean; | ||
/** | ||
The dock state to open DevTools in. | ||
@default 'previous' | ||
*/ | ||
readonly devToolsMode?: | ||
| 'undocked' | ||
| 'right' | ||
| 'bottom' | ||
| 'previous' | ||
| 'detach'; | ||
} | ||
} | ||
declare const electronDebug: { | ||
/** | ||
Install keyboard shortcuts and optionally activate DevTools on each created `BrowserWindow`. | ||
The dock state to open DevTools in. | ||
@example | ||
``` | ||
import {app, BrowserWindow} from 'electron'; | ||
import debug = require('electron-debug'); | ||
@default 'previous' | ||
*/ | ||
readonly devToolsMode?: | ||
| 'undocked' | ||
| 'right' | ||
| 'bottom' | ||
| 'previous' | ||
| 'detach'; | ||
}; | ||
debug(); | ||
/** | ||
Install keyboard shortcuts and optionally activate DevTools on each created `BrowserWindow`. | ||
let mainWindow; | ||
(async () => { | ||
await app.whenReady(); | ||
mainWindow = new BrowserWindow(); | ||
}); | ||
``` | ||
*/ | ||
(options?: electronDebug.Options): void; | ||
@example | ||
``` | ||
import {app, BrowserWindow} from 'electron'; | ||
import debug from 'electron-debug'; | ||
/** | ||
Reload the specified `BrowserWindow` instance or the focused one. | ||
debug(); | ||
@param window - Default: `BrowserWindow.getFocusedWindow()` | ||
*/ | ||
refresh(window?: BrowserWindow): void; | ||
let mainWindow; | ||
(async () => { | ||
await app.whenReady(); | ||
mainWindow = new BrowserWindow(); | ||
}); | ||
``` | ||
*/ | ||
export default function debug(options?: Options): void; | ||
/** | ||
Toggle DevTools for the specified `BrowserWindow` instance or the focused one. | ||
/** | ||
Reload the specified `BrowserWindow` instance or the focused one. | ||
@param window - Default: `BrowserWindow.getFocusedWindow()` | ||
*/ | ||
devTools(window?: BrowserWindow): void; | ||
@param window - Default: `BrowserWindow.getFocusedWindow()` | ||
*/ | ||
export function refresh(window?: BrowserWindow): void; | ||
/** | ||
Open DevTools for the specified `BrowserWindow` instance or the focused one. | ||
/** | ||
Toggle DevTools for the specified `BrowserWindow` instance or the focused one. | ||
@param window - Default: `BrowserWindow.getFocusedWindow()` | ||
*/ | ||
openDevTools(window?: BrowserWindow): void; | ||
@param window - Default: `BrowserWindow.getFocusedWindow()` | ||
*/ | ||
export function developmentTools(window?: BrowserWindow): void; | ||
/** | ||
The absolute path to a preload script to use in [`session#setPreloads()`](https://www.electronjs.org/docs/api/session#sessetpreloadspreloads). | ||
/** | ||
Open DevTools for the specified `BrowserWindow` instance or the focused one. | ||
Use it to enable `devtron` even when [`nodeIntegration`](https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions) is turned off. | ||
*/ | ||
preloadScriptPath: string; | ||
}; | ||
export = electronDebug; | ||
@param window - Default: `BrowserWindow.getFocusedWindow()` | ||
*/ | ||
export function openDevelopmentTools(window?: BrowserWindow): void; |
69
index.js
@@ -1,12 +0,11 @@ | ||
'use strict'; | ||
const {app, BrowserWindow, session} = require('electron'); | ||
const path = require('path'); | ||
const localShortcut = require('electron-localshortcut'); | ||
const isDev = require('electron-is-dev'); | ||
import process from 'node:process'; | ||
import {app, BrowserWindow} from 'electron'; | ||
import localShortcut from 'electron-localshortcut'; | ||
import isDev from 'electron-is-dev'; | ||
const isMacOS = process.platform === 'darwin'; | ||
const devToolsOptions = {}; | ||
const developmentToolsOptions = {}; | ||
function toggleDevTools(win = BrowserWindow.getFocusedWindow()) { | ||
function toggleDevelopmentTools(win = BrowserWindow.getFocusedWindow()) { | ||
if (win) { | ||
@@ -17,3 +16,3 @@ const {webContents} = win; | ||
} else { | ||
webContents.openDevTools(devToolsOptions); | ||
webContents.openDevTools(developmentToolsOptions); | ||
} | ||
@@ -23,15 +22,17 @@ } | ||
function devTools(win = BrowserWindow.getFocusedWindow()) { | ||
// eslint-disable-next-line unicorn/prevent-abbreviations | ||
export function devTools(win = BrowserWindow.getFocusedWindow()) { | ||
if (win) { | ||
toggleDevTools(win); | ||
toggleDevelopmentTools(win); | ||
} | ||
} | ||
function openDevTools(win = BrowserWindow.getFocusedWindow()) { | ||
// eslint-disable-next-line unicorn/prevent-abbreviations | ||
export function openDevTools(win = BrowserWindow.getFocusedWindow()) { | ||
if (win) { | ||
win.webContents.openDevTools(devToolsOptions); | ||
win.webContents.openDevTools(developmentToolsOptions); | ||
} | ||
} | ||
function refresh(win = BrowserWindow.getFocusedWindow()) { | ||
export function refresh(win = BrowserWindow.getFocusedWindow()) { | ||
if (win) { | ||
@@ -58,28 +59,3 @@ win.webContents.reloadIgnoringCache(); | ||
const addExtensionIfInstalled = (name, getPath) => { | ||
const isExtensionInstalled = name => { | ||
// For Electron >=9. | ||
if (session.defaultSession.getAllExtensions) { | ||
return {}.hasOwnProperty.call(session.defaultSession.getAllExtensions(), name); | ||
} | ||
// TODO: Remove this when targeting Electron >=9. | ||
return BrowserWindow.getDevToolsExtensions && | ||
{}.hasOwnProperty.call(BrowserWindow.getDevToolsExtensions(), name); | ||
}; | ||
try { | ||
if (!isExtensionInstalled(name)) { | ||
// For Electron >=9. | ||
if (session.defaultSession.loadExtension) { | ||
session.defaultSession.loadExtension(getPath(name)); | ||
} else { | ||
// TODO: Remove this when targeting Electron >=9. | ||
BrowserWindow.addDevToolsExtension(getPath(name)); | ||
} | ||
} | ||
} catch (_) {} | ||
}; | ||
module.exports = options => { | ||
export default function debug(options) { | ||
options = { | ||
@@ -89,3 +65,3 @@ isEnabled: null, | ||
devToolsMode: 'previous', | ||
...options | ||
...options, | ||
}; | ||
@@ -98,3 +74,3 @@ | ||
if (options.devToolsMode !== 'previous') { | ||
devToolsOptions.mode = options.devToolsMode; | ||
developmentToolsOptions.mode = options.devToolsMode; | ||
} | ||
@@ -114,17 +90,8 @@ | ||
addExtensionIfInstalled('devtron', name => require(name).path); | ||
addExtensionIfInstalled('electron-react-devtools', name => require(name).path); | ||
localShortcut.register('CommandOrControl+Shift+C', inspectElements); | ||
localShortcut.register(isMacOS ? 'Command+Alt+I' : 'Control+Shift+I', devTools); | ||
localShortcut.register('F12', devTools); | ||
localShortcut.register('CommandOrControl+R', refresh); | ||
localShortcut.register('F5', refresh); | ||
})(); | ||
}; | ||
module.exports.refresh = refresh; | ||
module.exports.devTools = devTools; | ||
module.exports.openDevTools = openDevTools; | ||
module.exports.preloadScriptPath = path.join(__dirname, 'preload.js'); | ||
} |
{ | ||
"name": "electron-debug", | ||
"version": "3.2.0", | ||
"version": "4.0.0", | ||
"description": "Adds useful debug features to your Electron app", | ||
@@ -13,10 +13,18 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"scripts": { | ||
"start": "electron test.js", | ||
"test": "xo && tsd" | ||
"test": "xo" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"preload.js" | ||
"index.d.ts" | ||
], | ||
@@ -33,12 +41,10 @@ "keywords": [ | ||
"dependencies": { | ||
"electron-is-dev": "^1.1.0", | ||
"electron-localshortcut": "^3.1.0" | ||
"electron-is-dev": "^3.0.1", | ||
"electron-localshortcut": "^3.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.0.0", | ||
"devtron": "^1.4.0", | ||
"electron": "^5.0.1", | ||
"@types/node": "^20.12.7", | ||
"electron": "^30.0.1", | ||
"electron-react-devtools": "^0.5.3", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"xo": "^0.58.0" | ||
}, | ||
@@ -45,0 +51,0 @@ "xo": { |
@@ -31,17 +31,9 @@ # electron-debug | ||
### Activates DevTools extensions | ||
Just install any of these extension and they'll be activated for you: | ||
- [devtron](https://electronjs.org/devtron) - The official Electron DevTools extension | ||
- You need to use [`preloadScriptPath`](#preloadScriptPath) if the `BrowserWindow`'s `nodeIntegration` is off. | ||
- [electron-react-devtools](https://github.com/firejune/electron-react-devtools) - React DevTools extension for Electron | ||
## Install | ||
```sh | ||
npm install electron-debug | ||
``` | ||
$ npm install electron-debug | ||
``` | ||
*Requires Electron 5 or later.* | ||
*Requires Electron 30 or later.* | ||
@@ -51,4 +43,4 @@ ## Usage | ||
```js | ||
const {app, BrowserWindow} = require('electron'); | ||
const debug = require('electron-debug'); | ||
import {app, BrowserWindow} from 'electron'; | ||
import debug from 'electron-debug'; | ||
@@ -122,14 +114,6 @@ debug(); | ||
### preloadScriptPath | ||
Type: `string` | ||
The absolute path to a preload script to use in [`session#setPreloads()`](https://www.electronjs.org/docs/api/session#sessetpreloadspreloads). | ||
Use it to enable `devtron` even when [`nodeIntegration`](https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions) is turned off. | ||
## Related | ||
- [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps and modules | ||
- [electron-store](https://github.com/sindresorhus/electron-store) - Save and load data like user preferences, app state, cache, etc | ||
- [electron-store](https://github.com/sindresorhus/electron-store) - Save and load data like user settings, app state, cache, etc | ||
- [electron-context-menu](https://github.com/sindresorhus/electron-context-menu) - Context menu for your Electron app | ||
@@ -140,2 +124,1 @@ - [electron-dl](https://github.com/sindresorhus/electron-dl) - Simplified file downloads for your Electron app | ||
- [electron-serve](https://github.com/sindresorhus/electron-serve) - Static file serving for Electron apps | ||
- [debug-menu](https://github.com/parro-it/debug-menu) - Chrome-like debug context-menu for Electron |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4
0
Yes
9014
5
129
121
+ Addedelectron-is-dev@3.0.1(transitive)
- Removedelectron-is-dev@1.2.0(transitive)
Updatedelectron-is-dev@^3.0.1