From 6ebbffe04c81cfd08f07bcaa4edda1faa915d61f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 26 Jun 2018 11:06:25 +0200 Subject: [PATCH 01/11] Add fake icon to make binaries work --- packages/fether-electron/src/main/index.js | 4 +--- packages/fether-electron/static/.gitkeep | 0 .../static/assets/menubar/icon.png | Bin 0 -> 589 bytes 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 packages/fether-electron/static/.gitkeep create mode 100644 packages/fether-electron/static/assets/menubar/icon.png diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index 8ce64e1c..49963c43 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -22,6 +22,7 @@ const pino = Pino(); const menubar = Mb({ height: 640, + icon: path.join(staticPath, 'assets', 'menubar', 'icon.png'), index: // Opens file:///path/to/build/index.html in prod mode, or whatever is // passed to ELECTRON_START_URL @@ -43,9 +44,6 @@ const menubar = Mb({ function createWindow () { pino.info(`Starting ${productName}...`); - // Show window on start - menubar.showWindow(); - doesParityExist() .catch(() => fetchParity(menubar.window)) // Install parity if not present .then(() => runParity(menubar.window)) diff --git a/packages/fether-electron/static/.gitkeep b/packages/fether-electron/static/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/fether-electron/static/assets/menubar/icon.png b/packages/fether-electron/static/assets/menubar/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1cba18cb73d4ffdfd732ceca5db534ee5677d748 GIT binary patch literal 589 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1O92wCOqsGdgL^t^f+Mmw5WRvOi+uW{?wMZ0givU|^K?ba4#PIKOp*y?0Zhi2M24 zGm8|0n+|b&+WFqQi!;^R^hHj!^940tU8m@56G@XVg1=aJO-(|)w|Puv{To@-c}>cv zl=00LGl3c5xwld@q9*Zw7wtW+wlv{f^3II5X>0uN9KEFXa>9-m#`i;J zDxQ}x&D?3=G)>KX&t@ly+3)u}b{FzquzMGOotfpmyQ=s1dzt^}eaQb$^For6sX{^j zq_4_vI-~`z=--Y0pz!?b^m#uSAMtqZ-}5p#8W?h_C9V-ADTyViR>?)FK#IZ0z|cb1 zz)aWBFvP&X%Gkil$Uxh`$jZQg?OEeb6b-rgDVb@NxHXjTwsZw*kObKfoS#-wo>-L1 kP+nfHmzkGcoSayYs+V7sKKq@G6i^X^r>mdKI;Vst0O;z|2><{9 literal 0 HcmV?d00001 -- GitLab From 75ce2a17feffd83075d615ed0eb7981779c28632 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 26 Jun 2018 14:05:23 +0200 Subject: [PATCH 02/11] Remove menubar --- packages/fether-electron/src/main/index.js | 104 ++++++++---------- packages/fether-electron/static/.gitkeep | 0 .../static/assets/menubar/icon.png | Bin 589 -> 0 bytes packages/fether-react/src/App/App.js | 14 +-- 4 files changed, 48 insertions(+), 70 deletions(-) create mode 100644 packages/fether-electron/static/.gitkeep delete mode 100644 packages/fether-electron/static/assets/menubar/icon.png diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index 49963c43..bf31c547 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -7,51 +7,50 @@ import electron from 'electron'; import path from 'path'; import url from 'url'; +import addMenu from './menu'; import { doesParityExist } from './operations/doesParityExist'; import fetchParity from './operations/fetchParity'; import handleError from './operations/handleError'; -import Mb from 'menubar'; import messages from './messages'; import { productName } from '../../electron-builder.json'; import Pino from './utils/pino'; import { runParity, killParity } from './operations/runParity'; import staticPath from './utils/staticPath'; -const { ipcMain, Menu, session } = electron; +const { app, BrowserWindow, ipcMain, session } = electron; +let mainWindow; const pino = Pino(); -const menubar = Mb({ - height: 640, - icon: path.join(staticPath, 'assets', 'menubar', 'icon.png'), - index: - // Opens file:///path/to/build/index.html in prod mode, or whatever is - // passed to ELECTRON_START_URL - process.env.ELECTRON_START_URL || - url.format({ - pathname: path.join(staticPath, 'build', 'index.html'), - protocol: 'file:', - slashes: true - }), - preloadWindow: true, - resizable: false, - transparent: true, - webPreferences: { - nodeIntegration: true - }, - width: 360 -}); - -function createWindow () { +function createWindow() { pino.info(`Starting ${productName}...`); + mainWindow = new BrowserWindow({ + height: 640, + resizable: false, + width: 360 + }); doesParityExist() - .catch(() => fetchParity(menubar.window)) // Install parity if not present - .then(() => runParity(menubar.window)) + .catch(() => fetchParity(mainWindow)) // Install parity if not present + .then(() => runParity(mainWindow)) .catch(handleError); // Errors should be handled before, this is really just in case + // Opens file:///path/to/build/index.html in prod mode, or whatever is + // passed to ELECTRON_START_URL + mainWindow.loadURL( + process.env.ELECTRON_START_URL || + url.format({ + pathname: path.join(staticPath, 'build', 'index.html'), + protocol: 'file:', + slashes: true + }) + ); + // Listen to messages from renderer process ipcMain.on('asynchronous-message', messages); + // Add application menu + addMenu(mainWindow); + // WS calls have Origin `file://` by default, which is not trusted. // We override Origin header on all WS connections with an authorized one. session.defaultSession.webRequest.onBeforeSendHeaders( @@ -59,52 +58,43 @@ function createWindow () { urls: ['ws://*/*', 'wss://*/*'] }, (details, callback) => { - if (!menubar.window) { + if (!mainWindow) { // There might be a split second where the user closes the app, so - // menubar.window is null, but there is still a network request done. + // mainWindow is null, but there is still a network request done. return; } - details.requestHeaders.Origin = `parity://${menubar.window.id}.ui.parity`; + details.requestHeaders.Origin = `parity://${mainWindow.id}.ui.parity`; callback({ requestHeaders: details.requestHeaders }); // eslint-disable-line } ); // Open external links in browser - menubar.window.webContents.on('new-window', function (event, url) { + mainWindow.webContents.on('new-window', function(event, url) { event.preventDefault(); electron.shell.openExternal(url); }); + + mainWindow.on('closed', () => { + mainWindow = null; + }); } -// Right click menu for Tray -menubar.on('after-create-window', function () { - // Add right-click menu - const contextMenu = Menu.buildFromTemplate([ - { role: 'about' }, - { type: 'separator' }, - { - label: 'Restart', - click: () => { - menubar.app.relaunch(); - menubar.app.exit(); - } - }, - { - label: 'Quit', - click: () => { - menubar.app.quit(); - } - } - ]); +app.on('ready', createWindow); - menubar.tray.on('right-click', () => { - menubar.tray.popUpContextMenu(contextMenu); - }); +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + killParity(); + app.quit(); + } }); // Make sure parity stops when UI stops -menubar.app.on('before-quit', killParity); -menubar.app.on('will-quit', killParity); -menubar.app.on('quit', killParity); +app.on('before-quit', killParity); +app.on('will-quit', killParity); +app.on('quit', killParity); -menubar.on('ready', createWindow); +app.on('activate', () => { + if (mainWindow === null) { + createWindow(); + } +}); diff --git a/packages/fether-electron/static/.gitkeep b/packages/fether-electron/static/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/fether-electron/static/assets/menubar/icon.png b/packages/fether-electron/static/assets/menubar/icon.png deleted file mode 100644 index 1cba18cb73d4ffdfd732ceca5db534ee5677d748..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 589 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1O92wCOqsGdgL^t^f+Mmw5WRvOi+uW{?wMZ0givU|^K?ba4#PIKOp*y?0Zhi2M24 zGm8|0n+|b&+WFqQi!;^R^hHj!^940tU8m@56G@XVg1=aJO-(|)w|Puv{To@-c}>cv zl=00LGl3c5xwld@q9*Zw7wtW+wlv{f^3II5X>0uN9KEFXa>9-m#`i;J zDxQ}x&D?3=G)>KX&t@ly+3)u}b{FzquzMGOotfpmyQ=s1dzt^}eaQb$^For6sX{^j zq_4_vI-~`z=--Y0pz!?b^m#uSAMtqZ-}5p#8W?h_C9V-ADTyViR>?)FK#IZ0z|cb1 zz)aWBFvP&X%Gkil$Uxh`$jZQg?OEeb6b-rgDVb@NxHXjTwsZw*kObKfoS#-wo>-L1 kP+nfHmzkGcoSayYs+V7sKKq@G6i^X^r>mdKI;Vst0O;z|2><{9 diff --git a/packages/fether-react/src/App/App.js b/packages/fether-react/src/App/App.js index acbc76ff..9b47d973 100644 --- a/packages/fether-react/src/App/App.js +++ b/packages/fether-react/src/App/App.js @@ -33,19 +33,7 @@ class App extends Component { return (
-
-
- - - -
- {this.renderScreen()} - {/*
- - - -
*/} -
+
{this.renderScreen()}
); -- GitLab From 6d5b891c1458e383eb379fbbafe49e1a719fc1a3 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 26 Jun 2018 14:12:51 +0200 Subject: [PATCH 03/11] Fix lint --- packages/fether-electron/src/main/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index bf31c547..2f2e8e4d 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -21,7 +21,7 @@ const { app, BrowserWindow, ipcMain, session } = electron; let mainWindow; const pino = Pino(); -function createWindow() { +function createWindow () { pino.info(`Starting ${productName}...`); mainWindow = new BrowserWindow({ height: 640, @@ -69,7 +69,7 @@ function createWindow() { ); // Open external links in browser - mainWindow.webContents.on('new-window', function(event, url) { + mainWindow.webContents.on('new-window', function (event, url) { event.preventDefault(); electron.shell.openExternal(url); }); -- GitLab From f7a12467f0360a968a31d0193ca2daba630afba8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 26 Jun 2018 14:36:01 +0200 Subject: [PATCH 04/11] Fix bug downlaoding parity --- .../fether-electron/src/main/operations/fetchParity.js | 10 ++-------- packages/fether-react/src/stores/healthStore.js | 7 ++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/fether-electron/src/main/operations/fetchParity.js b/packages/fether-electron/src/main/operations/fetchParity.js index fae9d714..e95cda34 100644 --- a/packages/fether-electron/src/main/operations/fetchParity.js +++ b/packages/fether-electron/src/main/operations/fetchParity.js @@ -84,7 +84,7 @@ export default mainWindow => { ); // Get the binary's url - const { downloadUrl } = data[0].files.find( + const { downloadUrl, checksum: expectedChecksum } = data[0].files.find( ({ name }) => name === 'parity' || name === 'parity.exe' ); @@ -97,13 +97,7 @@ export default mainWindow => { }); const downloadPath = downloadItem.getSavePath(); // Equal to defaultParityPath - // Once downloaded, we fetch the sha256 checksum - const { downloadUrl: checksumDownloadUrl } = data[0].files.find( - ({ name }) => name === 'parity.sha256' || name === 'parity.exe.sha256' - ); - const { data: checksumData } = await axios.get(checksumDownloadUrl); - // Downloaded checksumData is in the format: "{checksum} {filename}" - const [expectedChecksum] = checksumData.split(' '); + // Once downloaded, we check the sha256 checksum // Calculate the actual checksum const actualChecksum = await checksum(downloadPath, { algorithm: 'sha256' diff --git a/packages/fether-react/src/stores/healthStore.js b/packages/fether-react/src/stores/healthStore.js index ada90f05..b8ddc1ad 100644 --- a/packages/fether-react/src/stores/healthStore.js +++ b/packages/fether-react/src/stores/healthStore.js @@ -4,6 +4,7 @@ // SPDX-License-Identifier: BSD-3-Clause import { action, computed, observable } from 'mobx'; +import BigNumber from 'bignumber.js'; import { nodeHealth$, syncing$ } from '@parity/light.js'; import parityStore from './parityStore'; @@ -42,7 +43,11 @@ class HealthStore { if (parityStore.downloadProgress > 0 && !parityStore.isParityRunning) { return { status: STATUS.DOWNLOADING, - payload: { percentage: Math.round(parityStore.downloadProgress * 100) } + payload: { + percentage: new BigNumber( + Math.round(parityStore.downloadProgress * 100) + ) + } }; } -- GitLab From 65e5bf145abd568b627d88cefd360e67bddb0c94 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 26 Jun 2018 14:45:55 +0200 Subject: [PATCH 05/11] Update csp --- packages/fether-react/public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fether-react/public/index.html b/packages/fether-react/public/index.html index 27ac9c71..88d0eb61 100644 --- a/packages/fether-react/public/index.html +++ b/packages/fether-react/public/index.html @@ -4,7 +4,7 @@ - +