From 389f83e7ec3969f27ced7dc615fe60ae948a3a9d Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 11 Jan 2021 16:20:18 +0200 Subject: [PATCH 01/14] Set scheduler rule from stored configs to backend --- server.js | 4 +++- src/run-server.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 13d4cd66..464471dd 100644 --- a/server.js +++ b/server.js @@ -40,6 +40,7 @@ let isMigrationsError = false try { const pathToUserData = process.env.PATH_TO_USER_DATA const pathToUserCsv = process.env.PATH_TO_USER_CSV + const schedulerRule = process.env.SCHEDULER_RULE const secretKey = process.env.SECRET_KEY if (!secretKey) { @@ -120,7 +121,8 @@ let isMigrationsError = false `--logsFolder=${pathToUserData}/logs`, `--dbFolder=${pathToUserData}`, `--grape=${grape}`, - `--secretKey=${secretKey}` + `--secretKey=${secretKey}`, + `--schedulerRule=${schedulerRule}` ], { env, cwd: process.cwd(), diff --git a/src/run-server.js b/src/run-server.js index 4dd0075a..d5ef2abb 100644 --- a/src/run-server.js +++ b/src/run-server.js @@ -12,11 +12,14 @@ module.exports = ({ pathToUserData, secretKey }) => { + const mainConfsKeeper = getConfigsKeeperByName('main') const env = { ...process.env, PATH_TO_USER_DATA: pathToUserData, - PATH_TO_USER_CSV: getConfigsKeeperByName('main') + PATH_TO_USER_CSV: mainConfsKeeper .getConfigByName('pathToUserCsv'), + SCHEDULER_RULE: mainConfsKeeper + .getConfigByName('schedulerRule'), SECRET_KEY: secretKey } const ipc = fork(serverPath, [], { From 4cf00afbd33d277f799de13bb84a442f765a48e6 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 11 Jan 2021 16:56:00 +0200 Subject: [PATCH 02/14] Add menu item for changing sync frequency --- src/change-sync-frequency.js | 40 ++++++++++++++++++++++++++++++++++ src/create-menu.js | 6 +++++ src/errors/index.js | 9 +++++++- src/show-error-modal-dialog.js | 8 ++++++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/change-sync-frequency.js diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js new file mode 100644 index 00000000..8975ed08 --- /dev/null +++ b/src/change-sync-frequency.js @@ -0,0 +1,40 @@ +'use strict' + +const electron = require('electron') + +const { + SyncFrequencyChangingError +} = require('./errors') +const showErrorModalDialog = require('./show-error-modal-dialog') +const pauseApp = require('./pause-app') +const relaunch = require('./relaunch') +const { getConfigsKeeperByName } = require('./configs-keeper') + +module.exports = () => { + return async () => { + const win = electron.BrowserWindow.getFocusedWindow() + + try { + const schedulerRule = '' // TODO: + + await pauseApp() + const isSaved = await getConfigsKeeperByName('main') + .saveConfigs({ schedulerRule }) + + if (!isSaved) { + throw new SyncFrequencyChangingError() + } + + relaunch() + } catch (err) { + try { + await showErrorModalDialog(win, 'Change sync frequency', err) + } catch (err) { + console.error(err) + } + + console.error(err) + relaunch() + } + } +} diff --git a/src/create-menu.js b/src/create-menu.js index e20b946d..45a34de6 100644 --- a/src/create-menu.js +++ b/src/create-menu.js @@ -9,6 +9,7 @@ const exportDB = require('./export-db') const importDB = require('./import-db') const removeDB = require('./remove-db') const changeReportsFolder = require('./change-reports-folder') +const changeSyncFrequency = require('./change-sync-frequency') const triggerElectronLoad = require('./trigger-electron-load') const showAboutModalDialog = require('./show-about-modal-dialog') @@ -81,6 +82,11 @@ module.exports = ({ label: 'Change reports folder', accelerator: 'CmdOrCtrl+F', click: changeReportsFolder({ pathToUserDocuments }) + }, + { + label: 'Change sync frequency', + accelerator: 'CmdOrCtrl+S', + click: changeSyncFrequency() } ] }, diff --git a/src/errors/index.js b/src/errors/index.js index 9bd89d2b..34109044 100644 --- a/src/errors/index.js +++ b/src/errors/index.js @@ -89,6 +89,12 @@ class ReportsFolderChangingError extends BaseError { } } +class SyncFrequencyChangingError extends BaseError { + constructor (message = 'ERR_SYNC_FREQUENCY_HAS_NOT_CHANGED') { + super(message) + } +} + module.exports = { BaseError, InvalidFilePathError, @@ -103,5 +109,6 @@ module.exports = { WrongPathToUserDataError, WrongPathToUserCsvError, WrongSecretKeyError, - ReportsFolderChangingError + ReportsFolderChangingError, + SyncFrequencyChangingError } diff --git a/src/show-error-modal-dialog.js b/src/show-error-modal-dialog.js index 6046da06..e689e22e 100644 --- a/src/show-error-modal-dialog.js +++ b/src/show-error-modal-dialog.js @@ -6,7 +6,8 @@ const { DbImportingError, DbRemovingError, InvalidFolderPathError, - ReportsFolderChangingError + ReportsFolderChangingError, + SyncFrequencyChangingError } = require('./errors') const showMessageModalDialog = require('./show-message-modal-dialog') @@ -66,6 +67,11 @@ module.exports = async (win, title = 'Error', err) => { return _showErrorBox(win, title, message) } + if (err instanceof SyncFrequencyChangingError) { + const message = 'The sync frequency has not been changed' + + return _showErrorBox(win, title, message) + } const message = 'An unexpected exception occurred' From 5a83d7d010dd80b1f4f8ff36fa4f657ad56bcaff Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Tue, 12 Jan 2021 16:30:41 +0200 Subject: [PATCH 03/14] Fix setting scheduler rule to grenache service --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 464471dd..466b7e1d 100644 --- a/server.js +++ b/server.js @@ -122,7 +122,7 @@ let isMigrationsError = false `--dbFolder=${pathToUserData}`, `--grape=${grape}`, `--secretKey=${secretKey}`, - `--schedulerRule=${schedulerRule}` + `--schedulerRule=${schedulerRule || ''}` ], { env, cwd: process.cwd(), From a11d94a90d93f04a7f18c1cc56cafc241e0e3e28 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Tue, 12 Jan 2021 23:26:18 +0200 Subject: [PATCH 04/14] Add modal dialogs to set time format and value --- package.json | 1 + src/change-sync-frequency.js | 109 +++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/package.json b/package.json index c9f6d3e7..b1a27d5e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "bfx-svc-test-helper": "git+https://github.com/bitfinexcom/bfx-svc-test-helper.git", "bittorrent-dht": "^8.4.0", "ed25519-supercop": "^2.0.1", + "electron-alert": "^0.1.11", "electron-serve": "^1.0.0", "find-free-port": "^2.0.0", "grenache-grape": "^0.9.8", diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index 8975ed08..38c0925b 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -1,6 +1,7 @@ 'use strict' const electron = require('electron') +const Alert = require('electron-alert') const { SyncFrequencyChangingError @@ -11,10 +12,118 @@ const relaunch = require('./relaunch') const { getConfigsKeeperByName } = require('./configs-keeper') module.exports = () => { + const timeFormatAlert = new Alert() + const alert = new Alert() + + const closeTimeFormatAlert = () => { + if (!timeFormatAlert.browserWindow) return + + timeFormatAlert.browserWindow.close() + } + const closeAlert = () => { + if (!alert.browserWindow) return + + alert.browserWindow.close() + } + + const timeFormatAlertOptions = { + title: 'Set time format', + type: 'question', + input: 'radio', + inputValue: 'mins', + inputOptions: { + mins: 'Mins', + hours: 'Hours', + days: 'Days' + }, + onBeforeOpen: () => { + if (!timeFormatAlert.browserWindow) return + + timeFormatAlert.browserWindow.once('blur', closeTimeFormatAlert) + } + } + const alertOptions = { + title: 'Set sync frequency', + text: timeFormatAlertOptions.inputOptions.mins, + type: 'question', + input: 'range', + inputValue: 20, + inputAttributes: { + min: 5, + max: 60, + step: 1 + }, + onBeforeOpen: () => { + if (!alert.browserWindow) return + + alert.browserWindow.once('blur', closeAlert) + } + } + const sound = { freq: 'F2', type: 'triange', duration: 1.5 } + + const getAlertOpts = (timeFormat) => { + const { inputAttributes } = alertOptions + const { inputOptions } = timeFormatAlertOptions + const text = inputOptions[timeFormat.value] + + if (timeFormat.value === 'hours') { + return { + ...alertOptions, + text, + inputValue: 1, + inputAttributes: { + ...inputAttributes, + min: 1, + max: 24 + } + } + } + if (timeFormat.value === 'days') { + return { + ...alertOptions, + text, + inputValue: 1, + inputAttributes: { + ...inputAttributes, + min: 1, + max: 30 + } + } + } + + return alertOptions + } + return async () => { const win = electron.BrowserWindow.getFocusedWindow() + win.once('closed', closeTimeFormatAlert) + win.once('closed', closeAlert) try { + const timeFormat = await timeFormatAlert.fireFrameless( + timeFormatAlertOptions, null, true, false, sound + ) + win.removeListener('closed', closeTimeFormatAlert) + + if ( + timeFormat.dismiss === Alert.DismissReason.cancel || + timeFormat.dismiss === Alert.DismissReason.close + ) { + return + } + + const alertRes = await alert.fireFrameless( + getAlertOpts(timeFormat), null, true, false, sound + ) + win.removeListener('closed', closeAlert) + + if ( + timeFormat.dismiss === Alert.DismissReason.cancel || + timeFormat.dismiss === Alert.DismissReason.close + ) { + return + } + const schedulerRule = '' // TODO: await pauseApp() From 8e492540ede76c8ab6eb66b5fdea32b513e0bca3 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 13 Jan 2021 20:54:38 +0200 Subject: [PATCH 05/14] Apply scheduler rule by default --- src/initialize-app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/initialize-app.js b/src/initialize-app.js index a8c1a36e..8a012e1a 100644 --- a/src/initialize-app.js +++ b/src/initialize-app.js @@ -39,6 +39,10 @@ const pathToLayoutAppInitErr = path const pathToLayoutExprPortReq = path .join(pathToLayouts, 'express-port-required.html') +const { rule: schedulerRule } = require( + '../bfx-reports-framework/config/schedule.json' +) + const _ipcMessToPromise = (ipc) => { return new Promise((resolve, reject) => { try { @@ -74,7 +78,8 @@ module.exports = () => { { pathToUserCsv: process.platform === 'darwin' ? pathToUserDocuments - : '../../..' + : '../../..', + schedulerRule } ) const secretKey = await makeOrReadSecretKey( From 849842646a7cd56ebcedc6dee553d4dbd964db72 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 13 Jan 2021 21:00:51 +0200 Subject: [PATCH 06/14] Generate cron rule from setting modal dialogs values --- src/change-sync-frequency.js | 52 +++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index 38c0925b..69142eb4 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -11,7 +11,19 @@ const pauseApp = require('./pause-app') const relaunch = require('./relaunch') const { getConfigsKeeperByName } = require('./configs-keeper') +const _getSchedulerRule = (timeFormat, alertRes) => { + if (timeFormat.value === 'days') { + return `0 0 */${alertRes.value} * *` + } + if (timeFormat.value === 'hours') { + return `0 */${alertRes.value} * * *` + } + + return `*/${alertRes.value} * * * *` +} + module.exports = () => { + const configsKeeper = getConfigsKeeperByName('main') const timeFormatAlert = new Alert() const alert = new Alert() @@ -30,7 +42,7 @@ module.exports = () => { title: 'Set time format', type: 'question', input: 'radio', - inputValue: 'mins', + inputValue: 'hours', inputOptions: { mins: 'Mins', hours: 'Hours', @@ -44,15 +56,8 @@ module.exports = () => { } const alertOptions = { title: 'Set sync frequency', - text: timeFormatAlertOptions.inputOptions.mins, type: 'question', input: 'range', - inputValue: 20, - inputAttributes: { - min: 5, - max: 60, - step: 1 - }, onBeforeOpen: () => { if (!alert.browserWindow) return @@ -62,36 +67,44 @@ module.exports = () => { const sound = { freq: 'F2', type: 'triange', duration: 1.5 } const getAlertOpts = (timeFormat) => { - const { inputAttributes } = alertOptions const { inputOptions } = timeFormatAlertOptions const text = inputOptions[timeFormat.value] - if (timeFormat.value === 'hours') { + if (timeFormat.value === 'days') { return { ...alertOptions, text, inputValue: 1, inputAttributes: { - ...inputAttributes, min: 1, - max: 24 + max: 31, + step: 1 } } } - if (timeFormat.value === 'days') { + if (timeFormat.value === 'hours') { return { ...alertOptions, text, inputValue: 1, inputAttributes: { - ...inputAttributes, min: 1, - max: 30 + max: 23, + step: 1 } } } - return alertOptions + return { + ...alertOptions, + text, + inputValue: 2, + inputAttributes: { + min: 10, + max: 59, + step: 1 + } + } } return async () => { @@ -124,10 +137,13 @@ module.exports = () => { return } - const schedulerRule = '' // TODO: + const schedulerRule = _getSchedulerRule( + timeFormat, + alertRes + ) await pauseApp() - const isSaved = await getConfigsKeeperByName('main') + const isSaved = await configsKeeper .saveConfigs({ schedulerRule }) if (!isSaved) { From e106f401e9d4204ab9848aa525749def50f73f07 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 13 Jan 2021 23:37:38 +0200 Subject: [PATCH 07/14] Parse cron rule saved in config to apply in modal dialogs --- package.json | 1 + src/change-sync-frequency.js | 72 +++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index b1a27d5e..a19873d2 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "async": "^2.6.1", "bfx-svc-test-helper": "git+https://github.com/bitfinexcom/bfx-svc-test-helper.git", "bittorrent-dht": "^8.4.0", + "cron-validate": "^1.4.2", "ed25519-supercop": "^2.0.1", "electron-alert": "^0.1.11", "electron-serve": "^1.0.0", diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index 69142eb4..3396134e 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -2,6 +2,7 @@ const electron = require('electron') const Alert = require('electron-alert') +const cronValidate = require('cron-validate') const { SyncFrequencyChangingError @@ -22,6 +23,43 @@ const _getSchedulerRule = (timeFormat, alertRes) => { return `*/${alertRes.value} * * * *` } +const _testTime = (time) => { + return ( + time && + typeof time === 'string' && + /^\*\/\d{1,2}$/i.test(time) + ) +} + +const _getTime = (timeFormat, time) => { + return { + timeFormat, + value: time.replace('*/', '') + } +} + +const _getTimeDataFromRule = (rule) => { + const cronResult = cronValidate(rule) + + if (!cronResult.isValid()) { + return { timeFormat: 'hours', value: 2 } + } + + const value = cronResult.getValue() + + if (_testTime(value.daysOfMonth)) { + return _getTime('days', value.daysOfMonth) + } + if (_testTime(value.hours)) { + return _getTime('hours', value.hours) + } + if (_testTime(value.minutes)) { + return _getTime('mins', value.minutes) + } + + return { timeFormat: 'hours', value: 2 } +} + module.exports = () => { const configsKeeper = getConfigsKeeperByName('main') const timeFormatAlert = new Alert() @@ -66,7 +104,7 @@ module.exports = () => { } const sound = { freq: 'F2', type: 'triange', duration: 1.5 } - const getAlertOpts = (timeFormat) => { + const getAlertOpts = (timeFormat, timeData) => { const { inputOptions } = timeFormatAlertOptions const text = inputOptions[timeFormat.value] @@ -74,7 +112,8 @@ module.exports = () => { return { ...alertOptions, text, - inputValue: 1, + inputValue: timeFormat.value === timeData.timeFormat + ? timeData.value : 1, inputAttributes: { min: 1, max: 31, @@ -86,7 +125,8 @@ module.exports = () => { return { ...alertOptions, text, - inputValue: 1, + inputValue: timeFormat.value === timeData.timeFormat + ? timeData.value : 2, inputAttributes: { min: 1, max: 23, @@ -98,7 +138,8 @@ module.exports = () => { return { ...alertOptions, text, - inputValue: 2, + inputValue: timeFormat.value === timeData.timeFormat + ? timeData.value : 20, inputAttributes: { min: 10, max: 59, @@ -113,27 +154,30 @@ module.exports = () => { win.once('closed', closeAlert) try { + const savedSchedulerRule = await configsKeeper + .getConfigByName('schedulerRule') + const timeData = _getTimeDataFromRule(savedSchedulerRule) + const timeFormat = await timeFormatAlert.fireFrameless( - timeFormatAlertOptions, null, true, false, sound + { + ...timeFormatAlertOptions, + inputValue: timeData.timeFormat + }, + null, true, false, sound ) win.removeListener('closed', closeTimeFormatAlert) - if ( - timeFormat.dismiss === Alert.DismissReason.cancel || - timeFormat.dismiss === Alert.DismissReason.close - ) { + if (timeFormat.dismiss) { return } const alertRes = await alert.fireFrameless( - getAlertOpts(timeFormat), null, true, false, sound + getAlertOpts(timeFormat, timeData), + null, true, false, sound ) win.removeListener('closed', closeAlert) - if ( - timeFormat.dismiss === Alert.DismissReason.cancel || - timeFormat.dismiss === Alert.DismissReason.close - ) { + if (alertRes.dismiss) { return } From 8be311b975587af612aa5c8978cb709361bcfc74 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 14 Jan 2021 19:48:47 +0200 Subject: [PATCH 08/14] Customize sync frequency modal dialogs --- src/change-sync-frequency.js | 29 +++++++++++++++++++++++++++-- src/styles/modal-dialog.css | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/styles/modal-dialog.css diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index 3396134e..332eb67d 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -3,6 +3,13 @@ const electron = require('electron') const Alert = require('electron-alert') const cronValidate = require('cron-validate') +const path = require('path') +const fs = require('fs') + +const modalDialogStyle = fs.readFileSync(path.join( + __dirname, 'styles/modal-dialog.css' +)) +const style = `` const { SyncFrequencyChangingError @@ -62,8 +69,8 @@ const _getTimeDataFromRule = (rule) => { module.exports = () => { const configsKeeper = getConfigsKeeperByName('main') - const timeFormatAlert = new Alert() - const alert = new Alert() + const timeFormatAlert = new Alert([style]) + const alert = new Alert([style]) const closeTimeFormatAlert = () => { if (!timeFormatAlert.browserWindow) return @@ -79,6 +86,15 @@ module.exports = () => { const timeFormatAlertOptions = { title: 'Set time format', type: 'question', + background: '#172d3e', + customClass: { + title: 'titleColor', + content: 'textColor', + input: 'textColor radioInput' + }, + focusConfirm: true, + progressSteps: [1, 2], + currentProgressStep: 0, input: 'radio', inputValue: 'hours', inputOptions: { @@ -95,6 +111,15 @@ module.exports = () => { const alertOptions = { title: 'Set sync frequency', type: 'question', + background: '#172d3e', + customClass: { + title: 'titleColor', + content: 'textColor', + input: 'textColor' + }, + focusConfirm: true, + progressSteps: [1, 2], + currentProgressStep: 1, input: 'range', onBeforeOpen: () => { if (!alert.browserWindow) return diff --git a/src/styles/modal-dialog.css b/src/styles/modal-dialog.css new file mode 100644 index 00000000..91331cb6 --- /dev/null +++ b/src/styles/modal-dialog.css @@ -0,0 +1,21 @@ +.radioInput input { + -webkit-appearance: none; + margin: -5px 10px -4px 5px; + border: solid 2px #f5f8fa; + cursor: pointer; + width: 24px; + height: 24px; + border-radius: 12px; +} + +.radioInput input:checked { + background-color: #3085d6; +} + +.textColor { + color: #f5f8fa; +} + +.titleColor { + color: #82baf6; +} From 612ef9ee46c4cc4d9315b0cf05cda21608d1b310 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 15 Jan 2021 17:28:55 +0200 Subject: [PATCH 09/14] Improve range input actions for sync frequency --- src/change-sync-frequency.js | 13 +++-- src/modal-dialog-src/modal-dialog.css | 72 +++++++++++++++++++++++++++ src/modal-dialog-src/modal-dialog.js | 30 +++++++++++ src/styles/modal-dialog.css | 21 -------- 4 files changed, 111 insertions(+), 25 deletions(-) create mode 100644 src/modal-dialog-src/modal-dialog.css create mode 100644 src/modal-dialog-src/modal-dialog.js delete mode 100644 src/styles/modal-dialog.css diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index 332eb67d..b5e18ff2 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -7,9 +7,11 @@ const path = require('path') const fs = require('fs') const modalDialogStyle = fs.readFileSync(path.join( - __dirname, 'styles/modal-dialog.css' + __dirname, 'modal-dialog-src/modal-dialog.css' +)) +const modalDialogScript = fs.readFileSync(path.join( + __dirname, 'modal-dialog-src/modal-dialog.js' )) -const style = `` const { SyncFrequencyChangingError @@ -67,10 +69,13 @@ const _getTimeDataFromRule = (rule) => { return { timeFormat: 'hours', value: 2 } } +const style = `` +const script = `` + module.exports = () => { const configsKeeper = getConfigsKeeperByName('main') const timeFormatAlert = new Alert([style]) - const alert = new Alert([style]) + const alert = new Alert([style, script]) const closeTimeFormatAlert = () => { if (!timeFormatAlert.browserWindow) return @@ -115,7 +120,7 @@ module.exports = () => { customClass: { title: 'titleColor', content: 'textColor', - input: 'textColor' + input: 'textColor rangeInput' }, focusConfirm: true, progressSteps: [1, 2], diff --git a/src/modal-dialog-src/modal-dialog.css b/src/modal-dialog-src/modal-dialog.css new file mode 100644 index 00000000..54e53a92 --- /dev/null +++ b/src/modal-dialog-src/modal-dialog.css @@ -0,0 +1,72 @@ +.rangeInput { + display: flex; + align-items: center; +} + +.radioInput input[type=radio] { + -webkit-appearance: none; + margin: -5px 10px -4px 5px; + border: 2px solid #f5f8fa; + cursor: pointer; + width: 28px; + height: 28px; + border-radius: 14px; +} + +.radioInput input[type=radio]:focus { + outline: none; +} + +.radioInput input[type=radio]:checked { + background-color: #3085d6; +} + +.rangeInput output { + width: 20%; +} + +.rangeInput input[type=range] { + margin: 0; + background: #f5f8fa; + border: 0.2px solid #010101; + border-radius: 1.3px; + height: 6.4px; + width: 80%; + -webkit-appearance: none; +} + +.rangeInput input[type=range]:focus { + outline: none; +} + +.rangeInput input[type=range]::-webkit-slider-runnable-track { + background-color: transparent; + width: 100%; + height: 6.4px; + cursor: pointer; + -webkit-appearance: none; +} + +.rangeInput input[type=range]::-webkit-slider-thumb { + margin-top: -10.8px; + width: 28px; + height: 28px; + background: #3085d6; + border: none; + border-radius: 14px; + cursor: pointer; + -webkit-appearance: none; + box-shadow: -800px 0 0 -10.8px #3085d6; +} + +.rangeInput input[type=range]:focus::-webkit-slider-runnable-track { + background-image: linear-gradient(rgba(0,0,0,.2),rgba(0,0,0,.2)); +} + +.textColor { + color: #f5f8fa; +} + +.titleColor { + color: #82baf6; +} diff --git a/src/modal-dialog-src/modal-dialog.js b/src/modal-dialog-src/modal-dialog.js new file mode 100644 index 00000000..a02c5d39 --- /dev/null +++ b/src/modal-dialog-src/modal-dialog.js @@ -0,0 +1,30 @@ +'use strict' + +window.addEventListener('load', () => { + const inputs = document.querySelectorAll('.rangeInput input') + + const resizeProgress = (e) => { + try { + const target = e && e.target ? e.target : e + const val = Number.parseFloat(target.value) + const min = Number.parseFloat(target.min) + const max = Number.parseFloat(target.max) + const per = (((val - min) * 100) / (max - min)) + + target.style.background = `linear-gradient( + to right, + #3085d6 0%, + #3085d6 ${per}%, + #f5f8fa ${per}%, + #f5f8fa 100% + )` + } catch (err) { + console.error(err) + } + } + + for (const input of inputs) { + input.addEventListener('input', resizeProgress) + resizeProgress(input) + } +}) diff --git a/src/styles/modal-dialog.css b/src/styles/modal-dialog.css deleted file mode 100644 index 91331cb6..00000000 --- a/src/styles/modal-dialog.css +++ /dev/null @@ -1,21 +0,0 @@ -.radioInput input { - -webkit-appearance: none; - margin: -5px 10px -4px 5px; - border: solid 2px #f5f8fa; - cursor: pointer; - width: 24px; - height: 24px; - border-radius: 12px; -} - -.radioInput input:checked { - background-color: #3085d6; -} - -.textColor { - color: #f5f8fa; -} - -.titleColor { - color: #82baf6; -} From e734eb4ae6f682a471510bf198dbe1a44701469f Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 15 Jan 2021 17:52:22 +0200 Subject: [PATCH 10/14] Dont relaunch app when sets same sync frequency --- src/change-sync-frequency.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index b5e18ff2..f95b1b78 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -216,6 +216,10 @@ module.exports = () => { alertRes ) + if (savedSchedulerRule === schedulerRule) { + return + } + await pauseApp() const isSaved = await configsKeeper .saveConfigs({ schedulerRule }) From 74c2a3495d06e2e271093bbc005260c0f21d9d18 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 18 Jan 2021 15:59:54 +0200 Subject: [PATCH 11/14] Add cancel btn because blur event is not fired on mac --- src/change-sync-frequency.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/change-sync-frequency.js b/src/change-sync-frequency.js index f95b1b78..4d8071af 100644 --- a/src/change-sync-frequency.js +++ b/src/change-sync-frequency.js @@ -98,6 +98,7 @@ module.exports = () => { input: 'textColor radioInput' }, focusConfirm: true, + showCancelButton: true, progressSteps: [1, 2], currentProgressStep: 0, input: 'radio', @@ -123,6 +124,7 @@ module.exports = () => { input: 'textColor rangeInput' }, focusConfirm: true, + showCancelButton: true, progressSteps: [1, 2], currentProgressStep: 1, input: 'range', From 6bf07ab826e3a7911ac74c2db11534fc71987049 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 18 Jan 2021 21:29:39 +0200 Subject: [PATCH 12/14] Update ui env configs --- scripts/build-ui.sh | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/scripts/build-ui.sh b/scripts/build-ui.sh index f5866948..d759df5c 100755 --- a/scripts/build-ui.sh +++ b/scripts/build-ui.sh @@ -2,6 +2,8 @@ set -x +export CI_ENVIRONMENT_NAME=production + ROOT="$PWD" frontendFolder="$ROOT/bfx-report-ui" pathToTriggerElectronLoad="$frontendFolder/src/utils/triggerElectronLoad.js" @@ -58,32 +60,35 @@ if ! [ -s "$frontendFolder/package.json" ]; then exit 1 fi -cp -f "$frontendFolder/.env.example" "$frontendFolder/.env" -sed -i -e \ - "s/REACT_APP_ELECTRON=.*/REACT_APP_ELECTRON=true/g" \ - $frontendFolder/.env - -npm i --no-audit - sed -i -e \ "s/API_URL: .*,/API_URL: \'http:\/\/localhost:34343\/api\',/g" \ - $frontendFolder/src/var/config.js + $frontendFolder/src/config.js sed -i -e \ "s/WS_ADDRESS: .*,/WS_ADDRESS: \'ws:\/\/localhost:34343\/ws\',/g" \ - $frontendFolder/src/var/config.js + $frontendFolder/src/config.js if [ $isDevEnv != 0 ]; then + export CI_ENVIRONMENT_NAME=development + sed -i -e \ - "s/KEY_URL: .*,/KEY_URL: \'https:\/\/test.bitfinex.com\/api\',/g" \ - $frontendFolder/src/var/config.js + "s/KEY_URL: .*,/KEY_URL: \'https:\/\/api.staging.bitfinex.com\/api\',/g" \ + $frontendFolder/src/config.js fi sed -i -e \ - "s/showAuthPage: .*,/showAuthPage: true,/g" \ - $frontendFolder/src/var/config.js + "s/localExport: false/localExport: true/g" \ + $frontendFolder/src/config.js +sed -i -e \ + "s/showAuthPage: false/showAuthPage: true/g" \ + $frontendFolder/src/config.js +sed -i -e \ + "s/isElectronApp: false/isElectronApp: true/g" \ + $frontendFolder/src/config.js sed -i -e \ - "s/showFrameworkMode: .*,/showFrameworkMode: true,/g" \ - $frontendFolder/src/var/config.js + "s/showFrameworkMode: false/showFrameworkMode: true/g" \ + $frontendFolder/src/config.js + +npm i --no-audit npm run build mv -f $frontendFolder/build/* $uiBuildFolder From f3ff4517aa2dfb537358a0e5ec0cc8c3effd2f1d Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 28 Jan 2021 09:08:11 +0200 Subject: [PATCH 13/14] Exit with error when ui is not built --- scripts/build-ui.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/build-ui.sh b/scripts/build-ui.sh index d759df5c..4f9092be 100755 --- a/scripts/build-ui.sh +++ b/scripts/build-ui.sh @@ -91,6 +91,10 @@ sed -i -e \ npm i --no-audit npm run build +if ! [ -s "$frontendFolder/build/index.html" ]; then + exit 1 +fi + mv -f $frontendFolder/build/* $uiBuildFolder cp $pathToTriggerElectronLoad $uiBuildFolder/triggerElectronLoad.js touch $uiReadyFile From 7ab87d6fa5546ce568f8a6a7e144fced5bc2bd99 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 28 Jan 2021 09:10:28 +0200 Subject: [PATCH 14/14] Remove eslint config from parent electron dir --- scripts/build-ui.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/build-ui.sh b/scripts/build-ui.sh index 4f9092be..d6f0fac1 100755 --- a/scripts/build-ui.sh +++ b/scripts/build-ui.sh @@ -88,6 +88,8 @@ sed -i -e \ "s/showFrameworkMode: false/showFrameworkMode: true/g" \ $frontendFolder/src/config.js +rm -f "$ROOT/.eslintrc" + npm i --no-audit npm run build