electron-126: implemented changes for single user install in user config

This commit is contained in:
Vishwas Shashidhar
2017-09-06 22:06:00 +05:30
parent 55c3714b2b
commit 1049807a14
2 changed files with 21 additions and 37 deletions

View File

@@ -15,6 +15,9 @@ const childProcess = require('child_process');
const AppDirectory = require('appdirectory'); const AppDirectory = require('appdirectory');
const dirs = new AppDirectory('Symphony'); const dirs = new AppDirectory('Symphony');
const log = require('../log.js');
const logLevels = require('./enums/logLevels.js');
// cached config when first reading files. initially undefined and will be // cached config when first reading files. initially undefined and will be
// updated when read from disk. // updated when read from disk.
let userConfig; let userConfig;
@@ -250,28 +253,31 @@ function updateUserConfig(newGlobalConfig, oldUserConfig) {
* @returns {Promise} * @returns {Promise}
*/ */
function updateUserConfigWin(perUserInstall) { function updateUserConfigWin(perUserInstall) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// we get the user config path using electron
const userConfigFile = path.join(app.getPath('userData'), configFileName); const userConfigFile = path.join(app.getPath('userData'), configFileName);
// flag to determine whether per user installation
if (!perUserInstall) { // if it's not a per user installation or if the
// user config file doesn't exist, we simple move on
if (!perUserInstall || !fs.existsSync(userConfigFile)) {
log.send(logLevels.WARN, 'config: Could not find the user config file!');
reject(); reject();
return; return;
} }
// if user config file does't exists just copy global config file fs.unlink(userConfigFile, (err) => {
if (!fs.existsSync(userConfigFile)) { if (err) {
resolve(copyConfigWin()); log.send(logLevels.ERROR, 'config: Could not delete the user config file!');
return; reject();
} return;
}
resolve();
});
Promise.all([readGlobalConfig(), readUserConfig(userConfigFile)])
.then((data) => {
resolve(updateUserConfig(data[0], data[1]));
})
.catch((err) => {
reject(err);
});
}); });
} }
/** /**
@@ -299,27 +305,6 @@ function updateUserConfigMac(globalConfigPath) {
}); });
} }
/**
* Method to copy global config file to user config directory for Windows
* @returns {Promise}
*/
function copyConfigWin() {
return new Promise((resolve, reject) => {
const globalConfigFileName = path.join('config', configFileName);
const execPath = path.dirname(app.getPath('exe'));
const globalConfigPath = path.join(execPath, '', globalConfigFileName);
const userConfigPath = app.getPath('userData');
childProcess.exec(`echo D|xcopy /y /e /s /c "${globalConfigPath}" "${userConfigPath}"`, { timeout: 60000 }, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
}
/** /**
* Method which copies global config file to user config directory for mac * Method which copies global config file to user config directory for mac
* @param {String} globalConfigPath - The global config path from installer * @param {String} globalConfigPath - The global config path from installer

View File

@@ -117,8 +117,7 @@ function setupThenOpenMainWindow() {
isAppAlreadyOpen = true; isAppAlreadyOpen = true;
// allows installer to launch app and set auto startup mode then // allows installer to launch app and set appropriate global / user config params.
// immediately quit.
let hasInstallFlag = getCmdLineArg(process.argv, '--install', true); let hasInstallFlag = getCmdLineArg(process.argv, '--install', true);
let perUserInstall = getCmdLineArg(process.argv, '--peruser', true); let perUserInstall = getCmdLineArg(process.argv, '--peruser', true);
if (!isMac && hasInstallFlag) { if (!isMac && hasInstallFlag) {