From 6f28edc5bb149b74d89c1d87b21ea9b72d4d705d Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Thu, 26 Oct 2017 16:53:15 +0530 Subject: [PATCH] electron-194: adds support to set chrome flags --- config/Symphony.config | 4 ++++ js/config.js | 32 +++++++++++++++++++++++++++++++- js/main.js | 27 ++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/config/Symphony.config b/config/Symphony.config index 7568af3f..7151d52a 100644 --- a/config/Symphony.config +++ b/config/Symphony.config @@ -11,5 +11,9 @@ "submitURL": "https://localhost:1127/post", "companyName": "Symphony", "uploadToServer": false + }, + "customFlags": { + "authServerWhitelist": "", + "authNegotiateDelegateWhitelist": "" } } \ No newline at end of file diff --git a/js/config.js b/js/config.js index ba92566f..e79aab99 100644 --- a/js/config.js +++ b/js/config.js @@ -322,6 +322,34 @@ function clearCachedConfigs() { globalConfig = null; } +function readConfigFileSync() { + + let configPath; + let globalConfigFileName = path.join('config', configFileName); + if (isDevEnv) { + // for dev env, get config file from asar + configPath = path.join(app.getAppPath(), globalConfigFileName); + } else { + // for non-dev, config file is placed by installer relative to exe. + // this is so the config can be easily be changed post install. + let execPath = path.dirname(app.getPath('exe')); + // for mac exec is stored in subdir, for linux/windows config + // dir is in the same location. + configPath = path.join(execPath, isMac ? '..' : '', globalConfigFileName); + } + + let data = fs.readFileSync(configPath); + + try { + return JSON.parse(data); + } catch (err) { + console.log("parsing config failed", err); + } + + return null; + +} + module.exports = { configFileName, @@ -334,6 +362,8 @@ module.exports = { // items below here are only exported for testing, do NOT use! saveUserConfig, - clearCachedConfigs + clearCachedConfigs, + + readConfigFileSync }; diff --git a/js/main.js b/js/main.js index 80963a16..7a400180 100644 --- a/js/main.js +++ b/js/main.js @@ -10,7 +10,7 @@ const AutoLaunch = require('auto-launch'); const urlParser = require('url'); // Local Dependencies -const {getConfigField, updateUserConfigWin, updateUserConfigMac} = require('./config.js'); +const {getConfigField, updateUserConfigWin, updateUserConfigMac, readConfigFileSync} = require('./config.js'); const { isMac, isDevEnv } = require('./utils/misc.js'); const protocolHandler = require('./protocolHandler'); const getCmdLineArg = require('./utils/getCmdLineArg.js'); @@ -87,6 +87,31 @@ if (isMac) { }); } +function setChromeFlags() { + + log.send(logLevels.INFO, 'checking if we need to set custom chrome flags!'); + + let config = readConfigFileSync(); + + if (config && config !== null && config.customFlags) { + + log.send(logLevels.INFO, 'Chrome flags config found!'); + + if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") { + log.send(logLevels.INFO, 'Setting auth server whitelist flag'); + app.commandLine.appendSwitch('auth-server-whitelist', config.customFlags.authServerWhitelist); + } + + if (config.customFlags.authNegotiateDelegateWhitelist && config.customFlags.authNegotiateDelegateWhitelist !== "") { + log.send(logLevels.INFO, 'Setting auth negotiate delegate whitelist flag'); + app.commandLine.appendSwitch('auth-negotiate-delegate-whitelist', config.customFlags.authNegotiateDelegateWhitelist); + } + + } +} + +setChromeFlags(); + /** * This method will be called when Electron has finished * initialization and is ready to create browser windows.