From 3315554e50fa9e29e0063aef630d29874c3ec349 Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 5 Dec 2018 13:04:27 -0300 Subject: [PATCH 1/5] lint: remove rule react/destructuring-assignment --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index afeb5e9..390923c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -43,6 +43,7 @@ "ignoreTrailingComments": true } ], - "consistent-return": 0 + "consistent-return": 0, + "react/destructuring-assignment": 0 } } From 5112ac9948fcfd8c58ed458e5644286c44eb20d0 Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 5 Dec 2018 13:32:13 -0300 Subject: [PATCH 2/5] feature: add console route --- app/constants/routes.js | 1 + app/constants/sidebar.js | 6 +++++- app/router/router.js | 5 ++++- app/views/console.js | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 app/views/console.js diff --git a/app/constants/routes.js b/app/constants/routes.js index 18a4e37..5120961 100644 --- a/app/constants/routes.js +++ b/app/constants/routes.js @@ -4,3 +4,4 @@ export const DASHBOARD_ROUTE = '/'; export const SEND_ROUTE = '/send'; export const RECEIVE_ROUTE = '/receive'; export const SETTINGS_ROUTE = '/settings'; +export const CONSOLE_ROUTE = '/console'; diff --git a/app/constants/sidebar.js b/app/constants/sidebar.js index 0434fca..d8d2988 100644 --- a/app/constants/sidebar.js +++ b/app/constants/sidebar.js @@ -1,7 +1,7 @@ // @flow import { - DASHBOARD_ROUTE, SEND_ROUTE, RECEIVE_ROUTE, SETTINGS_ROUTE, + DASHBOARD_ROUTE, SEND_ROUTE, RECEIVE_ROUTE, SETTINGS_ROUTE, CONSOLE_ROUTE, } from './routes'; export const MENU_OPTIONS = [ @@ -17,6 +17,10 @@ export const MENU_OPTIONS = [ label: 'Receive', route: RECEIVE_ROUTE, }, + { + label: 'Console', + route: CONSOLE_ROUTE, + }, { label: 'Settings', route: SETTINGS_ROUTE, diff --git a/app/router/router.js b/app/router/router.js index bcfa091..99756e5 100644 --- a/app/router/router.js +++ b/app/router/router.js @@ -10,9 +10,11 @@ import { SendView } from '../views/send'; import { ReceiveView } from '../views/receive'; import { SettingsView } from '../views/settings'; import { NotFoundView } from '../views/not-found'; +import { ConsoleView } from '../views/console'; import { LayoutComponent } from '../components/layout'; + import { - DASHBOARD_ROUTE, SEND_ROUTE, RECEIVE_ROUTE, SETTINGS_ROUTE, + DASHBOARD_ROUTE, SEND_ROUTE, RECEIVE_ROUTE, SETTINGS_ROUTE, CONSOLE_ROUTE, } from '../constants/routes'; export const RouterComponent = () => ( @@ -26,6 +28,7 @@ export const RouterComponent = () => ( + diff --git a/app/views/console.js b/app/views/console.js new file mode 100644 index 0000000..50a305a --- /dev/null +++ b/app/views/console.js @@ -0,0 +1,39 @@ +// @flow + +import React, { Component, Fragment } from 'react'; +/* eslint-disable-next-line import/no-extraneous-dependencies */ +import { ipcRenderer } from 'electron'; + +type Props = {}; + +type State = { + log: string | null, +}; + +export class ConsoleView extends Component { + state = { + log: null, + }; + + componentDidMount() { + ipcRenderer.on('zcashd-log', (event, message) => { + this.setState({ + log: message, + }); + }); + } + + render() { + return ( +
+ {this.state.log + && this.state.log.split('\n').map(item => ( + + {item} +
+
+ ))} +
+ ); + } +} From 5d90678b079d5d18044c248ba9b9c49b62159c3f Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 5 Dec 2018 13:33:52 -0300 Subject: [PATCH 3/5] chore: add target in webpack config --- config/webpack-main.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/config/webpack-main.config.js b/config/webpack-main.config.js index 0e674c4..10b4814 100644 --- a/config/webpack-main.config.js +++ b/config/webpack-main.config.js @@ -10,6 +10,7 @@ module.exports = { minimizer: [new UglifyJSPlugin({ sourceMap: true })], }, devtool: 'cheap-module-source-map', + target: 'electron-renderer', module: { rules: [ { From 90c3e7bb81fe41e26f2f1b1cad48dfb83d6120a1 Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 5 Dec 2018 13:34:49 -0300 Subject: [PATCH 4/5] feature: send zcashd logs to ipcRenderer --- config/daemon/zcashd-child-process.js | 8 +++++--- config/electron.js | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config/daemon/zcashd-child-process.js b/config/daemon/zcashd-child-process.js index a2c784f..c90c7cf 100644 --- a/config/daemon/zcashd-child-process.js +++ b/config/daemon/zcashd-child-process.js @@ -3,10 +3,12 @@ import cp from 'child_process'; import path from 'path'; import os from 'os'; import processExists from 'process-exists'; -/* eslint-disable-next-line import/no-extraneous-dependencies */ +/* eslint-disable import/no-extraneous-dependencies */ import isDev from 'electron-is-dev'; import type { ChildProcess } from 'child_process'; import eres from 'eres'; +/* eslint-disable-next-line import/named */ +import { mainWindow } from '../electron'; import getBinariesPath from './get-binaries-path'; import getOsFolder from './get-os-folder'; @@ -53,8 +55,8 @@ const runDaemon: () => Promise = () => new Promise(async (resolve stdio: ['ignore', 'pipe', 'pipe'], }); - childProcess.stdout.on('data', () => { - // TODO: Send logs to app + childProcess.stdout.on('data', (data) => { + if (mainWindow) mainWindow.webContents.send('zcashd-log', data.toString()); if (!resolved) { resolve(childProcess); resolved = true; diff --git a/config/electron.js b/config/electron.js index 9ba8618..3c741d4 100644 --- a/config/electron.js +++ b/config/electron.js @@ -64,6 +64,7 @@ const createWindow = () => { mainWindow.loadURL(isDev ? 'http://0.0.0.0:8080/' : `file://${path.join(__dirname, '../build/index.html')}`); exports.app = app; + exports.mainWindow = mainWindow; }; /* eslint-disable-next-line consistent-return */ From 8ac29bb0160b67d3ad5dabb445b32d802c488b77 Mon Sep 17 00:00:00 2001 From: George Lima Date: Thu, 6 Dec 2018 17:26:55 -0300 Subject: [PATCH 5/5] hotfix: use function in setState --- app/views/console.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/console.js b/app/views/console.js index 50a305a..7b53a4d 100644 --- a/app/views/console.js +++ b/app/views/console.js @@ -17,9 +17,9 @@ export class ConsoleView extends Component { componentDidMount() { ipcRenderer.on('zcashd-log', (event, message) => { - this.setState({ + this.setState(() => ({ log: message, - }); + })); }); }