Skip to content

Commit

Permalink
SDA-4507 (Add validation for copying old global config file) (#2116)
Browse files Browse the repository at this point in the history
* SDA-4507 - Add validation for copying old global config file

* SDA-4507 - Read from default after copying global config

* SDA-4507 - Force welcome screen in user config url is not configured correctly
  • Loading branch information
KiranNiranjan committed Mar 25, 2024
1 parent fae7deb commit 66346ce
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
1 change: 1 addition & 0 deletions spec/plistHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('Plist Handler', () => {
userDataPath: undefined,
whitelistUrl: undefined,
chromeFlags: undefined,
latestAutoUpdateChannelEnabled: undefined,
});
});
});
18 changes: 15 additions & 3 deletions src/app/config-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,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) {
Expand Down Expand Up @@ -813,7 +813,19 @@ 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,
);
// After everything is set from previous SDA version
this.globalConfig = getAllUserDefaults();
return;
}
if (!this.installVariant || this.installVariant === '') {
Expand Down
54 changes: 37 additions & 17 deletions src/app/plist-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const GENERAL_SETTINGS = {
userDataPath: 'string',
chromeFlags: 'string',
betaAutoUpdateChannelEnabled: 'boolean',
latestAutoUpdateChannelEnabled: 'boolean',
};

const NOTIFICATION_SETTINGS = {
Expand Down Expand Up @@ -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());
};
Expand Down
19 changes: 14 additions & 5 deletions src/app/window-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ export class WindowHandler {
(this.globalConfig.url.includes(this.defaultUrl) &&
config.isFirstTimeLaunch()) ||
!!this.config.enableBrowserLogin;
// Force welcome screen if pod url is not configured correctly
if (
!!this.userConfig.url &&
this.userConfig.url.includes(this.defaultUrl)
) {
this.shouldShowWelcomeScreen = true;
}

this.windowOpts = {
...this.getWindowOpts(
Expand Down Expand Up @@ -596,11 +603,13 @@ export class WindowHandler {
if (this.mainWebContents && !this.mainWebContents.isDestroyed()) {
// Load welcome screen
if (this.shouldShowWelcomeScreen && !this.didShowWelcomeScreen) {
const podUrl = this.userConfig.url
? this.userConfig.url
: !this.globalConfig.url.includes(this.defaultUrl)
? this.globalConfig.url
: undefined;
const podUrl =
this.userConfig.url &&
!this.userConfig.url.includes(this.defaultUrl)
? this.userConfig.url
: !this.globalConfig.url.includes(this.defaultUrl)
? this.globalConfig.url
: undefined;
this.mainWebContents.send('page-load-welcome', {
locale: i18n.getLocale(),
resources: i18n.loadedResources,
Expand Down

0 comments on commit 66346ce

Please sign in to comment.