From bda2c52a0e10006ebf2933d0f8270fe708bf708d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 13 Feb 2018 14:50:52 +0100 Subject: [PATCH 1/3] Add menu for open Dev Tools and Chrome Dev Tools --- src/main/app.js | 32 ++++++++++++--------- src/main/menu.js | 73 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/src/main/app.js b/src/main/app.js index 0e2f3b00..83fcfa9b 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -24,6 +24,16 @@ const getWindowPosition = (height, width, display = screen.getPrimaryDisplay()) } } +const handleCloseWindow = w => e => { + if (!forceClose) { + e.preventDefault() + + if (w !== null) { + w.hide() + } + } +} + const getDefaultUrl = () => __DEV__ ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT || ''}` @@ -89,22 +99,16 @@ function createMainWindow() { const url = getDefaultUrl() if (devTools) { - window.webContents.openDevTools() + window.webContents.openDevTools({ + mode: 'detach', + }) } saveWindowSettings(window) window.loadURL(url) - window.on('close', e => { - if (!forceClose) { - e.preventDefault() - - if (mainWindow !== null) { - mainWindow.hide() - } - } - }) + window.on('close', handleCloseWindow(window)) window.webContents.on('devtools-opened', () => { window.focus() @@ -120,16 +124,16 @@ function createDevWindow() { const MIN_HEIGHT = 500 const MIN_WIDTH = 360 - const savedDimensions = db.getIn('settings', 'window.DevWindow.dimensions', {}) const savedPositions = db.getIn('settings', 'window.DevWindow.positions', null) - const width = savedDimensions.width || MIN_WIDTH - const height = savedDimensions.height || MIN_HEIGHT + const width = MIN_WIDTH + const height = MIN_HEIGHT const windowOptions = { ...defaultWindowOptions, ...(savedPositions !== null ? savedPositions : {}), fullscreenable: false, + resizable: false, height, minHeight: MIN_HEIGHT, minWidth: MIN_WIDTH, @@ -149,6 +153,8 @@ function createDevWindow() { window.loadURL(`${url}/#/dev`) + window.on('close', handleCloseWindow(window)) + window.on('ready-to-show', () => { window.show() }) diff --git a/src/main/menu.js b/src/main/menu.js index 38d9d9e0..aab71e94 100644 --- a/src/main/menu.js +++ b/src/main/menu.js @@ -1,30 +1,69 @@ -import { app, Menu } from 'electron' +import { BrowserWindow, app, Menu } from 'electron' + +const props = (predicate, values, defaultValue = {}) => (predicate ? values : defaultValue) const template = [ - ...(process.platform === 'darwin' - ? [ - { - label: app.getName(), - submenu: [ - { role: 'hide' }, - { role: 'hideothers' }, - { role: 'unhide' }, + ...props( + process.platform === 'darwin', + [ + { + label: app.getName(), + submenu: [ + { role: 'hide' }, + { role: 'hideothers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' }, + ], + }, + ], + [], + ), + ...props(process.platform === 'darwin' || __DEV__, [ + { + role: 'window', + submenu: [ + ...props( + __DEV__, + [ + { + label: 'App Dev Tools', + click() { + const devWindow = BrowserWindow.getAllWindows().find(w => w.name === 'DevWindow') + if (devWindow) { + devWindow.show() + } + }, + }, + { + label: 'Main Window Dev Tools', + click() { + const mainWindow = BrowserWindow.getAllWindows().find(w => w.name === 'MainWindow') + if (mainWindow) { + mainWindow.openDevTools({ + mode: 'detach', + }) + } + }, + }, { type: 'separator' }, - { role: 'quit' }, ], - }, - { - role: 'window', - submenu: [ + [], + ), + ...props( + process.platform === 'darwin', + [ { role: 'close' }, { role: 'minimize' }, { role: 'zoom' }, { type: 'separator' }, { role: 'front' }, ], - }, - ] - : []), + [], + ), + ], + }, + ]), ] export default Menu.buildFromTemplate(template) From c24a548fe171bd1d3ff1cf1bca2bbb92d62d59d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 13 Feb 2018 15:01:54 +0100 Subject: [PATCH 2/3] Add option for set devToolsMode, use DotenvWebpack --- README.md | 1 + package.json | 2 +- src/main/app.js | 2 +- src/main/menu.js | 2 +- webpack/plugins.js | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fcdc491d..8e4016ba 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ ``` SENTRY_URL=http://... +DEV_TOOLS_MODE=right|bottom|undocked|detach ``` #### Install dependencies diff --git a/package.json b/package.json index 662dd626..aab35bca 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "babel-preset-stage-0": "^6.24.1", "chance": "^1.0.13", "concurrently": "^3.5.1", - "dotenv": "^5.0.0", + "dotenv-webpack": "^1.5.4", "electron": "1.8.2", "electron-builder": "^20.0.4", "electron-devtools-installer": "^2.2.3", diff --git a/src/main/app.js b/src/main/app.js index 83fcfa9b..c13b4514 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -100,7 +100,7 @@ function createMainWindow() { if (devTools) { window.webContents.openDevTools({ - mode: 'detach', + mode: process.env.DEV_TOOLS_MODE, }) } diff --git a/src/main/menu.js b/src/main/menu.js index aab71e94..590b7b26 100644 --- a/src/main/menu.js +++ b/src/main/menu.js @@ -41,7 +41,7 @@ const template = [ const mainWindow = BrowserWindow.getAllWindows().find(w => w.name === 'MainWindow') if (mainWindow) { mainWindow.openDevTools({ - mode: 'detach', + mode: process.env.DEV_TOOLS_MODE, }) } }, diff --git a/webpack/plugins.js b/webpack/plugins.js index 973c4577..cd40a36a 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -1,13 +1,13 @@ -require('dotenv').config() const webpack = require('webpack') +const Dotenv = require('dotenv-webpack') require('../src/globals') module.exports = [ + new Dotenv(), new webpack.DefinePlugin({ __DEV__, __PROD__, - __SENTRY_URL__: JSON.stringify(process.env.SENTRY_URL), 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ] From 2175e78afef805374e61d8d7e330c04334451175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 13 Feb 2018 15:04:44 +0100 Subject: [PATCH 3/3] __SENTRY_URL__ > process.env.SENTRY_URL --- src/internals/index.js | 6 +++--- src/main/index.js | 6 ++++-- src/renderer/index.js | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/internals/index.js b/src/internals/index.js index 71499d21..9d429c07 100644 --- a/src/internals/index.js +++ b/src/internals/index.js @@ -5,7 +5,7 @@ import capitalize from 'lodash/capitalize' import cpuUsage from 'helpers/cpuUsage' -const { FORK_TYPE } = process.env +const { FORK_TYPE, SENTRY_URL } = process.env process.title = `${require('../../package.json').productName} ${capitalize(FORK_TYPE)}` // eslint-disable-line global-require @@ -13,10 +13,10 @@ function sendEvent(type: string, data: any, options: Object = { kill: true }) { process.send({ type, data, options }) } -if (__PROD__ && __SENTRY_URL__) { +if (__PROD__ && SENTRY_URL) { const Raven = require('raven') // eslint-disable-line global-require const ravenConfig = { captureUnhandledRejections: true } - Raven.config(__SENTRY_URL__, ravenConfig).install() + Raven.config(SENTRY_URL, ravenConfig).install() } // $FlowFixMe diff --git a/src/main/index.js b/src/main/index.js index efda3b7a..36cc6b0b 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -9,8 +9,10 @@ require('./app') setImmediate(() => require('./bridge')) // eslint-disable-line global-require -if (__PROD__ && __SENTRY_URL__) { +const { SENTRY_URL } = process.env + +if (__PROD__ && SENTRY_URL) { const Raven = require('raven') // eslint-disable-line global-require const ravenConfig = { captureUnhandledRejections: true } - Raven.config(__SENTRY_URL__, ravenConfig).install() + Raven.config(SENTRY_URL, ravenConfig).install() } diff --git a/src/renderer/index.js b/src/renderer/index.js index 1a230513..5464977b 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -23,8 +23,10 @@ import App from 'components/App' import 'styles/global' -if (__PROD__ && __SENTRY_URL__) { - Raven.config(__SENTRY_URL__, { allowSecretKey: true }).install() +const { SENTRY_URL } = process.env + +if (__PROD__ && SENTRY_URL) { + Raven.config(SENTRY_URL, { allowSecretKey: true }).install() window.addEventListener('unhandledrejection', event => Raven.captureException(event.reason)) }