Newer
Older
Luke Schoen
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// 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';
import handleError from '../../utils/handleError';
import cli from '../../cli';
import Pino from '../../utils/pino';
const pino = Pino();
let hasCalledInitParityEthereum = false;
class ParityEthereum {
setup = fetherAppWindow => {
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) {
return;
}
// Do not run Parity Ethereum if it is already running
if (await this.isRunning()) {
return;
}
// Run Parity Ethereum when installed
const parityEthereum = await this.run();
pino.info('Running Parity Ethereum');
return parityEthereum;
})
.then(() => {
// Notify the renderers
fetherAppWindow.webContents.send('parity-running', true);
global.isParityRunning = true; // Send this variable to renderers via IPC
})
.catch(handleError);
};
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;