feat(loading-screen): improve status message
This commit is contained in:
parent
4ce76f6e0f
commit
a1143bb6e0
|
@ -1,11 +1,10 @@
|
|||
// @flow
|
||||
|
||||
import electron from 'electron'; // eslint-disable-line
|
||||
import React, { type ComponentType, Component } from 'react';
|
||||
|
||||
import { LoadingScreen } from './loading-screen';
|
||||
|
||||
import rpc from '../../services/api';
|
||||
import electronStore from '../../config/electron-store';
|
||||
|
||||
type Props = {};
|
||||
|
||||
|
@ -21,6 +20,8 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
|
|||
): ComponentType<$Diff<PassedProps, Props>> => class extends Component<PassedProps, State> {
|
||||
timer: ?IntervalID = null;
|
||||
|
||||
hasDaemonError: boolean = false;
|
||||
|
||||
state = {
|
||||
isRunning: false,
|
||||
progress: 0,
|
||||
|
@ -29,8 +30,20 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
|
|||
|
||||
componentDidMount() {
|
||||
this.runTest();
|
||||
|
||||
this.timer = setInterval(this.runTest, 2000);
|
||||
|
||||
electron.ipcRenderer.on('zcash-daemon-status', (event: empty, message: Object) => {
|
||||
this.hasDaemonError = message.error;
|
||||
|
||||
if (message.error) {
|
||||
clearInterval(this.timer);
|
||||
}
|
||||
|
||||
this.setState({
|
||||
message: message.status,
|
||||
...(message.error ? { progress: 0, isRunning: false } : {}),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -41,16 +54,13 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
|
|||
}
|
||||
|
||||
runTest = () => {
|
||||
if (electronStore.get('DAEMON_FETCHING_PARAMS')) {
|
||||
return this.setState({
|
||||
message:
|
||||
'Downloading network params, this may take some time depending on your connection speed',
|
||||
});
|
||||
}
|
||||
if (this.hasDaemonError) return;
|
||||
|
||||
rpc
|
||||
.getinfo()
|
||||
.then((response) => {
|
||||
if (this.hasDaemonError) return;
|
||||
|
||||
if (response) {
|
||||
setTimeout(() => {
|
||||
this.setState(() => ({ isRunning: true }));
|
||||
|
@ -64,6 +74,8 @@ export const withDaemonStatusCheck = <PassedProps: {}>(
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (this.hasDaemonError) return;
|
||||
|
||||
const statusMessage = error.message === 'Something went wrong' ? 'Zepio Starting' : error.message;
|
||||
|
||||
const isRpcOff = Math.trunc(error.statusCode / 100) === 5;
|
||||
|
|
|
@ -65,24 +65,59 @@ let resolved = false;
|
|||
|
||||
const ZCASHD_PROCESS_NAME = getDaemonName();
|
||||
|
||||
let isWindowOpened = false;
|
||||
|
||||
const sendToRenderer = (event: string, message: Object, shouldLog: boolean = true) => {
|
||||
if (shouldLog) {
|
||||
log(message);
|
||||
}
|
||||
|
||||
if (isWindowOpened) {
|
||||
if (!mainWindow.isDestroyed()) {
|
||||
mainWindow.webContents.send(event, message);
|
||||
}
|
||||
} else {
|
||||
const interval = setInterval(() => {
|
||||
if (isWindowOpened) {
|
||||
mainWindow.webContents.send(event, message);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line
|
||||
const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve, reject) => {
|
||||
mainWindow.webContents.on('dom-ready', () => {
|
||||
isWindowOpened = true;
|
||||
});
|
||||
|
||||
const processName = path.join(getBinariesPath(), getOsFolder(), ZCASHD_PROCESS_NAME);
|
||||
const isRelaunch = Boolean(process.argv.find(arg => arg === '--relaunch'));
|
||||
|
||||
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', 'Fetching params...');
|
||||
|
||||
store.set('DAEMON_FETCHING_PARAMS', true);
|
||||
sendToRenderer('zcash-daemon-status', {
|
||||
error: false,
|
||||
status:
|
||||
'Downloading network params, this may take some time depending on your connection speed',
|
||||
});
|
||||
|
||||
const [err] = await eres(fetchParams());
|
||||
|
||||
if (err) {
|
||||
log('Something went wrong fetching params: ', err);
|
||||
sendToRenderer('zcash-daemon-status', {
|
||||
error: true,
|
||||
status: `Error while fetching params: ${err.message}`,
|
||||
});
|
||||
|
||||
return reject(new Error(err));
|
||||
}
|
||||
|
||||
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-params-download', 'Zepio Starting');
|
||||
log('Fetch Params finished!');
|
||||
store.set('DAEMON_FETCHING_PARAMS', false);
|
||||
sendToRenderer('zcash-daemon-status', {
|
||||
error: false,
|
||||
status: 'Zepio Starting',
|
||||
});
|
||||
|
||||
// In case of --relaunch on argv, we need wait to close the old zcash daemon
|
||||
// a workaround is use a interval to check if there is a old process running
|
||||
|
@ -164,7 +199,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
|
|||
);
|
||||
|
||||
childProcess.stdout.on('data', (data) => {
|
||||
if (!mainWindow.isDestroyed()) mainWindow.webContents.send('zcashd-log', data.toString());
|
||||
sendToRenderer('zcashd-log', data.toString(), false);
|
||||
if (!resolved) {
|
||||
resolve(childProcess);
|
||||
resolved = true;
|
||||
|
|
Loading…
Reference in New Issue