diff --git a/js/config.js b/js/config.js index 08cd7450..3a8ac50f 100644 --- a/js/config.js +++ b/js/config.js @@ -54,14 +54,18 @@ function getUserConfigField(fieldName) { }); } -function readUserConfig() { +function readUserConfig(customConfigPath) { return new Promise(function(resolve, reject) { if (userConfig) { resolve(userConfig); return; } - let configPath = path.join(app.getPath('userData'), configFileName); + let configPath = customConfigPath; + + if (!configPath) { + configPath = path.join(app.getPath('userData'), configFileName); + } fs.readFile(configPath, 'utf8', function(err, data) { if (err) { @@ -218,32 +222,6 @@ function updateUserConfig(newGlobalConfig, oldUserConfig) { }); } -/** - * Method to read user config data - * @param {String} userConfigFile - The user config file path - * @returns {Promise} - */ -function getUserConfigData(userConfigFile) { - return new Promise((resolve, reject) => { - fs.readFile(userConfigFile, 'utf8', (err, data) => { - if (err) { - reject('cannot open user config file: ' + userConfigFile + ', error: ' + err); - return; - } - - let userConfigData; - try { - // data is the contents of the text file we just read - userConfigData = JSON.parse(data); - } catch (e) { - reject('can not parse config file data: ' + data + ', error: ' + err); - return; - } - resolve(userConfigData); - }); - }); -} - /** * Method to overwrite user config on windows installer * @param {String} perUserInstall - Is a flag to determine whether we are installing for per user @@ -264,7 +242,7 @@ function updateUserConfigWin(perUserInstall) { return; } - Promise.all([readGlobalConfig(), getUserConfigData(userConfigFile)]) + Promise.all([readGlobalConfig(), readUserConfig(userConfigFile)]) .then((data) => { resolve(updateUserConfig(data[0], data[1])); }) @@ -289,13 +267,13 @@ function updateUserConfigMac(globalConfigPath) { return; } - Promise.all([readGlobalConfig(), getUserConfigData(userConfigFile)]) + Promise.all([readGlobalConfig(), readUserConfig(userConfigFile)]) .then((data) => { resolve(updateUserConfig(data[0], data[1])); }) .catch((err) => { reject(err); - }) + }); }); } diff --git a/js/main.js b/js/main.js index 128b03d6..1ad58563 100644 --- a/js/main.js +++ b/js/main.js @@ -120,8 +120,11 @@ function setupThenOpenMainWindow() { // as the app is launched as a root user we don't get // access to the config file let launchOnStartup = process.argv[3]; + // We wire this in via the post install script + // to get the config file path where the app is installed + let appGlobalConfigPath = process.argv[2]; setStartup(launchOnStartup) - .then(() => updateUserConfigMac(process.argv[2])) + .then(() => updateUserConfigMac(appGlobalConfigPath)) .then(app.quit) .catch(app.quit); return;