Commit aa866a9d authored by Amaury Martiny's avatar Amaury Martiny
Browse files

Fix bugs in @parity/electron

parent 8bea07b5
...@@ -39,9 +39,24 @@ function createWindow () { ...@@ -39,9 +39,24 @@ function createWindow () {
parityChannel: parity.channel parityChannel: parity.channel
}); });
// Look if Parity is installed
getParityPath() getParityPath()
.catch(() => fetchParity(mainWindow)) // Install parity if not present .catch(() =>
.then(() => runParity(mainWindow)) // Install parity if not present
fetchParity(mainWindow, progress =>
// Notify the renderers on download progress
mainWindow.webContents.send('parity-download-progress', progress)
)
)
.then(() =>
// Run parity when installed
runParity(err => handleError(err, 'An error occured with Parity.'))
)
.then(() => {
// Notify the renderers
mainWindow.webContents.send('parity-running', true);
global.isParityRunning = true; // Send this variable to renderes via IPC
})
.catch(handleError); .catch(handleError);
// Opens file:///path/to/build/index.html in prod mode, or whatever is // Opens file:///path/to/build/index.html in prod mode, or whatever is
......
...@@ -16,15 +16,19 @@ export default (err, message = 'An error occurred.') => { ...@@ -16,15 +16,19 @@ export default (err, message = 'An error occurred.') => {
{ {
buttons: ['OK', 'Open logs'], buttons: ['OK', 'Open logs'],
defaultId: 0, // Default button id defaultId: 0, // Default button id
detail: `Please attach the following debugging info: detail: `Please file an issue at ${
bugs.url
}. Please attach the following debugging info:
OS: ${process.platform} OS: ${process.platform}
Arch: ${process.arch} Arch: ${process.arch}
Channel: ${parity.channel} Channel: ${parity.channel}
Error: ${err.message} Error: ${err.message}
Please also attach the contents of the following file: Please also attach the contents of the following file:
${logFile}`, ${logFile}.
message: `${message} Please file an issue at ${bugs.url}.`, Click on "Open logs" to open this file.`,
message: `${message}`,
title: 'Parity Error', title: 'Parity Error',
type: 'error' type: 'error'
}, },
......
...@@ -3,14 +3,16 @@ ...@@ -3,14 +3,16 @@
// //
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import Api from '@parity/api';
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
import Api from '@parity/api';
import isElectron from 'is-electron'; import isElectron from 'is-electron';
import light from '@parity/light.js'; import light from '@parity/light.js';
import store from 'store'; import store from 'store';
import Debug from '../utils/debug';
import LS_PREFIX from './utils/lsPrefix'; import LS_PREFIX from './utils/lsPrefix';
const debug = Debug('sendStore');
const electron = isElectron() ? window.require('electron') : null; const electron = isElectron() ? window.require('electron') : null;
const LS_KEY = `${LS_PREFIX}::secureToken`; const LS_KEY = `${LS_PREFIX}::secureToken`;
...@@ -29,7 +31,7 @@ class ParityStore { ...@@ -29,7 +31,7 @@ class ParityStore {
} }
if (!electron) { if (!electron) {
console.log( debug(
'Not in Electron, ParityStore will only have limited capabilities.' 'Not in Electron, ParityStore will only have limited capabilities.'
); );
return; return;
......
...@@ -67,7 +67,7 @@ export const deleteParity = async () => { ...@@ -67,7 +67,7 @@ export const deleteParity = async () => {
}; };
// Fetch parity from https://vanity-service.parity.io/parity-binaries // Fetch parity from https://vanity-service.parity.io/parity-binaries
export const fetchParity = mainWindow => { export const fetchParity = (mainWindow, onProgress) => {
try { try {
return retry( return retry(
async (_, attempt) => { async (_, attempt) => {
...@@ -88,9 +88,7 @@ export const fetchParity = mainWindow => { ...@@ -88,9 +88,7 @@ export const fetchParity = mainWindow => {
// Start downloading. This will install parity into defaultParityPath. // Start downloading. This will install parity into defaultParityPath.
const downloadItem = await download(mainWindow, downloadUrl, { const downloadItem = await download(mainWindow, downloadUrl, {
directory: app.getPath('userData'), directory: app.getPath('userData'),
onProgress: progress => onProgress
// Notify the renderers
mainWindow.webContents.send('parity-download-progress', progress)
}); });
const downloadPath = downloadItem.getSavePath(); // Equal to defaultParityPath const downloadPath = downloadItem.getSavePath(); // Equal to defaultParityPath
...@@ -110,13 +108,11 @@ export const fetchParity = mainWindow => { ...@@ -110,13 +108,11 @@ export const fetchParity = mainWindow => {
await fsChmod(downloadPath, '755'); await fsChmod(downloadPath, '755');
// Double-check that Parity exists now. // Double-check that Parity exists now.
console.log('fetchParity');
const parityPath = await getParityPath(); const parityPath = await getParityPath();
return parityPath; return parityPath;
}, },
{ {
onRetry: async err => { onRetry: async err => {
console.log('onRetry');
debug(err); debug(err);
// Everytime we retry, we remove the parity file we just downloaded. // Everytime we retry, we remove the parity file we just downloaded.
...@@ -128,7 +124,6 @@ export const fetchParity = mainWindow => { ...@@ -128,7 +124,6 @@ export const fetchParity = mainWindow => {
} }
); );
} catch (err) { } catch (err) {
console.log('error in fetchParity');
return deleteParity().then(() => { return deleteParity().then(() => {
Promise.reject(err); Promise.reject(err);
}); });
......
...@@ -27,7 +27,7 @@ if (cli.wsInterface || cli.wsPort) { ...@@ -27,7 +27,7 @@ if (cli.wsInterface || cli.wsPort) {
* *
* @return [Promise<Boolean>] - Promise that resolves to true or false. * @return [Promise<Boolean>] - Promise that resolves to true or false.
*/ */
export const isParityRunning = async mainWindow => { export const isParityRunning = async () => {
try { try {
// Retry to ping as many times as there are hosts in `hostsToPing` // Retry to ping as many times as there are hosts in `hostsToPing`
await retry( await retry(
...@@ -37,10 +37,6 @@ export const isParityRunning = async mainWindow => { ...@@ -37,10 +37,6 @@ export const isParityRunning = async mainWindow => {
logger( logger(
`Another instance of parity is already running on ${host}, skip running local instance.` `Another instance of parity is already running on ${host}, skip running local instance.`
); );
// Notify the renderers
mainWindow.webContents.send('parity-running', true);
global.isParityRunning = true; // Send this variable to renderes via IPC
}, },
{ retries: hostsToPing.length } { retries: hostsToPing.length }
); );
......
...@@ -29,14 +29,14 @@ const catchableErrors = [ ...@@ -29,14 +29,14 @@ const catchableErrors = [
'IO error: While lock file:' 'IO error: While lock file:'
]; ];
export const runParity = async mainWindow => { export const runParity = async onParityError => {
// Do not run parity with --no-run-parity // Do not run parity with --no-run-parity
if (cli.runParity === false) { if (cli.runParity === false) {
return; return;
} }
// Do not run parity if there is already another instance running // Do not run parity if there is already another instance running
const isRunning = await isParityRunning(mainWindow); const isRunning = await isParityRunning();
if (isRunning) { if (isRunning) {
return; return;
} }
...@@ -68,7 +68,7 @@ export const runParity = async mainWindow => { ...@@ -68,7 +68,7 @@ export const runParity = async mainWindow => {
parity.stderr.on('data', callback); parity.stderr.on('data', callback);
parity.on('error', err => { parity.on('error', err => {
throw err; onParityError(err);
}); });
parity.on('close', (exitCode, signal) => { parity.on('close', (exitCode, signal) => {
if (exitCode === 0) { if (exitCode === 0) {
...@@ -91,15 +91,9 @@ export const runParity = async mainWindow => { ...@@ -91,15 +91,9 @@ export const runParity = async mainWindow => {
if (Object.keys(parityArgv()).length > 0) { if (Object.keys(parityArgv()).length > 0) {
app.exit(1); app.exit(1);
} else { } else {
throw new Error(`Exit code ${exitCode}, with signal ${signal}.`); onParityError(new Error(`Exit code ${exitCode}, with signal ${signal}.`));
} }
}); });
// Notify the renderers
mainWindow.webContents.send('parity-running', true);
global.isParityRunning = true; // Send this variable to renderes via IPC
return Promise.resolve(true);
}; };
export const killParity = () => { export const killParity = () => {
...@@ -108,5 +102,5 @@ export const killParity = () => { ...@@ -108,5 +102,5 @@ export const killParity = () => {
parity.kill(); parity.kill();
parity = null; parity = null;
} }
return Promise.resolve(true); return Promise.resolve();
}; };
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment