Skip to content

Commit

Permalink
React/Redux devtools now preloaded in electron
Browse files Browse the repository at this point in the history
  • Loading branch information
reZach committed Jan 4, 2020
1 parent 72952a2 commit 33f1086
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
26 changes: 24 additions & 2 deletions app/electron/main.js
Expand Up @@ -8,11 +8,28 @@ const isDev = process.env.NODE_ENV === "development";
const port = 40992; // Hardcoded; needs to match webpack.development.js and package.json
const selfHost = `http://localhost:${port}`;

// Installs extensions useful for development;
// https://github.com/electron-react-boilerplate/electron-react-boilerplate/blob/master/app/main.dev.js
// NOTE - if you'd like to run w/ these extensions when testing w/o electron, you need browser extensions to be installed (React Developer Tools & Redux DevTools)
const installExtensions = async () => {
const installer = require("electron-devtools-installer");
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
const extensions = ["REACT_DEVELOPER_TOOLS", "REDUX_DEVTOOLS"];

return Promise.all(
extensions.map(name => installer.default(installer[name], forceDownload))
).catch(console.log);
};

// Keep a global reference of the window object, if you don"t, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

function createWindow() {
async function createWindow() {
if (isDev){
await installExtensions();
}

// Create the browser window.
win = new BrowserWindow({
width: 800,
Expand All @@ -31,11 +48,16 @@ function createWindow() {
// Load app
if (isDev) {
win.loadURL(selfHost);
win.webContents.openDevTools();
} else {
win.loadFile(path.join(__dirname, "../dist/index.html"));
}

// Only do these things when in development
if (isDev) {
win.webContents.openDevTools();
require("electron-debug")(); // https://github.com/sindresorhus/electron-debug
}

// Emitted when the window is closed.
win.on("closed", () => {
// Dereference the window object, usually you would store windows
Expand Down
70 changes: 70 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -33,6 +33,8 @@
"cross-env": "^6.0.3",
"csp-html-webpack-plugin": "^3.0.4",
"electron": "^7.1.7",
"electron-debug": "^3.0.1",
"electron-devtools-installer": "^2.2.4",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"opener": "^1.5.1",
Expand Down

0 comments on commit 33f1086

Please sign in to comment.