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