Skip to content

Commit 3fc7ff2

Browse files
axelchalonamaury1093
authored andcommitted
Fix fetchParity(mainWindow) race condition (parity-js#173) (parity-js#174)
* Fix fetchParity(mainWindow) race condition * Lint
1 parent dca47ac commit 3fc7ff2

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

electron/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
const electron = require('electron');
1818
const path = require('path');
1919
const url = require('url');
20-
const { ensureDir: fsEnsureDir } = require('fs-extra');
2120

2221
const addMenu = require('./menu');
2322
const { cli } = require('./cli');
@@ -40,14 +39,6 @@ if (!['darwin', 'win32'].includes(process.platform)) {
4039
app.disableHardwareAcceleration();
4140
}
4241

43-
function runApp () {
44-
doesParityExist()
45-
.catch(() => fetchParity(mainWindow)) // Install parity if not present
46-
.catch(handleError); // Errors should be handled before, this is really just in case
47-
48-
return fsEnsureDir(getLocalDappsPath()).then(createWindow);
49-
}
50-
5142
function createWindow () {
5243
// Will send these variables to renderers via IPC
5344
global.dirName = __dirname;
@@ -75,6 +66,10 @@ function createWindow () {
7566
);
7667
}
7768

69+
doesParityExist()
70+
.catch(() => fetchParity(mainWindow)) // Install parity if not present
71+
.catch(handleError); // Errors should be handled before, this is really just in case
72+
7873
// Listen to messages from renderer process
7974
ipcMain.on('asynchronous-message', messages);
8075

@@ -179,7 +174,7 @@ function createWindow () {
179174
});
180175
}
181176

182-
app.on('ready', runApp);
177+
app.on('ready', createWindow);
183178

184179
app.on('window-all-closed', () => {
185180
if (process.platform !== 'darwin') {

src/util/dapps.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const util = require('util');
3131
require('util.promisify').shim();
3232

3333
const fs = require('fs');
34+
const { ensureDir: fsEnsureDir } = require('fs-extra');
3435
const fsReadFile = util.promisify(fs.readFile);
3536
const fsReaddir = util.promisify(fs.readdir);
3637
const fsStat = util.promisify(fs.stat);
@@ -130,7 +131,8 @@ export function fetchBuiltinApps () {
130131
export function fetchLocalApps () {
131132
const dappsPath = getLocalDappsPath();
132133

133-
return fsReaddir(dappsPath) // List files
134+
return fsEnsureDir(dappsPath)
135+
.then(() => fsReaddir(dappsPath)) // List files
134136
.then(filenames => // Gather info about files
135137
Promise.all(filenames.map(filename => {
136138
const filePath = path.join(dappsPath, filename);
@@ -169,7 +171,7 @@ export function fetchLocalApps () {
169171
localUrl: localUrl || `file://${dappsPath}/${filename}/index.html`,
170172
image: `file://${dappsPath}/${filename}/${iconUrl}`
171173
}
172-
)))
174+
)))
173175
.catch((error) => {
174176
console.warn('DappsStore:fetchLocal', error);
175177
});
@@ -251,7 +253,7 @@ export function fetchRegistryApp (api, dappReg, appId) {
251253
})
252254
);
253255
})
254-
.catch((error) => {
255-
console.warn('DappsStore:fetchRegistryApp', appId, error);
256-
});
256+
.catch((error) => {
257+
console.warn('DappsStore:fetchRegistryApp', appId, error);
258+
});
257259
}

0 commit comments

Comments
 (0)