SDA-1880 & SDA-1882 - Fix background throttling issue (#925)

This commit is contained in:
Kiran Niranjan
2020-03-18 19:50:27 +05:30
committed by GitHub
parent 79b2c42fdc
commit 996bd858a7
6 changed files with 113 additions and 17 deletions

View File

@@ -20,7 +20,7 @@
"customFlags": { "customFlags": {
"authServerWhitelist": "", "authServerWhitelist": "",
"authNegotiateDelegateWhitelist": "", "authNegotiateDelegateWhitelist": "",
"disableThrottling": false "disableThrottling": "DISABLED"
}, },
"permissions": { "permissions": {
"media": true, "media": true,

View File

@@ -5,17 +5,27 @@ import { app } from './__mocks__/electron';
jest.mock('../src/app/config-handler', () => { jest.mock('../src/app/config-handler', () => {
return { return {
CloudConfigDataTypes: {
NOT_SET: 'NOT_SET',
ENABLED: 'ENABLED',
DISABLED: 'DISABLED',
},
config: { config: {
getConfigFields: jest.fn(() => { getConfigFields: jest.fn(() => {
return { return {
customFlags: { customFlags: {
authServerWhitelist: 'url', authServerWhitelist: 'url',
authNegotiateDelegateWhitelist: 'whitelist', authNegotiateDelegateWhitelist: 'whitelist',
disableThrottling: false, disableThrottling: 'DISABLED',
}, },
disableGpu: true, disableGpu: true,
}; };
}), }),
getCloudConfigFields: jest.fn(() => {
return {
disableThrottling: 'DISABLED',
};
}),
}, },
}; };
}); });
@@ -75,6 +85,79 @@ describe('chrome flags', () => {
expect(spy).not.nthCalledWith(4); expect(spy).not.nthCalledWith(4);
}); });
it('should set `disable-renderer-backgrounding` chrome flag correctly when cloud config is ENABLED', () => {
config.getConfigFields = jest.fn(() => {
return {
customFlags: {
authServerWhitelist: 'url',
authNegotiateDelegateWhitelist: 'whitelist',
disableGpu: false,
disableThrottling: 'ENABLED',
},
};
});
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
setChromeFlags();
expect(spy).nthCalledWith(4, 'disable-renderer-backgrounding', 'true');
expect(spy).not.nthCalledWith(5);
});
it('should set `disable-renderer-backgrounding` chrome flag correctly when cloud config PMP setting is ENABLED', () => {
config.getCloudConfigFields = jest.fn(() => {
return {
disableThrottling: 'ENABLED',
};
});
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
setChromeFlags();
expect(spy).nthCalledWith(7, 'disable-renderer-backgrounding', 'true');
expect(spy).not.nthCalledWith(8);
});
it('should set `disable-renderer-backgrounding` chrome flag when any one is ENABLED ', () => {
config.getConfigFields = jest.fn(() => {
return {
customFlags: {
authServerWhitelist: 'url',
authNegotiateDelegateWhitelist: 'whitelist',
disableGpu: false,
disableThrottling: 'DISABLED',
},
};
});
config.getCloudConfigFields = jest.fn(() => {
return {
disableThrottling: 'ENABLED',
};
});
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
setChromeFlags();
expect(spy).nthCalledWith(4, 'disable-renderer-backgrounding', 'true');
expect(spy).not.nthCalledWith(5);
});
it('should set `disable-renderer-backgrounding` chrome flag when PMP is ENABLED', () => {
config.getConfigFields = jest.fn(() => {
return {
customFlags: {
authServerWhitelist: 'url',
authNegotiateDelegateWhitelist: 'whitelist',
disableGpu: false,
disableThrottling: 'ENABLED',
},
};
});
config.getCloudConfigFields = jest.fn(() => {
return {
disableThrottling: 'DISABLED',
};
});
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
setChromeFlags();
expect(spy).nthCalledWith(4, 'disable-renderer-backgrounding', 'true');
expect(spy).not.nthCalledWith(5);
});
describe('`isDevEnv`', () => { describe('`isDevEnv`', () => {
beforeEach(() => { beforeEach(() => {
(isDevEnv as any) = true; (isDevEnv as any) = true;

View File

@@ -1,7 +1,7 @@
import { app, session } from 'electron'; import { app, session } from 'electron';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { config, IConfig } from './config-handler'; import { CloudConfigDataTypes, config, IConfig } from './config-handler';
// Set default flags // Set default flags
logger.info(`chrome-flags: Setting mandatory chrome flags`, { flag: { 'ssl-version-fallback-min': 'tls1.2' } }); logger.info(`chrome-flags: Setting mandatory chrome flags`, { flag: { 'ssl-version-fallback-min': 'tls1.2' } });
@@ -17,6 +17,7 @@ export const setChromeFlags = () => {
logger.info(`chrome-flags: Checking if we need to set chrome flags!`); logger.info(`chrome-flags: Checking if we need to set chrome flags!`);
const flagsConfig = config.getConfigFields(['customFlags', 'disableGpu']) as IConfig; const flagsConfig = config.getConfigFields(['customFlags', 'disableGpu']) as IConfig;
const { disableThrottling } = config.getCloudConfigFields([ 'disableThrottling' ]) as any;
const configFlags: object = { const configFlags: object = {
'auth-negotiate-delegate-whitelist': flagsConfig.customFlags.authServerWhitelist, 'auth-negotiate-delegate-whitelist': flagsConfig.customFlags.authServerWhitelist,
'auth-server-whitelist': flagsConfig.customFlags.authNegotiateDelegateWhitelist, 'auth-server-whitelist': flagsConfig.customFlags.authNegotiateDelegateWhitelist,
@@ -24,8 +25,10 @@ export const setChromeFlags = () => {
'disable-d3d11': flagsConfig.disableGpu || null, 'disable-d3d11': flagsConfig.disableGpu || null,
'disable-gpu': flagsConfig.disableGpu || null, 'disable-gpu': flagsConfig.disableGpu || null,
'disable-gpu-compositing': flagsConfig.disableGpu || null, 'disable-gpu-compositing': flagsConfig.disableGpu || null,
'disable-renderer-backgrounding': flagsConfig.customFlags.disableThrottling || null,
}; };
if (flagsConfig.customFlags.disableThrottling === CloudConfigDataTypes.ENABLED || disableThrottling === CloudConfigDataTypes.ENABLED) {
configFlags['disable-renderer-backgrounding'] = 'true';
}
for (const key in configFlags) { for (const key in configFlags) {
if (!Object.prototype.hasOwnProperty.call(configFlags, key)) { if (!Object.prototype.hasOwnProperty.call(configFlags, key)) {

View File

@@ -94,7 +94,7 @@ export interface IPermission {
export interface ICustomFlag { export interface ICustomFlag {
authServerWhitelist: string; authServerWhitelist: string;
authNegotiateDelegateWhitelist: string; authNegotiateDelegateWhitelist: string;
disableThrottling: boolean; disableThrottling: CloudConfigDataTypes;
} }
export interface INotificationSetting { export interface INotificationSetting {
@@ -150,8 +150,9 @@ class Config {
* @param fields * @param fields
*/ */
public getConfigFields(fields: string[]): IConfig { public getConfigFields(fields: string[]): IConfig {
logger.info(`config-handler: Trying to get cloud config values for the fields`, fields); const configFields = { ...this.getGlobalConfigFields(fields), ...this.getUserConfigFields(fields), ...this.getFilteredCloudConfigFields(fields) } as IConfig;
return { ...this.getGlobalConfigFields(fields), ...this.getUserConfigFields(fields), ...this.getFilteredCloudConfigFields(fields) } as IConfig; logger.info(`config-handler: getting combined config values for the fields ${fields}`, configFields);
return configFields;
} }
/** /**
@@ -160,8 +161,9 @@ class Config {
* @param fields {Array} * @param fields {Array}
*/ */
public getUserConfigFields(fields: string[]): IConfig { public getUserConfigFields(fields: string[]): IConfig {
logger.info(`config-handler: Trying to get user config values for the fields`, fields); const userConfigData = pick(this.userConfig, fields) as IConfig;
return pick(this.userConfig, fields) as IConfig; logger.info(`config-handler: getting user config values for the fields ${fields}`, userConfigData);
return userConfigData;
} }
/** /**
@@ -170,8 +172,9 @@ class Config {
* @param fields {Array} * @param fields {Array}
*/ */
public getGlobalConfigFields(fields: string[]): IGlobalConfig { public getGlobalConfigFields(fields: string[]): IGlobalConfig {
logger.info(`config-handler: Trying to get global config values for the fields`, fields); const globalConfigData = pick(this.globalConfig, fields) as IGlobalConfig;
return pick(this.globalConfig, fields) as IGlobalConfig; logger.info(`config-handler: getting global config values for the fields ${fields}`, globalConfigData);
return globalConfigData;
} }
/** /**
@@ -180,7 +183,9 @@ class Config {
* @param fields {Array} * @param fields {Array}
*/ */
public getFilteredCloudConfigFields(fields: string[]): IConfig | {} { public getFilteredCloudConfigFields(fields: string[]): IConfig | {} {
return pick(this.filteredCloudConfig, fields) as IConfig; const filteredCloudConfigData = pick(this.filteredCloudConfig, fields) as IConfig;
logger.info(`config-handler: getting filtered cloud config values for the ${fields}`, filteredCloudConfigData);
return filteredCloudConfigData;
} }
/** /**
@@ -190,7 +195,10 @@ class Config {
public getCloudConfigFields(fields: string[]): IConfig { public getCloudConfigFields(fields: string[]): IConfig {
const { acpFeatureLevelEntitlements, podLevelEntitlements, pmpEntitlements } = this.cloudConfig as ICloudConfig; const { acpFeatureLevelEntitlements, podLevelEntitlements, pmpEntitlements } = this.cloudConfig as ICloudConfig;
const cloudConfig = { ...acpFeatureLevelEntitlements, ...podLevelEntitlements, ...pmpEntitlements }; const cloudConfig = { ...acpFeatureLevelEntitlements, ...podLevelEntitlements, ...pmpEntitlements };
return pick(cloudConfig, fields) as IConfig; logger.info(`config-handler: prioritized cloud config data`, cloudConfig);
const cloudConfigData = pick(cloudConfig, fields) as IConfig;
logger.info(`config-handler: getting prioritized cloud config values for the fields ${fields}`, cloudConfigData);
return cloudConfigData;
} }
/** /**
@@ -223,7 +231,7 @@ class Config {
logger.info(`config-handler: prioritized and filtered cloud config: `, this.filteredCloudConfig); logger.info(`config-handler: prioritized and filtered cloud config: `, this.filteredCloudConfig);
try { try {
await writeFile(this.cloudConfigPath, JSON.stringify(this.cloudConfig), { encoding: 'utf8' }); await writeFile(this.cloudConfigPath, JSON.stringify(this.cloudConfig), { encoding: 'utf8' });
logger.info(`config-handler: writting cloud config values to file`); logger.info(`config-handler: writing cloud config values to file`);
} catch (error) { } catch (error) {
logger.error(`config-handler: failed to update cloud config file with ${data}`, error); logger.error(`config-handler: failed to update cloud config file with ${data}`, error);
} }

View File

@@ -1,11 +1,12 @@
import { powerSaveBlocker } from 'electron'; import { powerSaveBlocker } from 'electron';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { config, IConfig } from './config-handler'; import { CloudConfigDataTypes, config, IConfig } from './config-handler';
export const handlePerformanceSettings = () => { export const handlePerformanceSettings = () => {
const { customFlags } = config.getCloudConfigFields([ 'customFlags' ]) as IConfig; const { customFlags } = config.getCloudConfigFields([ 'customFlags' ]) as IConfig;
const { disableThrottling } = config.getCloudConfigFields([ 'disableThrottling' ]) as any;
if (customFlags && customFlags.disableThrottling) { if ((customFlags && customFlags.disableThrottling === CloudConfigDataTypes.ENABLED) || disableThrottling === CloudConfigDataTypes.ENABLED) {
logger.info(`perf-handler: Disabling power throttling!`); logger.info(`perf-handler: Disabling power throttling!`);
powerSaveBlocker.start('prevent-display-sleep'); powerSaveBlocker.start('prevent-display-sleep');
return; return;

View File

@@ -96,12 +96,13 @@ export class WindowHandler {
this.config = config.getConfigFields([ 'isCustomTitleBar', 'mainWinPos', 'minimizeOnClose', 'notificationSettings', 'alwaysOnTop', 'locale', 'customFlags' ]); this.config = config.getConfigFields([ 'isCustomTitleBar', 'mainWinPos', 'minimizeOnClose', 'notificationSettings', 'alwaysOnTop', 'locale', 'customFlags' ]);
logger.info(`window-handler: main windows initialized with following config data`, this.config); logger.info(`window-handler: main windows initialized with following config data`, this.config);
this.globalConfig = config.getGlobalConfigFields([ 'url', 'contextIsolation' ]); this.globalConfig = config.getGlobalConfigFields([ 'url', 'contextIsolation' ]);
const { disableThrottling } = config.getCloudConfigFields([ 'disableThrottling' ]) as any;
const { url, contextIsolation }: IGlobalConfig = this.globalConfig; const { url, contextIsolation }: IGlobalConfig = this.globalConfig;
const { customFlags } = this.config; const { customFlags } = this.config;
this.windows = {}; this.windows = {};
this.contextIsolation = contextIsolation || false; this.contextIsolation = contextIsolation || false;
this.backgroundThrottling = !customFlags.disableThrottling; this.backgroundThrottling = (customFlags.disableThrottling !== CloudConfigDataTypes.ENABLED || disableThrottling !== CloudConfigDataTypes.ENABLED);
this.isCustomTitleBar = isWindowsOS && this.config.isCustomTitleBar === CloudConfigDataTypes.ENABLED; this.isCustomTitleBar = isWindowsOS && this.config.isCustomTitleBar === CloudConfigDataTypes.ENABLED;
this.windowOpts = { this.windowOpts = {
...this.getWindowOpts({ ...this.getWindowOpts({