From be56a0679035bc8278bb33ed387785d4af549b1b Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 30 Aug 2017 11:59:38 +0200 Subject: [PATCH] Basic electron interface --- js/package.json | 5 ++- js/src/index.electron.js | 57 ++++++++++++++++++++++++++ js/src/{index.ejs => index.parity.ejs} | 0 js/src/{index.js => index.parity.js} | 0 js/src/secureApi.js | 4 +- js/webpack/app.js | 4 +- 6 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 js/src/index.electron.js rename js/src/{index.ejs => index.parity.ejs} (100%) rename js/src/{index.js => index.parity.js} (100%) diff --git a/js/package.json b/js/package.json index 8135f2c70..cc7d801c6 100644 --- a/js/package.json +++ b/js/package.json @@ -1,7 +1,7 @@ { - "name": "parity.js", + "name": "Parity", "version": "1.8.17", - "main": "release/index.js", + "main": "src/index.electron.js", "jsnext:main": "src/index.js", "author": "Parity Team ", "maintainers": [ @@ -46,6 +46,7 @@ "lint:js:fix": "eslint --fix --ignore-path .gitignore ./src/", "start": "npm run clean && npm install && npm run build:lib && npm run start:app", "start:app": "node webpack/dev.server", + "start:electron": "electron .", "test": "NODE_ENV=test mocha --compilers ejs:ejsify 'src/**/*.spec.js' 'packages/**/*.spec.js'", "test:coverage": "NODE_ENV=test istanbul cover _mocha -- --compilers ejs:ejsify 'src/**/*.spec.js' 'packages/**/*.spec.js'", "test:e2e": "NODE_ENV=test mocha 'src/**/*.e2e.js' 'packages/**/*.e2e.js'", diff --git a/js/src/index.electron.js b/js/src/index.electron.js new file mode 100644 index 000000000..fde818e0c --- /dev/null +++ b/js/src/index.electron.js @@ -0,0 +1,57 @@ +// Copyright 2015-2017 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +const electron = require('electron'); +const app = electron.app; +const BrowserWindow = electron.BrowserWindow; + +const path = require('path'); +const url = require('url'); + +let mainWindow; + +function createWindow () { + mainWindow = new BrowserWindow({ + height: 600, + width: 800 + }); + + mainWindow.loadURL(url.format({ + pathname: path.join(__dirname, '../.build', 'index.html'), + protocol: 'file:', + slashes: true + })); + + mainWindow.webContents.openDevTools(); + + mainWindow.on('closed', function () { + mainWindow = null; + }); +} + +app.on('ready', createWindow); + +app.on('window-all-closed', function () { + if (process.platform !== 'darwin') { + app.quit(); + } +}); + +app.on('activate', function () { + if (mainWindow === null) { + createWindow(); + } +}); diff --git a/js/src/index.ejs b/js/src/index.parity.ejs similarity index 100% rename from js/src/index.ejs rename to js/src/index.parity.ejs diff --git a/js/src/index.js b/js/src/index.parity.js similarity index 100% rename from js/src/index.js rename to js/src/index.parity.js diff --git a/js/src/secureApi.js b/js/src/secureApi.js index f20859d83..264f167cf 100644 --- a/js/src/secureApi.js +++ b/js/src/secureApi.js @@ -46,7 +46,9 @@ export default class SecureApi extends Api { // Returns a protocol with `:` at the end. static protocol () { - return window.location.protocol; + return window.location.protocol === 'file:' + ? 'http:' + : window.location.protocol; } constructor (uiUrl, nextToken, getTransport = SecureApi.getTransport, protocol = SecureApi.protocol) { diff --git a/js/webpack/app.js b/js/webpack/app.js index a7f1d901e..c1613bd26 100644 --- a/js/webpack/app.js +++ b/js/webpack/app.js @@ -47,7 +47,7 @@ const isEmbed = EMBED === '1' || EMBED === 'true'; const entry = isEmbed ? { embed: './embed.js' } - : { bundle: './index.js' }; + : { bundle: './index.parity.js' }; module.exports = { cache: !isProd, @@ -176,7 +176,7 @@ module.exports = { new HtmlWebpackPlugin({ title: 'Parity', filename: 'index.html', - template: './index.ejs', + template: './index.parity.ejs', favicon: FAVICON, chunks: ['bundle'] }),