mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-25 08:21:21 -06:00
SDA-4507 - Add validation for copying old global config file (#2115)
This commit is contained in:
parent
48a7fa921f
commit
3dde3d0678
@ -50,6 +50,7 @@ describe('Plist Handler', () => {
|
||||
userDataPath: undefined,
|
||||
whitelistUrl: undefined,
|
||||
chromeFlags: undefined,
|
||||
latestAutoUpdateChannelEnabled: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -723,10 +723,10 @@ class Config {
|
||||
/**
|
||||
* Overwrites the global config file with the backed up config file
|
||||
*/
|
||||
public copyGlobalConfig(settings: IConfig) {
|
||||
public copyGlobalConfig(settings: IConfig, appGlobalConfig: IConfig) {
|
||||
try {
|
||||
if (settings) {
|
||||
setPlistFromPreviousSettings(settings);
|
||||
setPlistFromPreviousSettings(settings, appGlobalConfig);
|
||||
fs.unlinkSync(this.tempGlobalConfigFilePath);
|
||||
}
|
||||
} catch (e) {
|
||||
@ -812,7 +812,17 @@ class Config {
|
||||
this.tempGlobalConfigFilePath,
|
||||
this.globalConfig,
|
||||
);
|
||||
this.copyGlobalConfig(this.globalConfig as IConfig);
|
||||
|
||||
let appGlobalConfigData = {} as IConfig;
|
||||
if (fs.existsSync(this.globalConfigPath)) {
|
||||
appGlobalConfigData = this.parseConfigData(
|
||||
fs.readFileSync(this.globalConfigPath, 'utf8'),
|
||||
) as IConfig;
|
||||
}
|
||||
this.copyGlobalConfig(
|
||||
this.globalConfig as IConfig,
|
||||
appGlobalConfigData,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!this.installVariant || this.installVariant === '') {
|
||||
|
@ -34,6 +34,7 @@ const GENERAL_SETTINGS = {
|
||||
userDataPath: 'string',
|
||||
chromeFlags: 'string',
|
||||
betaAutoUpdateChannelEnabled: 'boolean',
|
||||
latestAutoUpdateChannelEnabled: 'boolean',
|
||||
};
|
||||
|
||||
const NOTIFICATION_SETTINGS = {
|
||||
@ -97,30 +98,49 @@ export const getAllUserDefaults = (): IConfig => {
|
||||
return settings;
|
||||
};
|
||||
|
||||
export const setPlistFromPreviousSettings = (settings: IConfig) => {
|
||||
export const setPlistFromPreviousSettings = (
|
||||
settings: any,
|
||||
appGlobalConfig: IConfig,
|
||||
) => {
|
||||
Object.keys(GENERAL_SETTINGS).map((key) => {
|
||||
systemPreferences.setUserDefault(key, GENERAL_SETTINGS[key], settings[key]);
|
||||
let value = settings?.[key];
|
||||
if (value === undefined) {
|
||||
if (appGlobalConfig?.[key] === undefined) {
|
||||
return;
|
||||
}
|
||||
value = appGlobalConfig[key];
|
||||
}
|
||||
systemPreferences.setUserDefault(key, GENERAL_SETTINGS[key], value);
|
||||
});
|
||||
Object.keys(NOTIFICATION_SETTINGS).map((key) => {
|
||||
systemPreferences.setUserDefault(
|
||||
key,
|
||||
NOTIFICATION_SETTINGS[key],
|
||||
settings.notificationSettings[key],
|
||||
);
|
||||
let value = settings?.notificationSettings?.[key];
|
||||
if (value === undefined) {
|
||||
if (appGlobalConfig?.notificationSettings?.[key] === undefined) {
|
||||
return;
|
||||
}
|
||||
value = appGlobalConfig.notificationSettings[key];
|
||||
}
|
||||
systemPreferences.setUserDefault(key, NOTIFICATION_SETTINGS[key], value);
|
||||
});
|
||||
Object.keys(CUSTOM_FLAGS).map((key) => {
|
||||
systemPreferences.setUserDefault(
|
||||
key,
|
||||
CUSTOM_FLAGS[key],
|
||||
settings.customFlags[key],
|
||||
);
|
||||
let value = settings?.customFlags?.[key];
|
||||
if (value === undefined) {
|
||||
if (appGlobalConfig?.customFlags?.[key] === undefined) {
|
||||
return;
|
||||
}
|
||||
value = appGlobalConfig.customFlags[key];
|
||||
}
|
||||
systemPreferences.setUserDefault(key, CUSTOM_FLAGS[key], value);
|
||||
});
|
||||
Object.keys(PERMISSIONS).map((key) => {
|
||||
systemPreferences.setUserDefault(
|
||||
key,
|
||||
PERMISSIONS[key],
|
||||
settings.permissions[key],
|
||||
);
|
||||
let value = settings?.permissions?.[key];
|
||||
if (value === undefined) {
|
||||
if (appGlobalConfig?.permissions?.[key] === undefined) {
|
||||
return;
|
||||
}
|
||||
value = appGlobalConfig.permissions[key];
|
||||
}
|
||||
systemPreferences.setUserDefault(key, PERMISSIONS[key], value);
|
||||
});
|
||||
systemPreferences.setUserDefault('installVariant', 'string', getGuid());
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user