Skip to content

Commit

Permalink
SDA-4472 - Migrate settings from Symphony.config and installVariant t…
Browse files Browse the repository at this point in the history
…o /Library/Preferences
  • Loading branch information
KiranNiranjan committed Feb 13, 2024
1 parent 8c0fa7b commit d67d8d5
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 27 deletions.
100 changes: 76 additions & 24 deletions installer/mac/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,63 @@
## Create file path variables ##
settingsFilePath='/tmp/sym_settings.txt'
permissionsFilePath='/tmp/sym_permissions.txt'
installPath="$2"
configPath="/Symphony.app/Contents/config"
configFilePath="${installPath}${configPath}/Symphony.config"
installVariantPath="${installPath}${configPath}/InstallVariant.info"
newPath=${configFilePath}
plistFileName="com.symphony.electron-desktop.plist"
userName=$(stat -f%Su /dev/console)
plistFilePath="/Users/$userName/Library/Preferences/$plistFileName"

echo $plistFilePath
echo $userName

# Create a plist file it not exist
if [ ! -f $plistFilePath ]
then
# Add a default entry
echo "Plist file does not exists creating new file"
sudo -u $userName defaults write $plistFilePath ApplicationName Symphony
fi

#Set default value
sudo -u $userName defaults write $plistFilePath url -string "https://my.symphony.com"
sudo -u $userName defaults write $plistFilePath autoUpdateUrl -string ""
sudo -u $userName defaults write $plistFilePath autoUpdateChannel -string "latest"
sudo -u $userName defaults write $plistFilePath isAutoUpdateEnabled -bool true
sudo -u $userName defaults write $plistFilePath isPodUrlEditable -bool true
sudo -u $userName defaults write $plistFilePath forceAutoUpdate -bool false
sudo -u $userName defaults write $plistFilePath autoUpdateCheckInterval -string "30"
sudo -u $userName defaults write $plistFilePath enableBrowserLogin -bool false
sudo -u $userName defaults write $plistFilePath browserLoginAutoConnect -bool false
sudo -u $userName defaults write $plistFilePath overrideUserAgent -bool false
sudo -u $userName defaults write $plistFilePath minimizeOnClose -string "ENABLED"
sudo -u $userName defaults write $plistFilePath launchOnStartup -string "ENABLED"
sudo -u $userName defaults write $plistFilePath alwaysOnTop -string "DISABLED"
sudo -u $userName defaults write $plistFilePath bringToFront -string "DISABLED"
sudo -u $userName defaults write $plistFilePath whitelistUrl -string "*"
sudo -u $userName defaults write $plistFilePath isCustomTitleBar -string "ENABLED"
sudo -u $userName defaults write $plistFilePath memoryRefresh -string "ENABLED"
sudo -u $userName defaults write $plistFilePath memoryThreshold -string "800"
sudo -u $userName defaults write $plistFilePath devToolsEnabled -bool true
sudo -u $userName defaults write $plistFilePath contextIsolation -bool true
sudo -u $userName defaults write $plistFilePath contextOriginUrl -string ""
sudo -u $userName defaults write $plistFilePath disableGpu -bool false
sudo -u $userName defaults write $plistFilePath enableRendererLogs -bool false
sudo -u $userName defaults write $plistFilePath ctWhitelist -array
sudo -u $userName defaults write $plistFilePath podWhitelist -array
sudo -u $userName defaults write $plistFilePath position -string "upper-right"
sudo -u $userName defaults write $plistFilePath display -string ""
sudo -u $userName defaults write $plistFilePath authServerWhitelist -string ""
sudo -u $userName defaults write $plistFilePath authNegotiateDelegateWhitelist -string ""
sudo -u $userName defaults write $plistFilePath disableThrottling -string "DISABLED"
sudo -u $userName defaults write $plistFilePath media -bool true
sudo -u $userName defaults write $plistFilePath geolocation -bool true
sudo -u $userName defaults write $plistFilePath notifications -bool true
sudo -u $userName defaults write $plistFilePath midiSysex -bool true
sudo -u $userName defaults write $plistFilePath pointerLock -bool true
sudo -u $userName defaults write $plistFilePath fullscreen -bool true
sudo -u $userName defaults write $plistFilePath openExternal -bool true
sudo -u $userName defaults write $plistFilePath autoLaunchPath -string ""
sudo -u $userName defaults write $plistFilePath userDataPath -string ""
sudo -u $userName defaults write $plistFilePath chromeFlags -string ""
sudo -u $userName defaults write $plistFilePath betaAutoUpdateChannelEnabled -bool true

## Get Symphony Settings from the temp file ##
pod_url=$(sed -n '1p' ${settingsFilePath});
Expand Down Expand Up @@ -35,25 +87,25 @@ pod_url_escaped=$(sed 's#[&/\]#\\&#g' <<<"$pod_url")
context_origin_url_escaped=$(sed 's#[&/\]#\\&#g' <<<"$context_origin_url")

## Replace the default settings with the user selected settings ##
sed -i "" -E "s#\"url\" ?: ?\".*\"#\"url\"\: \"$pod_url_escaped\"#g" "${newPath}"
sed -i "" -E "s#\"contextOriginUrl\" ?: ?\".*\"#\"contextOriginUrl\"\: \"$context_origin_url_escaped\"#g" "${newPath}"
sed -i "" -E "s#\"minimizeOnClose\" ?: ?\"([Ee][Nn][Aa][Bb][Ll][Ee][Dd]|[Dd][Ii][Ss][Aa][Bb][Ll][Ee][Dd])\"#\"minimizeOnClose\":\ \"$minimize_on_close\"#g" "${newPath}"
sed -i "" -E "s#\"alwaysOnTop\" ?: ?\"([Ee][Nn][Aa][Bb][Ll][Ee][Dd]|[Dd][Ii][Ss][Aa][Bb][Ll][Ee][Dd])\"#\"alwaysOnTop\":\ \"$always_on_top\"#g" "${newPath}"
sed -i "" -E "s#\"launchOnStartup\" ?: ?\"([Ee][Nn][Aa][Bb][Ll][Ee][Dd]|[Dd][Ii][Ss][Aa][Bb][Ll][Ee][Dd])\"#\"launchOnStartup\":\ \"$launch_on_startup\"#g" "${newPath}"
sed -i "" -E "s#\"bringToFront\" ?: ?\"([Ee][Nn][Aa][Bb][Ll][Ee][Dd]|[Dd][Ii][Ss][Aa][Bb][Ll][Ee][Dd])\"#\"bringToFront\":\ \"$bring_to_front\"#g" "${newPath}"
sed -i "" -E "s#\"devToolsEnabled\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"devToolsEnabled\":\ $dev_tools_enabled#g" "${newPath}"
sed -i "" -E "s#\"enableBrowserLogin\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"enableBrowserLogin\":\ $enable_browser_login#g" "${newPath}"
sed -i "" -E "s#\"browserLoginAutoConnect\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"browserLoginAutoConnect\":\ $browser_login_autoconnect#g" "${newPath}"
plutil -replace url -string "${pod_url_escaped}" $plistFilePath
plutil -replace contextOriginUrl -string "${context_origin_url_escaped}" $plistFilePath
plutil -replace minimizeOnClose -string "${minimize_on_close}" $plistFilePath
plutil -replace alwaysOnTop -string "${always_on_top}" $plistFilePath
plutil -replace launchOnStartup -string "${launch_on_startup}" $plistFilePath
plutil -replace bringToFront -string "${bring_to_front}" $plistFilePath
plutil -replace devToolsEnabled -bool "${dev_tools_enabled}" $plistFilePath
plutil -replace enableBrowserLogin -bool "${enable_browser_login}" $plistFilePath
plutil -replace browserLoginAutoConnect -bool "${browser_login_autoconnect}" $plistFilePath

## Add settings force auto update
force_auto_update=$(sed -n '10p' ${settingsFilePath});
if [ "$force_auto_update" = "" ]; then force_auto_update=false; fi
sed -i "" -E "s#\"forceAutoUpdate\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"forceAutoUpdate\":\ $force_auto_update#g" "${newPath}"
plutil -replace forceAutoUpdate -bool "${force_auto_update}" $plistFilePath

## Add settings is pod url editable
is_pod_url_editable=$(sed -n '11p' ${settingsFilePath});
if [ "$is_pod_url_editable" = "" ]; then is_pod_url_editable=true; fi
sed -i "" -E "s#\"isPodUrlEditable\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"isPodUrlEditable\":\ $is_pod_url_editable#g" "${newPath}"
plutil -replace isPodUrlEditable -bool "${is_pod_url_editable}" $plistFilePath

## Get Symphony Permissions from the temp file ##
media=$(sed -n '1p' ${permissionsFilePath});
Expand All @@ -74,16 +126,16 @@ if [ "$full_screen" = "" ]; then full_screen=true; fi
if [ "$open_external_app" = "" ]; then open_external_app=true; fi

## Replace the default permissions with the user selected permissions ##
sed -i "" -E "s#\"media\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"media\":\ $media#g" "${newPath}"
sed -i "" -E "s#\"geolocation\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"geolocation\":\ $geo_location#g" "${newPath}"
sed -i "" -E "s#\"notifications\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"notifications\":\ $notifications#g" "${newPath}"
sed -i "" -E "s#\"midiSysex\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"midiSysex\":\ $midi_sysex#g" "${newPath}"
sed -i "" -E "s#\"pointerLock\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"pointerLock\":\ $pointer_lock#g" "${newPath}"
sed -i "" -E "s#\"fullscreen\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"fullscreen\":\ $full_screen#g" "${newPath}"
sed -i "" -E "s#\"openExternal\" ?: ?([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])#\"openExternal\":\ $open_external_app#g" "${newPath}"
plutil -replace media -bool "${media}" $plistFilePath
plutil -replace geolocation -bool "${geo_location}" $plistFilePath
plutil -replace notifications -bool "${notifications}" $plistFilePath
plutil -replace midiSysex -bool "${midi_sysex}" $plistFilePath
plutil -replace pointerLock -bool "${pointer_lock}" $plistFilePath
plutil -replace fullscreen -bool "${full_screen}" $plistFilePath
plutil -replace openExternal -bool "${open_external_app}" $plistFilePath

## Remove the temp settings & permissions file created ##
rm -f ${settingsFilePath}
rm -f ${permissionsFilePath}

uuidgen > "${installVariantPath}"
plutil -replace installVariant -string "${uuidgen}" $plistFilePath
4 changes: 4 additions & 0 deletions spec/__mocks__/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ export const screen = {
}),
};

export const systemPreferences = {
getUserDefault: jest.fn(),
};

export const remote = {
app,
getCurrentWindow,
Expand Down
4 changes: 4 additions & 0 deletions spec/childWindowHandle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ jest.mock('../src/app/auto-update-handler', () => {
return {};
});

jest.mock('../src/app/config-handler', () => {
return {};
});

describe('child window handle', () => {
it('should set open window handler', () => {
const spy = jest.spyOn(webContents, 'setWindowOpenHandler');
Expand Down
41 changes: 41 additions & 0 deletions spec/dialogHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,47 @@ jest.mock('../src/app/window-handler', () => {
};
});

jest.mock('../src/app/plist-handler', () => {
return {};
});
jest.mock('../src/app/config-handler', () => {
return {
CloudConfigDataTypes: {
NOT_SET: 'NOT_SET',
ENABLED: 'ENABLED',
DISABLED: 'DISABLED',
},
config: {
getConfigFields: jest.fn(() => {
return {
minimizeOnClose: 'ENABLED',
launchOnStartup: 'ENABLED',
alwaysOnTop: 'ENABLED',
isAlwaysOnTop: 'ENABLED',
bringToFront: 'ENABLED',
devToolsEnabled: true,
};
}),
getGlobalConfigFields: jest.fn(() => {
return {
devToolsEnabled: true,
};
}),
getFilteredCloudConfigFields: jest.fn(() => {
return {
devToolsEnabled: true,
};
}),
getCloudConfigFields: jest.fn(() => {
return {
devToolsEnabled: true,
};
}),
updateUserConfig: jest.fn(),
},
};
});

jest.mock('../src/renderer/notification', () => {
return {
setupNotificationPosition: jest.fn(),
Expand Down
54 changes: 54 additions & 0 deletions spec/plistHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { getAllUserDefaults } from '../src/app/plist-handler';

describe('Plist Handler', () => {
it('should return config object', () => {
expect(getAllUserDefaults()).toStrictEqual({
alwaysOnTop: undefined,
autoLaunchPath: undefined,
autoUpdateChannel: undefined,
autoUpdateCheckInterval: undefined,
autoUpdateUrl: undefined,
betaAutoUpdateChannelEnabled: undefined,
bringToFront: undefined,
browserLoginAutoConnect: undefined,
chromeFlags: {
authNegotiateDelegateWhitelist: undefined,
authServerWhitelist: undefined,
disableThrottling: undefined,
},
contextIsolation: undefined,
contextOriginUrl: undefined,
ctWhitelist: undefined,
devToolsEnabled: undefined,
disableGpu: undefined,
enableBrowserLogin: undefined,
enableRendererLogs: undefined,
forceAutoUpdate: undefined,
isAutoUpdateEnabled: undefined,
isCustomTitleBar: undefined,
isPodUrlEditable: undefined,
launchOnStartup: undefined,
memoryRefresh: undefined,
memoryThreshold: undefined,
minimizeOnClose: undefined,
notificationSettings: {
display: undefined,
position: undefined,
},
overrideUserAgent: undefined,
permissions: {
fullscreen: undefined,
geolocation: undefined,
media: undefined,
midiSysex: undefined,
notifications: undefined,
openExternal: undefined,
pointerLock: undefined,
},
podWhitelist: undefined,
url: undefined,
userDataPath: undefined,
whitelistUrl: undefined,
});
});
});
26 changes: 23 additions & 3 deletions src/app/config-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, dialog, powerSaveBlocker } from 'electron';
import { app, dialog, powerSaveBlocker, systemPreferences } from 'electron';
import * as fs from 'fs';
import * as path from 'path';

Expand All @@ -16,6 +16,7 @@ import {
SDAUserSessionActionTypes,
} from './bi/interface';
import { terminateC9Shell } from './c9-shell-handler';
import { getAllUserDefaults } from './plist-handler';
import { appStats } from './stats';

const writeFile = util.promisify(fs.writeFile);
Expand Down Expand Up @@ -786,12 +787,20 @@ class Config {
* Reads a stores the global config file
*/
private readGlobalConfig() {
if (isMac) {
this.globalConfig = getAllUserDefaults();
logger.info(
`config-handler: Global configuration from plist: `,
this.globalConfig,
);
return;
}
if (!fs.existsSync(this.globalConfigPath)) {
throw new Error(
`Global config file missing! App will not run as expected!`,
);
}
if (fs.existsSync(this.tempGlobalConfigFilePath)) {
/*if (fs.existsSync(this.tempGlobalConfigFilePath)) {
this.globalConfig = this.parseConfigData(
fs.readFileSync(this.tempGlobalConfigFilePath, 'utf8'),
);
Expand All @@ -804,7 +813,7 @@ class Config {
this.copyGlobalConfig();
}
return;
}
}*/
const parsedConfigData = this.parseConfigData(
fs.readFileSync(this.globalConfigPath, 'utf8'),
);
Expand All @@ -818,6 +827,17 @@ class Config {
* Reads the install variant from a file
*/
private readInstallVariant() {
if (isMac) {
this.installVariant = systemPreferences.getUserDefault(
'installVariant',
'string',
);
logger.info(
`config-handler: Install variant from plist: `,
this.installVariant,
);
return;
}
this.installVariant = fs.readFileSync(this.installVariantPath, 'utf8');
logger.info(`config-handler: Install variant: `, this.installVariant);
}
Expand Down
Loading

0 comments on commit d67d8d5

Please sign in to comment.