mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
ELECTRON-1129 - Fix first time launch issue (#590)
This commit is contained in:
parent
e8fb5bea91
commit
491a0ca24e
11
js/config.js
11
js/config.js
@ -265,6 +265,7 @@ function updateUserConfig(oldUserConfig) {
|
|||||||
reject(new Error(`Failed to update user config error: ${err}`));
|
reject(new Error(`Failed to update user config error: ${err}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
userConfig = newUserConfig;
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -275,7 +276,7 @@ function updateUserConfig(oldUserConfig) {
|
|||||||
* Manipulates user config on first time launch
|
* Manipulates user config on first time launch
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
function updateUserConfigOnLaunch() {
|
function updateUserConfigOnLaunch(resolve, reject) {
|
||||||
// we get the user config path using electron
|
// we get the user config path using electron
|
||||||
const userConfigFile = path.join(app.getPath('userData'), configFileName);
|
const userConfigFile = path.join(app.getPath('userData'), configFileName);
|
||||||
|
|
||||||
@ -283,7 +284,7 @@ function updateUserConfigOnLaunch() {
|
|||||||
// user config file doesn't exist, we simple move on
|
// user config file doesn't exist, we simple move on
|
||||||
if (!fs.existsSync(userConfigFile)) {
|
if (!fs.existsSync(userConfigFile)) {
|
||||||
log.send(logLevels.WARN, 'config: Could not find the user config file!');
|
log.send(logLevels.WARN, 'config: Could not find the user config file!');
|
||||||
return Promise.reject(new Error('config: Could not find the user config file!'));
|
return reject(new Error('config: Could not find the user config file!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case the file exists, we remove it so that all the
|
// In case the file exists, we remove it so that all the
|
||||||
@ -294,9 +295,11 @@ function updateUserConfigOnLaunch() {
|
|||||||
const version = app.getVersion().toString() || '1.0.0';
|
const version = app.getVersion().toString() || '1.0.0';
|
||||||
const updatedData = Object.assign(data || {}, { configVersion: version });
|
const updatedData = Object.assign(data || {}, { configVersion: version });
|
||||||
|
|
||||||
return updateUserConfig(updatedData);
|
updateUserConfig(updatedData)
|
||||||
|
.then(resolve)
|
||||||
|
.catch(reject);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
return Promise.reject(err);
|
return reject(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
48
js/main.js
48
js/main.js
@ -313,24 +313,27 @@ function setupThenOpenMainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkFirstTimeLaunch() {
|
function checkFirstTimeLaunch() {
|
||||||
return getUserConfigField('configVersion')
|
return new Promise((resolve, reject) => {
|
||||||
.then((configVersion) => {
|
getUserConfigField('configVersion')
|
||||||
const appVersionString = app.getVersion().toString();
|
.then((configVersion) => {
|
||||||
const execPath = nodePath.dirname(app.getPath('exe'));
|
const appVersionString = app.getVersion().toString();
|
||||||
const shouldUpdateUserConfig = execPath.indexOf('AppData\\Local\\Programs') !== -1 || isMac;
|
const execPath = nodePath.dirname(app.getPath('exe'));
|
||||||
|
const shouldUpdateUserConfig = execPath.indexOf('AppData\\Local\\Programs') !== -1 || isMac;
|
||||||
|
|
||||||
if (!(configVersion
|
if (!(configVersion
|
||||||
&& typeof configVersion === 'string'
|
&& typeof configVersion === 'string'
|
||||||
&& (compareSemVersions.check(appVersionString, configVersion) !== 1)) && shouldUpdateUserConfig) {
|
&& (compareSemVersions.check(appVersionString, configVersion) !== 1))) {
|
||||||
return setupFirstTimeLaunch();
|
return setupFirstTimeLaunch(resolve, reject, shouldUpdateUserConfig);
|
||||||
}
|
}
|
||||||
log.send(logLevels.INFO, `not a first-time launch as
|
log.send(logLevels.INFO, `not a first-time launch as
|
||||||
configVersion: ${configVersion} appVersion: ${appVersionString} shouldUpdateUserConfig: ${shouldUpdateUserConfig}`);
|
configVersion: ${configVersion} appVersion: ${appVersionString} shouldUpdateUserConfig: ${shouldUpdateUserConfig}`);
|
||||||
return Promise.resolve();
|
return resolve();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
return setupFirstTimeLaunch();
|
log.send(logLevels.ERROR, `Error reading configVersion error: ${e}`);
|
||||||
});
|
return setupFirstTimeLaunch(resolve, reject, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -339,11 +342,18 @@ function checkFirstTimeLaunch() {
|
|||||||
*
|
*
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
function setupFirstTimeLaunch() {
|
function setupFirstTimeLaunch(resolve, reject, shouldUpdateUserConfig) {
|
||||||
log.send(logLevels.INFO, 'setting first time launch config');
|
log.send(logLevels.INFO, 'setting first time launch config');
|
||||||
return getConfigField('launchOnStartup')
|
getConfigField('launchOnStartup')
|
||||||
.then(setStartup)
|
.then(setStartup)
|
||||||
.then(updateUserConfigOnLaunch);
|
.then(() => {
|
||||||
|
if (shouldUpdateUserConfig) {
|
||||||
|
log.send(logLevels.INFO, `Resetting user config data? ${shouldUpdateUserConfig}`);
|
||||||
|
return updateUserConfigOnLaunch(resolve, reject);
|
||||||
|
}
|
||||||
|
return resolve();
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user