From d7ab8c41280908fcbe29d4cd706e99c4ec391b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Mon, 28 May 2018 16:30:14 +0200 Subject: [PATCH] Remove app devtools --- src/components/App.js | 2 - src/components/DevTools.js | 298 ----------------------------------- src/components/layout/Dev.js | 29 ---- src/helpers/cpuUsage.js | 43 ----- src/internals/index.js | 20 +-- src/main/app.js | 57 +------ src/main/bridge.js | 11 -- src/main/menu.js | 9 -- 8 files changed, 2 insertions(+), 467 deletions(-) delete mode 100644 src/components/DevTools.js delete mode 100644 src/components/layout/Dev.js delete mode 100644 src/helpers/cpuUsage.js diff --git a/src/components/App.js b/src/components/App.js index dd659344..8a1898e4 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -16,7 +16,6 @@ import Onboarding from 'components/Onboarding' import ThrowBlock from 'components/ThrowBlock' import Default from 'components/layout/Default' -import Dev from 'components/layout/Dev' import Print from 'components/layout/Print' import CounterValues from 'helpers/countervalues' import { BridgeSyncProvider } from 'bridge/BridgeSyncContext' @@ -41,7 +40,6 @@ const App = ({ - {(__DEV__ || DEV_TOOLS) && } diff --git a/src/components/DevTools.js b/src/components/DevTools.js deleted file mode 100644 index 9baa004c..00000000 --- a/src/components/DevTools.js +++ /dev/null @@ -1,298 +0,0 @@ -// @flow - -/* eslint-disable import/no-named-as-default-member */ - -import React, { PureComponent } from 'react' -import { remote, ipcRenderer } from 'electron' -import { translate } from 'react-i18next' -import styled from 'styled-components' -import color from 'color' -import fs from 'fs' -import path from 'path' - -import takeRight from 'lodash/takeRight' -import last from 'lodash/last' -import reduce from 'lodash/fp/reduce' -import flow from 'lodash/fp/flow' -import filter from 'lodash/fp/filter' -import sortBy from 'lodash/fp/sortBy' -import chunk from 'lodash/chunk' - -import Chart from 'components/base/Chart' -import Box from 'components/base/Box' -import Bar from 'components/base/Bar' -import CopyToClipboard from 'components/base/CopyToClipboard' - -import staticPath from 'helpers/staticPath' - -import theme from 'styles/theme' - -const getLanguages = p => fs.readdirSync(p).filter(f => fs.statSync(path.join(p, f)).isDirectory()) -const languages = getLanguages(path.join(staticPath, '/i18n')) - -const mainWindow = remote.BrowserWindow.getAllWindows().find(w => w.name === 'MainWindow') - -type HslColor = { - color: Array, -} - -type ColorType = { - name: string, - val: string, - isDark: boolean, - color: { - isDark: () => boolean, - hsl: () => HslColor, - }, -} - -type SimpleType = { - name: string, - val: string, -} - -const transform = flow( - reduce.convert({ cap: false })((acc, cur, key) => { - const c = color(cur) - return [ - ...acc, - { - name: key, - val: cur, - color: c, - isDark: c.isDark(), - }, - ] - }, []), - filter(el => el.name !== 'transparent'), - sortBy(el => el.color.hsl().color[2]), -) - -const colors: Array = transform(theme.colors) -const spaces: Array = theme.space.map((s, i) => ({ - name: s.toString(), - val: i.toString(), -})) -const fontSizes: Array = theme.fontSizes.map((s, i) => ({ - name: s.toString(), - val: i.toString(), -})) - -const Container = styled(Box).attrs({ - bg: 'dark', - p: 5, - grow: true, - color: 'white', - fontSize: 3, -})`` - -const Title = styled(Box).attrs({ - color: 'white', -})` - text-transform: uppercase; -` - -const Items = styled(Box).attrs({ - horizontal: true, - flow: 4, -})`` - -const Item = styled(Box).attrs({ - alignItems: 'center', - bg: 'dark', - borderRadius: 1, - color: 'white', - justifyContent: 'center', - py: 2, - px: 4, -})` - border: 2px solid ${p => p.theme.colors.white}; - flex: 1; - overflow: hidden; - cursor: pointer; -` - -type State = { - cpuUsage: Object, -} - -class DevTools extends PureComponent { - state = { - cpuUsage: {}, - } - - componentDidMount() { - ipcRenderer.on('msg', this.handleMessage) - } - - componentWillUnmount() { - ipcRenderer.removeListener('msg', this.handleMessage) - } - - handleMessage = (e: any, { type, data }: Object) => { - if (type === 'usage.cpu') { - this.setState(prev => ({ - cpuUsage: { - ...prev.cpuUsage, - [data.name]: takeRight( - [ - ...(prev.cpuUsage[data.name] || []), - { - date: new Date().getTime().toString(), - value: parseFloat(data.value), - }, - ], - 10, - ), - }, - })) - } - } - - handleChangeLanguage = lang => () => { - mainWindow.webContents.send('msg', { - type: 'application.changeLanguage', - data: lang, - }) - } - - handleStartSync = () => - mainWindow.webContents.send('msg', { - type: 'accounts.sync.start', - }) - - handleStopSync = () => - mainWindow.webContents.send('msg', { - type: 'accounts.sync.stop', - }) - - render() { - const { cpuUsage } = this.state - - return ( - - -
- {chunk(colors, 5).map((c, i) => ( - - {c.map(color => ( - } - /> - ))} - - ))} -
-
- {chunk(spaces, 5).map((s, i) => ( - - {s.map(space => ( - {space.name}} - /> - ))} - - ))} -
-
- {chunk(fontSizes, 5).map((f, i) => ( - - {f.map(fontSize => ( - {fontSize.name}} - /> - ))} - - ))} -
- -
- {languages.map(lang => ( - - {lang} - - ))} -
- -
- - Start - - - Stop - -
- -
- {chunk(Object.keys(cpuUsage).sort(), 2).map((l, i) => ( - - {l.map(k => ( - - - {last(cpuUsage[k]).value}% - {k} - - - - - - ))} - - ))} -
-
-
- ) - } -} - -const Color = ({ onClick, color }: { onClick: Function, color: ColorType }) => ( - - {color.name} - -) - -const Section = ({ - title, - children, - horizontal, -}: { - title: string, - children: any, - horizontal?: boolean, -}) => ( - - {title} - - {children} - - -) - -Section.defaultProps = { - horizontal: false, -} - -export default translate()(DevTools) diff --git a/src/components/layout/Dev.js b/src/components/layout/Dev.js deleted file mode 100644 index c8ffdd24..00000000 --- a/src/components/layout/Dev.js +++ /dev/null @@ -1,29 +0,0 @@ -// @flow - -import React, { PureComponent } from 'react' -import styled from 'styled-components' - -import Box from 'components/base/Box' -import GrowScroll from 'components/base/GrowScroll' - -import DevTools from 'components/DevTools' - -const Container = styled(Box).attrs({ - grow: true, -})` - height: 100%; -` - -class Dev extends PureComponent<{}> { - render() { - return ( - - - - - - ) - } -} - -export default Dev diff --git a/src/helpers/cpuUsage.js b/src/helpers/cpuUsage.js deleted file mode 100644 index e21d03ad..00000000 --- a/src/helpers/cpuUsage.js +++ /dev/null @@ -1,43 +0,0 @@ -const TIMEOUT_CPU_USAGE = 5e3 - -const wait = ms => new Promise(resolve => setTimeout(resolve, ms)) - -const cpuUsage = async (startTime, startUsage) => { - await wait(500) - - const newStartTime = process.hrtime() - const newStartUsage = process.cpuUsage() - - const elapTime = process.hrtime(startTime) - const elapUsage = process.cpuUsage(startUsage) - - startTime = newStartTime - startUsage = newStartUsage - - const elapTimeMS = elapTime[0] * 1e3 + elapTime[1] / 1e6 - - const elapUserMS = elapUsage.user / 1e3 - const elapSystMS = elapUsage.system / 1e3 - const cpuPercent = (100 * (elapUserMS + elapSystMS) / elapTimeMS).toFixed(1) - - return { - cpuPercent, - newStartTime: startTime, - newStartUsage: startUsage, - } -} - -export default callback => { - const initCpuUsage = async (startTime, startUsage) => { - const { cpuPercent, newStartTime, newStartUsage } = await cpuUsage(startTime, startUsage) - - callback(cpuPercent) - - setTimeout(() => initCpuUsage(newStartTime, newStartUsage), TIMEOUT_CPU_USAGE) - } - - const startTime = process.hrtime() - const startUsage = process.cpuUsage() - - initCpuUsage(startTime, startUsage) -} diff --git a/src/internals/index.js b/src/internals/index.js index 4cc59b34..36ec3c28 100644 --- a/src/internals/index.js +++ b/src/internals/index.js @@ -3,12 +3,10 @@ import objectPath from 'object-path' import capitalize from 'lodash/capitalize' -import cpuUsage from 'helpers/cpuUsage' - require('../env') require('../init-sentry') -const { DEV_TOOLS, FORK_TYPE } = process.env +const { FORK_TYPE } = process.env process.title = `${require('../../package.json').productName} ${capitalize(FORK_TYPE)}` @@ -44,19 +42,3 @@ process.on('message', payload => { handler(sendEvent, data) } }) - -if (__DEV__ || DEV_TOOLS) { - cpuUsage(cpuPercent => - sendEvent( - 'usage.cpu', - { - name: FORK_TYPE, - value: cpuPercent, - }, - { - window: 'DevWindow', - kill: false, - }, - ), - ) -} diff --git a/src/main/app.js b/src/main/app.js index 01f35768..e923e21f 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -15,13 +15,7 @@ let mainWindow = null let forceClose = false -const { - UPGRADE_EXTENSIONS, - ELECTRON_WEBPACK_WDS_PORT, - DEV_TOOLS, - DEV_TOOLS_MODE, - HIDE_DEV_WINDOW, -} = process.env +const { UPGRADE_EXTENSIONS, ELECTRON_WEBPACK_WDS_PORT, DEV_TOOLS, DEV_TOOLS_MODE } = process.env const devTools = __DEV__ || DEV_TOOLS @@ -204,51 +198,6 @@ function createMainWindow() { return window } -function createDevWindow() { - const MIN_HEIGHT = 500 - const MIN_WIDTH = 360 - - const savedPositions = db.getIn('settings', 'window.DevWindow.positions', null) - - 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, - show: false, - skipTaskbar: true, - title: 'Dev Tools', - width, - } - - const window = new BrowserWindow(windowOptions) - - window.name = 'DevWindow' - - const url = getDefaultUrl() - - saveWindowSettings(window) - - window.loadURL(`${url}#/dev`) - - window.setMenu(null) - - window.on('close', handleCloseWindow(window)) - - window.on('ready-to-show', () => window.show()) - - // Don't want to use HTML - window.on('page-title-updated', e => e.preventDefault()) - - return window -} - app.on('before-quit', () => { forceClose = true }) @@ -287,10 +236,6 @@ app.on('ready', async () => { await installExtensions() } - if (devTools && !HIDE_DEV_WINDOW) { - createDevWindow() - } - Menu.setApplicationMenu(menu) mainWindow = createMainWindow() diff --git a/src/main/bridge.js b/src/main/bridge.js index 75f0948f..efe03485 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -6,8 +6,6 @@ import { BrowserWindow, ipcMain, app } from 'electron' import objectPath from 'object-path' import path from 'path' -import cpuUsage from 'helpers/cpuUsage' - import setupAutoUpdater, { quitAndInstall } from './autoUpdate' const { DEV_TOOLS } = process.env @@ -100,12 +98,3 @@ ipcMain.on('msg', (event: any, payload) => { const send = (type: string, data: *) => event.sender.send('msg', { type, data }) handler(send, data, type) }) - -if (__DEV__ || DEV_TOOLS) { - cpuUsage(cpuPercent => - sendEventToWindow('DevWindow', { - type: 'usage.cpu', - data: { name: 'main', value: cpuPercent }, - }), - ) -} diff --git a/src/main/menu.js b/src/main/menu.js index 9d997036..a0001f40 100644 --- a/src/main/menu.js +++ b/src/main/menu.js @@ -44,15 +44,6 @@ const template = [ ...props( __DEV__ || DEV_TOOLS, [ - { - label: 'App Dev Tools', - click() { - const devWindow = BrowserWindow.getAllWindows().find(w => w.name === 'DevWindow') - if (devWindow) { - devWindow.show() - } - }, - }, { label: 'Main Window Dev Tools', click() {