fix: ELECTRON-1243: fix chrome flags tests (#696)

* ELECTRON-1243: add support to control throttling

* ELECTRON-1243: fix chrome flags tests

* ELECTRON-1243: refactor code and address PR comments
This commit is contained in:
Vishwas Shashidhar 2019-07-02 16:24:17 +05:30 committed by GitHub
parent 63534d04cd
commit 918c5741a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 7 deletions

View File

@ -17,7 +17,8 @@
"customFlags": {
"authServerWhitelist": "",
"authNegotiateDelegateWhitelist": "",
"disableGpu": false
"disableGpu": false,
"disableThrottling": false
},
"permissions": {
"media": true,

View File

@ -2,7 +2,7 @@
"name": "symphony",
"productName": "Symphony",
"version": "3.8.0",
"clientVersion": "1.55",
"clientVersion": "1.55.3",
"buildNumber": "0",
"searchAPIVersion": "1.55.3",
"description": "Symphony desktop app (Foundation ODP)",

View File

@ -89,8 +89,9 @@ describe('chrome flags', () => {
expect(spy).nthCalledWith(4, 'disable-d3d11', true);
expect(spy).nthCalledWith(5, 'disable-gpu', true);
expect(spy).nthCalledWith(6, 'disable-gpu-compositing', true);
expect(spy).nthCalledWith(7, 'remote-debugging-port', '5858');
expect(spy).nthCalledWith(8, 'host-rules', 'MAP * 127.0.0.1');
expect(spy).nthCalledWith(7, 'disable-renderer-backgrounding', 'false');
expect(spy).nthCalledWith(8, 'remote-debugging-port', '5858');
expect(spy).nthCalledWith(9, 'host-rules', 'MAP * 127.0.0.1');
});
it('should return `undefined` when `chromeFlagsFromCmd` is null', () => {

View File

@ -21,6 +21,7 @@ export const setChromeFlags = () => {
'disable-d3d11': customFlags.disableGpu || null,
'disable-gpu': customFlags.disableGpu || null,
'disable-gpu-compositing': customFlags.disableGpu || null,
'disable-renderer-backgrounding': customFlags.disableThrottling || 'false',
};
for (const key in configFlags) {

View File

@ -56,6 +56,7 @@ export interface ICustomFlag {
authServerWhitelist: string;
authNegotiateDelegateWhitelist: string;
disableGpu: boolean;
disableThrottling: boolean;
}
export interface INotificationSetting {

View File

@ -10,11 +10,15 @@ import { setChromeFlags } from './chrome-flags';
import { config } from './config-handler';
import './dialog-handler';
import './main-api-handler';
import { handlePerformanceSettings } from './perf-handler';
import { protocolHandler } from './protocol-handler';
import { ICustomBrowserWindow, windowHandler } from './window-handler';
const allowMultiInstance: string | boolean = getCommandLineArgs(process.argv, '--multiInstance', true) || isDevEnv;
handlePerformanceSettings();
setChromeFlags();
// on windows, we create the protocol handler via the installer
// because electron leaves registry traces upon uninstallation
if (isMac) {
@ -41,7 +45,6 @@ const startApplication = async () => {
await autoLaunchInstance.handleAutoLaunch();
}
setChromeFlags();
};
// Handle multiple/single instances

15
src/app/perf-handler.ts Normal file
View File

@ -0,0 +1,15 @@
import { powerSaveBlocker } from 'electron';
import { logger } from '../common/logger';
import { config, IConfig } from './config-handler';
export const handlePerformanceSettings = () => {
const { customFlags } = config.getGlobalConfigFields([ 'customFlags' ]) as IConfig;
if (customFlags.disableThrottling) {
logger.info(`perf-handler: Disabling power throttling!`);
powerSaveBlocker.start('prevent-display-sleep');
return;
}
logger.info(`perf-handler: Power throttling enabled as config is not set to override power throttling!`);
};

View File

@ -69,6 +69,7 @@ export class WindowHandler {
public spellchecker: SpellChecker | undefined;
private readonly contextIsolation: boolean;
private readonly backgroundThrottling: boolean;
private readonly windowOpts: ICustomBrowserWindowConstructorOpts;
private readonly globalConfig: IConfig;
private readonly config: IConfig;
@ -88,10 +89,11 @@ export class WindowHandler {
constructor(opts?: Electron.BrowserViewConstructorOptions) {
// Use these variables only on initial setup
this.config = config.getConfigFields([ 'isCustomTitleBar', 'mainWinPos', 'minimizeOnClose', 'notificationSettings' ]);
this.globalConfig = config.getGlobalConfigFields([ 'url', 'contextIsolation' ]);
this.globalConfig = config.getGlobalConfigFields([ 'url', 'contextIsolation', 'customFlags' ]);
this.windows = {};
this.contextIsolation = this.globalConfig.contextIsolation || false;
this.backgroundThrottling = !this.globalConfig.customFlags.disableThrottling;
this.isCustomTitleBar = isWindowsOS && this.config.isCustomTitleBar;
this.windowOpts = {
...this.getWindowOpts({
@ -789,6 +791,7 @@ export class WindowHandler {
sandbox: true,
nodeIntegration: false,
contextIsolation: this.contextIsolation,
backgroundThrottling: this.backgroundThrottling,
}, ...webPreferences,
};
const defaultWindowOpts = {

View File

@ -164,7 +164,7 @@ export const showBadgeCount = (count: number): void => {
return;
}
logger.info(`window-utils: updating barge count to ${count}!`);
logger.info(`window-utils: updating badge count to ${count}!`);
if (isMac) {
// too big of a number here and setBadgeCount crashes