From 87ad70479e005aeaeed06f0366b9b5f30afc47d7 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 26 Dec 2024 22:45:45 +0530 Subject: [PATCH] SDA-4757 - Fix config race condition --- src/app/config-handler.ts | 16 +--------------- src/app/init.ts | 6 ++++++ src/app/plist-handler.ts | 7 ++++--- src/common/config-interface.ts | 11 +++++++++++ 4 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 src/common/config-interface.ts diff --git a/src/app/config-handler.ts b/src/app/config-handler.ts index 4d31c7e42..b0aeef5d7 100644 --- a/src/app/config-handler.ts +++ b/src/app/config-handler.ts @@ -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'; @@ -19,7 +20,6 @@ import { terminateC9Shell } from './c9-shell-handler'; import { getAllUserDefaults, initializePlistFile, - readPlistFile, setPlistFromPreviousSettings, } from './plist-handler'; import { appStats } from './stats'; @@ -32,16 +32,6 @@ export enum CloudConfigDataTypes { DISABLED = 'DISABLED', } -export const ConfigFieldsDefaultValues: Partial = { - isPodUrlEditable: true, - forceAutoUpdate: false, - enableBrowserLogin: false, - browserLoginAutoConnect: false, - latestAutoUpdateChannelEnabled: true, - betaAutoUpdateChannelEnabled: true, - browserLoginRetryTimeout: '5', -}; - export const ConfigFieldsToRestart = new Set([ 'permissions', 'disableThrottling', @@ -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; @@ -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: `, diff --git a/src/app/init.ts b/src/app/init.ts index 21f500619..43bc5f4b8 100644 --- a/src/app/init.ts +++ b/src/app/init.ts @@ -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 @@ -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(); diff --git a/src/app/plist-handler.ts b/src/app/plist-handler.ts index a7047190c..9ac89b950 100644 --- a/src/app/plist-handler.ts +++ b/src/app/plist-handler.ts @@ -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 = {}; @@ -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} 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 { diff --git a/src/common/config-interface.ts b/src/common/config-interface.ts new file mode 100644 index 000000000..f78db3d8a --- /dev/null +++ b/src/common/config-interface.ts @@ -0,0 +1,11 @@ +import { IConfig } from '../app/config-handler'; + +export const ConfigFieldsDefaultValues: Partial = { + isPodUrlEditable: true, + forceAutoUpdate: false, + enableBrowserLogin: false, + browserLoginAutoConnect: false, + latestAutoUpdateChannelEnabled: true, + betaAutoUpdateChannelEnabled: true, + browserLoginRetryTimeout: '5', +};