From 528a70b2f5c408ba5db82b5669b6105b468d5a4b Mon Sep 17 00:00:00 2001 From: Aleksey Popov Date: Tue, 19 Sep 2017 15:36:42 +0300 Subject: [PATCH 01/12] moved menu template into a separate file --- app/main.js | 126 +------------------------------------------------- app/menu.js | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 124 deletions(-) create mode 100644 app/menu.js diff --git a/app/main.js b/app/main.js index d998d7efa..293eef960 100644 --- a/app/main.js +++ b/app/main.js @@ -1,5 +1,6 @@ const electron = require('electron'); // eslint-disable-line import/no-extraneous-dependencies const path = require('path'); +const buildMenu = require('./menu'); const { app } = electron; const { BrowserWindow } = electron; @@ -24,132 +25,9 @@ function createWindow() { win.on('blur', () => win.webContents.send('blur')); win.on('focus', () => win.webContents.send('focus')); - const template = [ - { - label: 'Edit', - submenu: [ - { - role: 'undo', - }, - { - role: 'redo', - }, - { - type: 'separator', - }, - { - role: 'cut', - }, - { - role: 'copy', - }, - { - role: 'paste', - }, - { - role: 'selectall', - }, - ], - }, - { - label: 'View', - submenu: [ - { - role: 'reload', - }, - { - role: 'togglefullscreen', - }, - ], - }, - { - label: 'Window', - submenu: [ - { - role: 'minimize', - }, - ], - }, - { - label: 'Help', - submenu: [ - { - label: 'Lisk Website', - click() { - electron.shell.openExternal('https://lisk.io'); - }, - }, - { - label: 'Lisk Chat', - click() { - electron.shell.openExternal('https://lisk.chat'); - }, - }, - { - label: 'Lisk Explorer', - click() { - electron.shell.openExternal('https://explorer.lisk.io'); - }, - }, - { - label: 'Lisk Forum', - click() { - electron.shell.openExternal('https://forum.lisk.io'); - }, - }, - { - type: 'separator', - }, - { - label: 'Report Issue...', - click() { - electron.shell.openExternal('https://lisk.zendesk.com/hc/en-us/requests/new'); - }, - }, - { - label: 'What\'s New...', - click() { - electron.shell.openExternal('https://github.com/LiskHQ/lisk-nano/releases'); - }, - }, - ], - }, - ]; - - if (process.platform === 'darwin') { - const name = app.getName(); - - template.unshift({ - label: name, - submenu: [ - { - role: 'about', - label: 'About', - }, - { - role: 'quit', - label: 'Quit', - }, - ], - }); - } else { - template[template.length - 1].submenu.push({ - label: 'About', - click(item, focusedWindow) { - if (focusedWindow) { - const options = { - buttons: ['OK'], - icon: `${__dirname}/assets/lisk.png`, - message: `Lisk Nano\nVersion ${app.getVersion()}\n${copyright}`, - }; - electron.dialog.showMessageBox(focusedWindow, options, () => {}); - } - }, - }); } - const menu = Menu.buildFromTemplate(template); - Menu.setApplicationMenu(menu); + Menu.setApplicationMenu(buildMenu(app, copyright)); win.loadURL(`file://${__dirname}/dist/index.html`); diff --git a/app/menu.js b/app/menu.js new file mode 100644 index 000000000..d461ffd87 --- /dev/null +++ b/app/menu.js @@ -0,0 +1,129 @@ +const electron = require('electron'); // eslint-disable-line import/no-extraneous-dependencies + +const { Menu } = electron; + +const template = [ + { + label: 'Edit', + submenu: [ + { + role: 'undo', + }, + { + role: 'redo', + }, + { + type: 'separator', + }, + { + role: 'cut', + }, + { + role: 'copy', + }, + { + role: 'paste', + }, + { + role: 'selectall', + }, + ], + }, + { + label: 'View', + submenu: [ + { + role: 'reload', + }, + { + role: 'togglefullscreen', + }, + ], + }, + { + label: 'Window', + submenu: [ + { + role: 'minimize', + }, + ], + }, + { + label: 'Help', + submenu: [ + { + label: 'Lisk Website', + click() { + electron.shell.openExternal('https://lisk.io'); + }, + }, + { + label: 'Lisk Chat', + click() { + electron.shell.openExternal('https://lisk.chat'); + }, + }, + { + label: 'Lisk Explorer', + click() { + electron.shell.openExternal('https://explorer.lisk.io'); + }, + }, + { + label: 'Lisk Forum', + click() { + electron.shell.openExternal('https://forum.lisk.io'); + }, + }, + { + type: 'separator', + }, + { + label: 'Report Issue...', + click() { + electron.shell.openExternal('https://lisk.zendesk.com/hc/en-us/requests/new'); + }, + }, + { + label: 'What\'s New...', + click() { + electron.shell.openExternal('https://github.com/LiskHQ/lisk-nano/releases'); + }, + }, + ], + }, +]; + +module.exports = (app, copyright) => { + if (process.platform === 'darwin') { + const name = app.getName(); + template.unshift({ + label: name, + submenu: [ + { + role: 'about', + label: 'About', + }, + { + role: 'quit', + label: 'Quit', + }, + ], + }); + } else { + template[template.length - 1].submenu.push({ + label: 'About', + click(item, focusedWindow) { + if (focusedWindow) { + const options = { + buttons: ['OK'], + icon: `${__dirname}/assets/lisk.png`, + message: `Lisk Nano\nVersion ${app.getVersion()}\n${copyright}`, + }; + electron.dialog.showMessageBox(focusedWindow, options, () => {}); + } + }, + }); + } + return Menu.buildFromTemplate(template); +}; From 6e4d24ca6dc8c84eda9e8fd7a86b15bab7bed410 Mon Sep 17 00:00:00 2001 From: Aleksey Popov Date: Tue, 19 Sep 2017 15:37:27 +0300 Subject: [PATCH 02/12] setup launch protocol --- app/main.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++++ 2 files changed, 53 insertions(+) diff --git a/app/main.js b/app/main.js index 293eef960..819f48bbe 100644 --- a/app/main.js +++ b/app/main.js @@ -7,7 +7,19 @@ const { BrowserWindow } = electron; const { Menu } = electron; let win; +let isUILoaded = false; +let eventStack = []; + const copyright = `Copyright © 2016 - ${new Date().getFullYear()} Lisk Foundation`; +const protocolName = 'lisk'; + +const sendUrlToRouter = (url) => { + if (isUILoaded && win && win.webContents) { + win.webContents.send('openUrl', url); + } else { + eventStack.push({ event: 'openUrl', value: url }); + } +}; function createWindow() { const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize; @@ -25,6 +37,8 @@ function createWindow() { win.on('blur', () => win.webContents.send('blur')); win.on('focus', () => win.webContents.send('focus')); + if (process.platform === 'win32') { + sendUrlToRouter(process.argv.slice(1)); } Menu.setApplicationMenu(buildMenu(app, copyright)); @@ -58,6 +72,15 @@ function createWindow() { selectionMenu.popup(win); } }); + + // Resolve all events from stack when dom is ready + win.webContents.on('did-finish-load', () => { + isUILoaded = true; + if (eventStack.length > 0) { + eventStack.forEach(({ event, value }) => win.webContents.send(event, value)); + eventStack = []; + } + }); } app.on('ready', createWindow); @@ -81,3 +104,29 @@ app.on('activate', () => { createWindow(); } }); + +// Set app protocol +app.setAsDefaultProtocolClient(protocolName); + +// Force single instance application +const isSecondInstance = app.makeSingleInstance((argv) => { + if (process.platform === 'win32') { + sendUrlToRouter(argv.slice(1)); + } + if (win) { + if (win.isMinimized()) win.restore(); + win.focus(); + } +}); + +if (isSecondInstance) { + app.quit(); +} + +app.on('will-finish-launching', () => { + // Protocol handler for MacOS + app.on('open-url', (event, url) => { + event.preventDefault(); + sendUrlToRouter(url); + }); +}); diff --git a/package.json b/package.json index 196786b10..6f631ece4 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,10 @@ "build": { "appId": "io.lisk.nano", "productName": "Lisk Nano", + "protocols": { + "name": "lisk-nano", + "schemes": ["lisk"] + }, "artifactName": "lisk-nano-${os}-${arch}-${version}.${ext}", "linux": { "target": [ From 85df0e89921396aa9058712288bc9aab06ab0ad0 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 28 Sep 2017 16:59:54 +0200 Subject: [PATCH 03/12] Fix the step calculation --- src/utils/passphrase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/passphrase.js b/src/utils/passphrase.js index 25ac2d4af..7defa0c94 100644 --- a/src/utils/passphrase.js +++ b/src/utils/passphrase.js @@ -30,7 +30,7 @@ const leftPadd = (str, pad, length) => { * Resets previous settings and creates a step with a random length between 1.6% to 3.2% */ const init = (rand = Math.random()) => { - let step = Math.max((160 + Math.floor(rand * 160))); + let step = (160 + Math.floor(rand * 160)) / 100; step = step >= 0.01 ? step : step * 10; return { step, From 765b76203054c27d7554f9c5b018072e174676e2 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 28 Sep 2017 17:07:40 +0200 Subject: [PATCH 04/12] Fix the step calculation --- src/utils/passphrase.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/passphrase.js b/src/utils/passphrase.js index 25ac2d4af..62f6cd190 100644 --- a/src/utils/passphrase.js +++ b/src/utils/passphrase.js @@ -30,8 +30,8 @@ const leftPadd = (str, pad, length) => { * Resets previous settings and creates a step with a random length between 1.6% to 3.2% */ const init = (rand = Math.random()) => { - let step = Math.max((160 + Math.floor(rand * 160))); - step = step >= 0.01 ? step : step * 10; + let step = (160 + Math.floor(rand * 160)) / 100; + step = step >= 0.01 ? step : 0.1 + (step * 5); return { step, percentage: 0, From f86fcfac4d02c6d60aaf01a8868da358b90f370d Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 28 Sep 2017 18:17:36 +0200 Subject: [PATCH 05/12] Fixed the issue with showing the missing word --- src/components/passphrase/passphraseVerifier.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/passphrase/passphraseVerifier.js b/src/components/passphrase/passphraseVerifier.js index e097f53f4..f503d574d 100644 --- a/src/components/passphrase/passphraseVerifier.js +++ b/src/components/passphrase/passphraseVerifier.js @@ -19,11 +19,11 @@ class PassphraseConfirmator extends React.Component { } hideRandomWord(rand = Math.random()) { - const words = this.props.passphrase.trim().split(/\s+/); + const words = this.props.passphrase.trim().split(/\s+/).filter(item => item.length > 0); const index = Math.floor(rand * (words.length - 1)); this.setState({ - passphraseParts: this.props.passphrase.split(` ${words[index]} `), + passphraseParts: this.props.passphrase.split(words[index]), missing: words[index], answer: '', }); From 0b9df247defd52f1bdc66cbb4074ac62cb2afcf1 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 28 Sep 2017 18:38:23 +0200 Subject: [PATCH 06/12] Fix unit tests --- src/components/passphrase/passphraseVerifier.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/passphrase/passphraseVerifier.test.js b/src/components/passphrase/passphraseVerifier.test.js index 6f851a6b4..a5db0cf61 100644 --- a/src/components/passphrase/passphraseVerifier.test.js +++ b/src/components/passphrase/passphraseVerifier.test.js @@ -41,8 +41,8 @@ describe('PassphraseVerifier', () => { const randomIndex = 0.6; const expectedValues = { passphraseParts: [ - 'survey stereo pool fortune oblige slight', - 'goddess mistake sentence anchor pool', + 'survey stereo pool fortune oblige slight ', + ' goddess mistake sentence anchor pool', ], missing: 'gravity', answer: '', From 1b5c694e148d9dd570fa5ca692e787cc71f129e4 Mon Sep 17 00:00:00 2001 From: Aleksey Popov Date: Thu, 28 Sep 2017 22:17:53 +0300 Subject: [PATCH 07/12] use `onSubmit` event in `Login` component --- src/components/login/login.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/login/login.js b/src/components/login/login.js index 0b54a5b18..f954a4dee 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -135,6 +135,11 @@ class Login extends React.Component { } } + onFormSubmit(event) { + event.preventDefault(); + this.onLoginSubmission(this.state.passphrase); + } + autoLogin() { const { savedAccounts } = this.props; if (savedAccounts && savedAccounts.length > 0 && !this.props.account.afterLogout) { @@ -160,7 +165,7 @@ class Login extends React.Component {
-
+ {this.props.t('New Account')}
From 66ffabd7e73f78205123b365e573ee036522b879 Mon Sep 17 00:00:00 2001 From: Aleksey Popov Date: Thu, 28 Sep 2017 22:45:05 +0300 Subject: [PATCH 08/12] use `onSubmit` event in `Send` component --- src/components/actionBar/index.js | 4 +- src/components/pricedButton/index.js | 3 +- src/components/send/send.js | 75 +++++++++++++++------------- src/components/send/send.test.js | 2 +- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/components/actionBar/index.js b/src/components/actionBar/index.js index 7b255ad22..4cf130b21 100644 --- a/src/components/actionBar/index.js +++ b/src/components/actionBar/index.js @@ -11,7 +11,8 @@ const ActionBar = ({
); } From c640750dc1cf30bdefb953fe1ba3ad5ae05b31db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Fri, 29 Sep 2017 09:00:28 +0200 Subject: [PATCH 12/12] Prevent NPE for recovery notification Check if there is a previous build before trying to find out its result. --- Jenkinsfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 73c104ba8..92d08dba3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -148,8 +148,13 @@ node('lisk-nano-01'){ } milestone 1 /* notify of success if previous build failed */ - if (currentBuild.getPreviousBuild().result == 'FAILURE') { - slackSend color: 'good', message: "Recovery: build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}> was sucessful.", channel: '#lisk-nano-jenkins' + previous_build = currentBuild.getPreviousBuild() + if (previous_build != null && previous_build.result == 'FAILURE') { + def pr_branch = '' + if (env.CHANGE_BRANCH != null) { + pr_branch = " (${env.CHANGE_BRANCH})" + } + slackSend color: 'good', message: "Recovery: build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch} was successful.", channel: '#lisk-nano-jenkins' } } }