diff --git a/package.json b/package.json index 451d26f3..13e51045 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bfx-report-electron", - "version": "3.5.4", + "version": "3.5.5", "repository": "https://github.com/bitfinexcom/bfx-report-electron", "description": "Reporting tool", "author": "bitfinex.com", diff --git a/server.js b/server.js index c1fc3641..f301a6d9 100644 --- a/server.js +++ b/server.js @@ -178,10 +178,10 @@ let isMigrationsError = false } const handlerErr = (err) => { ipc.removeListener('message', handlerMess) - + reject(err) } - + ipc.once('error', handlerErr) ipc.on('message', handlerMess) }) diff --git a/src/change-reports-folder.js b/src/change-reports-folder.js index dd649a51..30855c47 100644 --- a/src/change-reports-folder.js +++ b/src/change-reports-folder.js @@ -2,6 +2,8 @@ const electron = require('electron') +const { CSV_PATH_VERSION } = require('./const') + const { InvalidFilePathError, ReportsFolderChangingError @@ -51,7 +53,10 @@ module.exports = ({ pathToUserDocuments }) => { await pauseApp() const isSaved = await getConfigsKeeperByName('main') - .saveConfigs({ pathToUserCsv: filePaths[0] }) + .saveConfigs({ + csvPathVersion: CSV_PATH_VERSION, + pathToUserCsv: filePaths[0] + }) if (!isSaved) { throw new ReportsFolderChangingError() diff --git a/src/const.js b/src/const.js index 4b3948c5..400c7df6 100644 --- a/src/const.js +++ b/src/const.js @@ -6,6 +6,7 @@ const DB_FILE_NAME = 'db-sqlite_sync_m0.db' const DB_SHM_FILE_NAME = `${DB_FILE_NAME}-shm` const DB_WAL_FILE_NAME = `${DB_FILE_NAME}-wal` const SECRET_KEY_FILE_NAME = 'secret-key' +const CSV_PATH_VERSION = 1 module.exports = { CONFIGS_FILE_NAME, @@ -13,5 +14,6 @@ module.exports = { DB_FILE_NAME, DB_SHM_FILE_NAME, DB_WAL_FILE_NAME, - SECRET_KEY_FILE_NAME + SECRET_KEY_FILE_NAME, + CSV_PATH_VERSION } diff --git a/src/error-manager/index.js b/src/error-manager/index.js index 04fa2938..547b16f6 100644 --- a/src/error-manager/index.js +++ b/src/error-manager/index.js @@ -211,7 +211,7 @@ const initLogger = () => { const error = message.data.join(os.EOL) // Don't open a new issue when can't download differentially - // it would fallback to full download + // it would fallback to full download if (/Cannot download differentially/gi.test(error)) { return message } diff --git a/src/initialize-app.js b/src/initialize-app.js index 08835b97..51695b4d 100644 --- a/src/initialize-app.js +++ b/src/initialize-app.js @@ -3,6 +3,8 @@ const { app } = require('electron') const path = require('path') +const { CSV_PATH_VERSION } = require('./const') + const triggerElectronLoad = require('./trigger-electron-load') const wins = require('./windows') const ipcs = require('./ipcs') @@ -50,6 +52,55 @@ const { rule: schedulerRule } = require( '../bfx-reports-framework/config/schedule.json' ) +const _resetCsvPath = async ( + configsKeeper, + opts = {} +) => { + const { + pathToUserCsv, + isRelativeCsvPath + } = opts + + // Need to use a new csv folder path for export + const storedPathToUserCsv = configsKeeper + .getConfigByName('pathToUserCsv') + const csvPathVersion = configsKeeper + .getConfigByName('csvPathVersion') + + if (csvPathVersion === CSV_PATH_VERSION) { + return + } + if ( + ( + isRelativeCsvPath && + !storedPathToUserCsv.endsWith('csv') + ) || + ( + !isRelativeCsvPath && + !storedPathToUserCsv.endsWith('bitfinex/reports') + ) || + ( + !isRelativeCsvPath && + !path.isAbsolute(storedPathToUserCsv) + ) || + ( + isRelativeCsvPath && + path.isAbsolute(storedPathToUserCsv) + ) + ) { + await configsKeeper.saveConfigs({ + csvPathVersion: CSV_PATH_VERSION, + pathToUserCsv + }) + + return + } + + await configsKeeper.saveConfigs({ + csvPathVersion: CSV_PATH_VERSION + }) +} + const _ipcMessToPromise = (ipc) => { return new Promise((resolve, reject) => { try { @@ -101,31 +152,13 @@ module.exports = async () => { schedulerRule } ) - - // Need to use a new csv folder path for export - const storedPathToUserCsv = configsKeeper - .getConfigByName('pathToUserCsv') - - if ( - ( - isRelativeCsvPath && - !storedPathToUserCsv.endsWith('csv') - ) || - ( - !isRelativeCsvPath && - !storedPathToUserCsv.endsWith('bitfinex/reports') - ) || - ( - !isRelativeCsvPath && - !path.isAbsolute(storedPathToUserCsv) - ) || - ( - isRelativeCsvPath && - path.isAbsolute(storedPathToUserCsv) - ) - ) { - await configsKeeper.saveConfigs({ pathToUserCsv }) - } + _resetCsvPath( + configsKeeper, + { + pathToUserCsv, + isRelativeCsvPath + } + ) const secretKey = await makeOrReadSecretKey( { pathToUserData }