Add devtools in production mode

This commit is contained in:
GHOSCHT 2021-07-10 19:57:14 +02:00
parent 12168899d1
commit 7cbafad5d9
3 changed files with 43 additions and 13 deletions

View file

@ -58,6 +58,7 @@
"electron-acrylic-window": "^0.5.5",
"electron-devtools-installer": "^3.2.0",
"electron-is-dev": "^2.0.0",
"electron-localshortcut": "^3.2.1",
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^9.0.1",
"react": "^16.13.1",

View file

@ -5,20 +5,16 @@ const { BrowserWindow } = require("electron-acrylic-window");
const { app, Tray, Menu } = require("electron");
const isDev = require("electron-is-dev");
const screenz = require("screenz");
const els = require("electron-localshortcut");
const devTools = require("electron-devtools-installer");
let tray = null;
let mainWindow = null;
const gotTheLock = app.requestSingleInstanceLock();
// Conditionally include the dev tools installer to load React Dev Tools
let installExtension;
let REACT_DEVELOPER_TOOLS;
if (isDev) {
const devTools = require("electron-devtools-installer");
installExtension = devTools.default;
REACT_DEVELOPER_TOOLS = devTools.REACT_DEVELOPER_TOOLS;
}
const installExtension = devTools.default;
const { REACT_DEVELOPER_TOOLS } = devTools;
// Handle creating/removing shortcuts on Windows when installing/uninstalling
if (require("electron-squirrel-startup")) {
@ -68,6 +64,16 @@ function createWindow() {
if (isDev) {
win.webContents.openDevTools({ mode: "detach" });
}
// Register shortcut to open devtools
els.register(win, "Ctrl+Shift+I", () => {
if (win.webContents.isDevToolsOpened()) {
win.webContents.closeDevTools();
} else {
win.webContents.openDevTools({ mode: "detach" });
}
});
return win;
}
@ -132,11 +138,9 @@ if (!gotTheLock) {
app.allowRendererProcessReuse = false;
mainWindow = createWindow();
if (isDev) {
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((error) => console.log(`An error occurred: , ${error}`));
}
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((error) => console.log(`An error occurred: , ${error}`));
mainWindow.setMenu(null);

View file

@ -3227,11 +3227,26 @@ electron-devtools-installer@^3.2.0:
tslib "^2.1.0"
unzip-crx-3 "^0.2.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@^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.2.1:
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-publish@22.11.7:
version "22.11.7"
resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-22.11.7.tgz#4126cbb08ccf082a2aa7fef89ee629b3a4b8ae9a"
@ -5195,6 +5210,16 @@ jszip@^3.1.0:
readable-stream "~2.3.6"
set-immediate-shim "~1.0.1"
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==
keyv@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9"