Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Download network dapps and load them from filesystem #144

Merged
merged 15 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ npm-debug.log
build
dist
docs
test/tmp
.build
.coverage
.dist
Expand Down
19 changes: 0 additions & 19 deletions Cargo.precompiled.toml

This file was deleted.

18 changes: 0 additions & 18 deletions Cargo.toml

This file was deleted.

22 changes: 0 additions & 22 deletions build.rs

This file was deleted.

52 changes: 20 additions & 32 deletions electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

const electron = require('electron');
const fs = require('fs');
const path = require('path');
const url = require('url');
const util = require('util');
const { ensureDir: fsEnsureDir } = require('fs-extra');

const addMenu = require('./menu');
const { cli } = require('./cli');
Expand All @@ -33,11 +32,16 @@ const { name: appName } = require('../package.json');
const { app, BrowserWindow, ipcMain, session } = electron;
const { URL } = url;

const fsExists = util.promisify(fs.stat); // eslint-disable-line
const fsMkdir = util.promisify(fs.mkdir);

let mainWindow;

function runApp () {
doesParityExist()
.catch(() => fetchParity(mainWindow)) // Install parity if not present
.catch(handleError); // Errors should be handled before, this is really just in case

return fsEnsureDir(getLocalDappsPath()).then(createWindow);
}

function createWindow () {
// Will send these variables to renderers via IPC
global.dirName = __dirname;
Expand All @@ -46,18 +50,10 @@ function createWindow () {

mainWindow = new BrowserWindow({
height: 800,
width: 1200
width: 1200,
webPreferences: { nodeIntegrationInWorker: true }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nodeintegration is enabled for the BrowserWindow but disabled by default for its WebWorkers; I had to add this option to remove the following error (wasn't blocking though):

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine, we are not requiring any external files as web workers.

Is the error stack longer? Who is requiring @parity/shared/lib/webWorker.js? I'd be more enthusiast to remove web workers altoghether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the whole error stack

we import some files of @parity/shared (for example import { initStore } from '@parity/shared/lib/redux' in index.parity.js) that require the worker of @parity/shared (in that case, initStore calls setupWorker). I imagine that's where it's coming from

});

const localDappsPath = getLocalDappsPath();

fsExists(localDappsPath)
.catch(() => fsMkdir(localDappsPath));

doesParityExist()
.catch(() => fetchParity(mainWindow)) // Install parity if not present
.catch(handleError); // Errors should be handled before, this is really just in case

if (cli.uiDev === true) {
// Opens http://127.0.0.1:3000 in --ui-dev mode
mainWindow.loadURL('http://127.0.0.1:3000');
Expand Down Expand Up @@ -88,22 +84,6 @@ function createWindow () {
callback({ requestHeaders: details.requestHeaders });
});

// Do not accept all kind of web permissions (camera, location...)
// https://electronjs.org/docs/tutorial/security#4-handle-session-permission-requests-from-remote-content
session.defaultSession
.setPermissionRequestHandler((webContents, permission, callback) => {
if (!webContents.getURL().startsWith('file:')) {
// Denies the permissions request for all non-file://. Currently all
// network dapps are loaded on http://127.0.0.1:8545, so they won't
// have any permissions.
return callback(false);
}

// All others loaded on file:// (shell, builtin, local) can have those
// permissions.
return callback(true);
});

// Verify WebView Options Before Creation
// https://electronjs.org/docs/tutorial/security#12-verify-webview-options-before-creation
mainWindow.webContents.on('will-attach-webview', (event, webPreferences, params) => {
Expand All @@ -120,6 +100,14 @@ function createWindow () {

// Listen to the creation of (dapp) webviews to attach event listeners to them
mainWindow.webContents.on('did-attach-webview', (event, webContents) => {
// Do not accept all kinds of web permissions (camera, location...)
// https://electronjs.org/docs/tutorial/security#4-handle-session-permission-requests-from-remote-content
webContents.session
.setPermissionRequestHandler((webContents, permission, callback) => {
// Deny all permissions for dapps
return callback(false);
});

let baseUrl;
let appId;

Expand Down Expand Up @@ -166,7 +154,7 @@ function createWindow () {
});
}

app.on('ready', createWindow);
app.on('ready', runApp);

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
Expand Down
2 changes: 1 addition & 1 deletion electron/operations/runParity.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
.then(() => fsChmod(parityPath(), '755')) // Should already be 755 after download, just to be sure
.then(() => {
const logStream = fs.createWriteStream(logFile, { flags: 'a' });
let logLastLine; // Always contains last line of the logFile
let logLastLine = ''; // Always contains last line of the logFile

// Run an instance of parity with the correct args
parity = spawn(parityPath(), parityArgv);
Expand Down
Loading