Skip to content

Commit

Permalink
SDA-4757 - Fix config race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan committed Dec 26, 2024
1 parent 975041d commit 87ad704
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
16 changes: 1 addition & 15 deletions src/app/config-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';

import * as util from 'util';
import { buildNumber } from '../../package.json';
import { ConfigFieldsDefaultValues } from '../common/config-interface';
import { isDevEnv, isElectronQA, isLinux, isMac } from '../common/env';
import { logger } from '../common/logger';
import { arrayEquals, filterOutSelectedValues, pick } from '../common/utils';
Expand All @@ -19,7 +20,6 @@ import { terminateC9Shell } from './c9-shell-handler';
import {
getAllUserDefaults,
initializePlistFile,
readPlistFile,
setPlistFromPreviousSettings,
} from './plist-handler';
import { appStats } from './stats';
Expand All @@ -32,16 +32,6 @@ export enum CloudConfigDataTypes {
DISABLED = 'DISABLED',
}

export const ConfigFieldsDefaultValues: Partial<IConfig> = {
isPodUrlEditable: true,
forceAutoUpdate: false,
enableBrowserLogin: false,
browserLoginAutoConnect: false,
latestAutoUpdateChannelEnabled: true,
betaAutoUpdateChannelEnabled: true,
browserLoginRetryTimeout: '5',
};

export const ConfigFieldsToRestart = new Set([
'permissions',
'disableThrottling',
Expand Down Expand Up @@ -865,8 +855,6 @@ class Config {
this.globalConfig as IConfig,
appGlobalConfigData,
);
// Validate user config before starting the application
await readPlistFile();
// After everything is set from previous SDA version
this.globalConfig = getAllUserDefaults();
return;
Expand All @@ -882,8 +870,6 @@ class Config {
'installVariant',
'string',
);
// Validate user config before starting the application
await readPlistFile();
this.globalConfig = getAllUserDefaults();
logger.info(
`config-handler: Global configuration from plist: `,
Expand Down
6 changes: 6 additions & 0 deletions src/app/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import { isDevEnv, isMac } from '../common/env';
import { logger } from '../common/logger';
import { getCommandLineArgs } from '../common/utils';
import { readPlistFile } from './plist-handler';
import { appStats } from './stats';

// Handle custom user data path from process.argv
Expand All @@ -16,6 +17,11 @@ const userDataPath =
userDataPathArg &&
userDataPathArg.substring(userDataPathArg.indexOf('=') + 1);

if (isMac) {
// Validate user config before starting the application
readPlistFile();
}

// If we are running in production, sandbox the entire app
// and set the app user model id for windows native notifications
app.enableSandbox();
Expand Down
7 changes: 4 additions & 3 deletions src/app/plist-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { execSync } from 'child_process';
import { app, systemPreferences } from 'electron';
import * as fs from 'fs';

import { ConfigFieldsDefaultValues } from '../common/config-interface';
import { logger } from '../common/logger';
import { getGuid } from '../common/utils';
import { ConfigFieldsDefaultValues, IConfig } from './config-handler';
import { IConfig } from './config-handler';

let plistData = {};

Expand Down Expand Up @@ -182,10 +183,10 @@ export const initializePlistFile = (path: string) => {
* The plist file is located at `~/Library/Preferences/com.symphony.electron-desktop.plist`.
* If the file exists and is successfully parsed, its data is stored in the `plistData` variable.
*
* @returns {Promise<void>} A promise that resolves once the file has been read and processed.
* @returns {void} A promise that resolves once the file has been read and processed.
* @throws {Error} Throws an error if the plist file cannot be read or parsed, which is logged using the logger.
*/
export const readPlistFile = async () => {
export const readPlistFile = (): void => {
const userPath = app.getPath('home');
const plistPath = `${userPath}/Library/Preferences/com.symphony.electron-desktop.plist`;
try {
Expand Down
11 changes: 11 additions & 0 deletions src/common/config-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IConfig } from '../app/config-handler';

export const ConfigFieldsDefaultValues: Partial<IConfig> = {
isPodUrlEditable: true,
forceAutoUpdate: false,
enableBrowserLogin: false,
browserLoginAutoConnect: false,
latestAutoUpdateChannelEnabled: true,
betaAutoUpdateChannelEnabled: true,
browserLoginRetryTimeout: '5',
};

0 comments on commit 87ad704

Please sign in to comment.