@@ -10,6 +10,7 @@ const AppPaths = require('./../utils/paths');
1010const settingsFile = AppPaths . desktopApp . settingsFile ;
1111const winCfgPath = AppPaths . desktopApp . winCfgPath ;
1212const apiConfigPath = AppPaths . apiConfigPath ;
13+ const clientConfigPath = AppPaths . clientConfigPath ;
1314
1415const encryptionController = require ( './encryption' ) ;
1516
@@ -254,6 +255,32 @@ const retrieveWinSettings = () => {
254255 return cachedWinSettings ;
255256} ;
256257
258+ /**
259+ * Retrieve client settings ( runtime-config.json )
260+ */
261+ const retrieveClientSettings = ( ) => {
262+ // no api settings ?
263+ if ( ! clientConfigPath ) {
264+ return { } ;
265+ }
266+
267+ // load settings
268+ let clientConfig = { } ;
269+ try {
270+ // check if api config file exists and
271+ if ( fs . existsSync ( clientConfigPath ) ) {
272+ // read api settings
273+ const clientConfigData = fs . readFileSync ( clientConfigPath , 'utf8' ) ;
274+ clientConfig = JSON . parse ( clientConfigData ) ;
275+ }
276+ } catch ( e ) {
277+ // NOTHING
278+ }
279+
280+ // finished loading api settings
281+ return clientConfig ;
282+ } ;
283+
257284/**
258285 * Retrieve api settings ( config.json )
259286 */
@@ -280,6 +307,36 @@ const retrieveAPISettings = () => {
280307 return apiConfig ;
281308} ;
282309
310+ /**
311+ * Update client settings ( runtime-config.json )
312+ * @return {boolean } True if saved with success, false otherwise
313+ */
314+ const updateClientSettings = ( settings ) => {
315+ // no settings ?
316+ if ( ! clientConfigPath ) {
317+ return false ;
318+ }
319+
320+ // convert settings to string if necessary
321+ settings = typeof settings === 'string' ?
322+ settings :
323+ JSON . stringify ( settings , null , 2 ) ;
324+
325+ // save settings
326+ try {
327+ fs . writeFileSync ( clientConfigPath , settings ) ;
328+ } catch ( e ) {
329+ // log error
330+ logger . error ( `Error saving client settings: ${ e } ` ) ;
331+
332+ // an error occurred
333+ return false ;
334+ }
335+
336+ // settings saved
337+ return true ;
338+ } ;
339+
283340/**
284341 * Update api settings ( config.json )
285342 * @return {boolean } True if saved with success, false otherwise
@@ -355,7 +412,9 @@ module.exports = {
355412 getEncryptionCapability,
356413 retrieveWinSettings,
357414 retrieveAPISettings,
415+ retrieveClientSettings,
358416 updateAPISettings,
417+ updateClientSettings,
359418 runMongoAsAService,
360419 runGoDataAPIAsAService
361420} ;
0 commit comments