From 77c26638e1f21f6145a72ce81289ec6b1622f48d Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Mon, 19 Sep 2022 15:36:40 +0200 Subject: [PATCH] Fully replace electron-debug with our own implementation (#2585) --- _scripts/webpack.main.config.js | 4 ---- package.json | 1 - src/main/index.js | 31 ++++++++++++++++++++++----- yarn.lock | 38 --------------------------------- 4 files changed, 26 insertions(+), 48 deletions(-) diff --git a/_scripts/webpack.main.config.js b/_scripts/webpack.main.config.js index d4df75f2..fb1ad736 100644 --- a/_scripts/webpack.main.config.js +++ b/_scripts/webpack.main.config.js @@ -14,10 +14,6 @@ const config = { entry: { main: path.join(__dirname, '../src/main/index.js'), }, - // webpack spits out errors while inlining electron-debug as - // it tries to dynamically load dependencies - // the error: "Critical dependency: the request of a dependency is an expression" - externals: ['electron-debug'], module: { rules: [ { diff --git a/package.json b/package.json index 18913c2a..3f8c1e7f 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,6 @@ "css-minimizer-webpack-plugin": "^4.1.0", "electron": "^20.1.4", "electron-builder": "^23.3.3", - "electron-debug": "^3.2.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-config-standard": "^16.0.3", diff --git a/src/main/index.js b/src/main/index.js index 7c733b7c..59d698bd 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -80,10 +80,6 @@ function runApp() { } } }) - } else { - require('electron-debug')({ - showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true') - }) } app.on('ready', async (_, __) => { @@ -303,10 +299,20 @@ function runApp() { // Show when loaded newWindow.once('ready-to-show', () => { - if (newWindow.isVisible()) { return } + if (newWindow.isVisible()) { + // only open the dev tools if they aren't already open + if (isDev && !newWindow.webContents.isDevToolsOpened()) { + newWindow.webContents.openDevTools({ activate: false }) + } + return + } newWindow.show() newWindow.focus() + + if (isDev) { + newWindow.webContents.openDevTools({ activate: false }) + } }) newWindow.once('close', async () => { @@ -816,6 +822,21 @@ function runApp() { accelerator: 'CmdOrCtrl+Shift+R' }, { role: 'toggledevtools' }, + { role: 'toggledevtools', accelerator: 'f12', visible: false }, + { + label: 'Enter Inspect Element Mode', + accelerator: 'CmdOrCtrl+Shift+C', + click: (_, window) => { + if (window.webContents.isDevToolsOpened()) { + window.devToolsWebContents.executeJavaScript('DevToolsAPI.enterInspectElementMode()') + } else { + window.webContents.once('devtools-opened', () => { + window.devToolsWebContents.executeJavaScript('DevToolsAPI.enterInspectElementMode()') + }) + window.webContents.openDevTools() + } + } + }, { type: 'separator' }, { role: 'resetzoom' }, { role: 'resetzoom', accelerator: 'CmdOrCtrl+num0', visible: false }, diff --git a/yarn.lock b/yarn.lock index d13a4677..06aaaa05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3159,14 +3159,6 @@ electron-context-menu@^3.1.2: electron-dl "^3.2.1" electron-is-dev "^2.0.0" -electron-debug@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/electron-debug/-/electron-debug-3.2.0.tgz#46a15b555c3b11872218c65ea01d058aa0814920" - integrity sha512-7xZh+LfUvJ52M9rn6N+tPuDw6oRAjxUj9SoxAZfJ0hVCXhZCsdkrSt7TgXOiWiEOBgEV8qwUIO/ScxllsPS7ow== - dependencies: - electron-is-dev "^1.1.0" - electron-localshortcut "^3.1.0" - electron-dl@^3.2.1: version "3.3.1" resolved "https://registry.yarnpkg.com/electron-dl/-/electron-dl-3.3.1.tgz#14164595bebcc636c671eb791b2a3265003f76c4" @@ -3176,31 +3168,11 @@ electron-dl@^3.2.1: pupa "^2.0.1" unused-filename "^2.1.0" -electron-is-accelerator@^0.1.0: - version "0.1.2" - resolved "https://registry.yarnpkg.com/electron-is-accelerator/-/electron-is-accelerator-0.1.2.tgz#509e510c26a56b55e17f863a4b04e111846ab27b" - integrity sha1-UJ5RDCala1Xhf4Y6SwThEYRqsns= - -electron-is-dev@^1.1.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.2.0.tgz#2e5cea0a1b3ccf1c86f577cee77363ef55deb05e" - integrity sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw== - electron-is-dev@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-2.0.0.tgz#833487a069b8dad21425c67a19847d9064ab19bd" integrity sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA== -electron-localshortcut@^3.1.0: - version "3.2.1" - resolved "https://registry.yarnpkg.com/electron-localshortcut/-/electron-localshortcut-3.2.1.tgz#cfc83a3eff5e28faf98ddcc87f80a2ce4f623cd3" - integrity sha512-DWvhKv36GsdXKnaFFhEiK8kZZA+24/yFLgtTwJJHc7AFgDjNRIBJZ/jq62Y/dWv9E4ypYwrVWN2bVrCYw1uv7Q== - dependencies: - debug "^4.0.1" - electron-is-accelerator "^0.1.0" - keyboardevent-from-electron-accelerator "^2.0.0" - keyboardevents-areequal "^0.2.1" - electron-osx-sign@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.6.0.tgz#9b69c191d471d9458ef5b1e4fdd52baa059f1bb8" @@ -4890,16 +4862,6 @@ jsprim@^1.2.2: json-schema "0.4.0" verror "1.10.0" -keyboardevent-from-electron-accelerator@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/keyboardevent-from-electron-accelerator/-/keyboardevent-from-electron-accelerator-2.0.0.tgz#ace21b1aa4e47148815d160057f9edb66567c50c" - integrity sha512-iQcmNA0M4ETMNi0kG/q0h/43wZk7rMeKYrXP7sqKIJbHkTU8Koowgzv+ieR/vWJbOwxx5nDC3UnudZ0aLSu4VA== - -keyboardevents-areequal@^0.2.1: - version "0.2.2" - resolved "https://registry.yarnpkg.com/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz#88191ec738ce9f7591c25e9056de928b40277194" - integrity sha512-Nv+Kr33T0mEjxR500q+I6IWisOQ0lK1GGOncV0kWE6n4KFmpcu7RUX5/2B0EUtX51Cb0HjZ9VJsSY3u4cBa0kw== - keycode@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.2.1.tgz#09c23b2be0611d26117ea2501c2c391a01f39eff"