Skip to content

Commit 614ab30

Browse files
committed
Move manageConfigs helper into separate file
1 parent 965ce20 commit 614ab30

3 files changed

Lines changed: 66 additions & 60 deletions

File tree

src/helpers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const parseEnvValToBool = require('./parse-env-val-to-bool')
1919
const isBfxApiStaging = require('./is-bfx-api-staging')
2020
const waitPort = require('./wait-port')
2121
const getUIFontsAsCSSString = require('./get-ui-fonts-as-css-string')
22+
const manageConfigs = require('./manage-configs')
2223

2324
module.exports = {
2425
getFreePort,
@@ -33,5 +34,6 @@ module.exports = {
3334
parseEnvValToBool,
3435
isBfxApiStaging,
3536
waitPort,
36-
getUIFontsAsCSSString
37+
getUIFontsAsCSSString,
38+
manageConfigs
3739
}

src/helpers/manage-configs.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict'
2+
3+
const path = require('node:path')
4+
5+
const isMac = process.platform === 'darwin'
6+
const { REPORT_FILES_PATH_VERSION } = require('../const')
7+
8+
const {
9+
configsKeeperFactory
10+
} = require('../configs-keeper')
11+
12+
const _resetReportFilesPath = async (
13+
configsKeeper,
14+
opts = {}
15+
) => {
16+
const {
17+
pathToUserReportFiles
18+
} = opts
19+
20+
// Need to use a new report folder path for export
21+
const reportFilesPathVersion = configsKeeper
22+
.getConfigByName('reportFilesPathVersion')
23+
24+
if (reportFilesPathVersion === REPORT_FILES_PATH_VERSION) {
25+
return
26+
}
27+
28+
await configsKeeper.saveConfigs({
29+
reportFilesPathVersion: REPORT_FILES_PATH_VERSION,
30+
pathToUserReportFiles
31+
})
32+
}
33+
34+
module.exports = (params) => {
35+
const {
36+
pathToUserData,
37+
pathToUserDocuments,
38+
pathToUserDownloads
39+
} = params ?? {}
40+
41+
const pathToUserReportFiles = isMac
42+
? pathToUserDownloads
43+
: path.join(
44+
pathToUserDocuments,
45+
'bitfinex/reports'
46+
)
47+
48+
const configsKeeper = configsKeeperFactory(
49+
{
50+
pathToUserData,
51+
configsByDefault: { pathToUserReportFiles }
52+
}
53+
)
54+
_resetReportFilesPath(
55+
configsKeeper,
56+
{ pathToUserReportFiles }
57+
)
58+
59+
return configsKeeper
60+
}

src/initialize-app.js

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
'use strict'
22

33
const { app } = require('electron')
4-
const path = require('path')
54
const i18next = require('i18next')
65

7-
const isMac = process.platform === 'darwin'
8-
const { REPORT_FILES_PATH_VERSION } = require('./const')
9-
106
const TranslationIpcChannelHandlers = require(
117
'./window-creators/main-renderer-ipc-bridge/translation-ipc-channel-handlers'
128
)
@@ -37,17 +33,15 @@ const {
3733
} = require('./window-creators/change-loading-win-visibility-state')
3834
const WINDOW_NAMES = require('./window-creators/window.names')
3935
const makeOrReadSecretKey = require('./make-or-read-secret-key')
40-
const {
41-
configsKeeperFactory
42-
} = require('./configs-keeper')
4336
const {
4437
IpcMessageError,
4538
AppInitializationError
4639
} = require('./errors')
4740
const {
4841
deserializeError,
4942
getFreePort,
50-
initIpcChannelHandlers
43+
initIpcChannelHandlers,
44+
manageConfigs
5145
} = require('./helpers')
5246
const getUserDataPath = require('./helpers/get-user-data-path')
5347
const {
@@ -61,28 +55,6 @@ const manageWorkerMessages = require(
6155
)
6256
const printToPDF = require('./print-to-pdf')
6357

64-
const _resetReportFilesPath = async (
65-
configsKeeper,
66-
opts = {}
67-
) => {
68-
const {
69-
pathToUserReportFiles
70-
} = opts
71-
72-
// Need to use a new report folder path for export
73-
const reportFilesPathVersion = configsKeeper
74-
.getConfigByName('reportFilesPathVersion')
75-
76-
if (reportFilesPathVersion === REPORT_FILES_PATH_VERSION) {
77-
return
78-
}
79-
80-
await configsKeeper.saveConfigs({
81-
reportFilesPathVersion: REPORT_FILES_PATH_VERSION,
82-
pathToUserReportFiles
83-
})
84-
}
85-
8658
const _ipcMessToPromise = (ipc) => {
8759
return new Promise((resolve, reject) => {
8860
try {
@@ -131,34 +103,6 @@ const _ipcMessToPromise = (ipc) => {
131103
})
132104
}
133105

134-
const _manageConfigs = (params) => {
135-
const {
136-
pathToUserData,
137-
pathToUserDocuments,
138-
pathToUserDownloads
139-
} = params ?? {}
140-
141-
const pathToUserReportFiles = isMac
142-
? pathToUserDownloads
143-
: path.join(
144-
pathToUserDocuments,
145-
'bitfinex/reports'
146-
)
147-
148-
const configsKeeper = configsKeeperFactory(
149-
{
150-
pathToUserData,
151-
configsByDefault: { pathToUserReportFiles }
152-
}
153-
)
154-
_resetReportFilesPath(
155-
configsKeeper,
156-
{ pathToUserReportFiles }
157-
)
158-
159-
return configsKeeper
160-
}
161-
162106
module.exports = async () => {
163107
try {
164108
initIpcChannelHandlers(
@@ -187,7 +131,7 @@ module.exports = async () => {
187131
const pathToUserDocuments = app.getPath('documents')
188132
const pathToUserDownloads = app.getPath('downloads')
189133

190-
const configsKeeper = _manageConfigs({
134+
const configsKeeper = manageConfigs({
191135
pathToUserData,
192136
pathToUserDocuments,
193137
pathToUserDownloads

0 commit comments

Comments
 (0)