Newer
Older
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
Luke Schoen
committed
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import {
getParityPath,
fetchParity,
isParityRunning,
runParity
} from '@parity/electron';
import getRemainingArgs from 'commander-remaining-args';
import { parity } from '../../../../package.json';
Luke Schoen
committed
import handleError from '../utils/handleError';
import cli from '../cli';
import Pino from '../utils/pino';
Luke Schoen
committed
const pino = Pino();
let hasCalledInitParityEthereum = false;
class ParityEthereum {
constructor (fetherAppWindow) {
Luke Schoen
committed
if (hasCalledInitParityEthereum) {
throw new Error('Unable to initialise Parity Ethereum more than once');
}
// Check if Parity Ethereum is installed
getParityPath()
// Download and install Parity Ethereum if not present
.catch(() => {
pino.info('Downloading and Installing Parity Ethereum');
return this.install(fetherAppWindow);
})
.then(async () => {
// Do not run Parity Ethereum if the user ran Fether with --no-run-parity
if (!cli.runParity) {
Luke Schoen
committed
}
// Do not run Parity Ethereum if it is already running
if (await this.isRunning()) {
Luke Schoen
committed
}
// Run Parity Ethereum when installed
Luke Schoen
committed
pino.info('Running Parity Ethereum');
Luke Schoen
committed
})
Luke Schoen
committed
// Notify the renderers
fetherAppWindow.webContents.send('parity-running', isRunning);
global.isParityRunning = isRunning; // Send this variable to renderers via IPC
Luke Schoen
committed
})
.catch(handleError);
Luke Schoen
committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
install = fetherAppWindow => {
return fetchParity(fetherAppWindow, {
onProgress: progress => {
// Notify the renderers on download progress
return fetherAppWindow.webContents.send(
'parity-download-progress',
progress
);
},
parityChannel: parity.channel
});
};
isRunning = async () => {
return isParityRunning({
wsInterface: cli.wsInterface,
wsPort: cli.wsPort
});
};
run = async () => {
return runParity({
flags: [
...getRemainingArgs(cli),
'--light',
'--chain',
cli.chain,
'--ws-interface',
cli.wsInterface,
'--ws-port',
cli.wsPort
],
onParityError: err =>
handleError(err, 'An error occured with Parity Ethereum.')
});
};
}
export default ParityEthereum;