mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-26 08:51:22 -06:00
feat: ELECTRON-1332 (Make Context Isolation configurable) (#691)
* ELECTRON-1332 - Make Context Isolation configurable * ELECTRON-1332 - Abstract opts constructors functions
This commit is contained in:
parent
0caef99513
commit
2e80c599fc
@ -8,6 +8,7 @@
|
||||
"isCustomTitleBar": true,
|
||||
"memoryRefresh": true,
|
||||
"devToolsEnabled": true,
|
||||
"contextIsolation": false,
|
||||
"ctWhitelist": [],
|
||||
"notificationSettings": {
|
||||
"position": "upper-right",
|
||||
|
@ -31,6 +31,7 @@ export interface IConfig {
|
||||
isCustomTitleBar: boolean;
|
||||
memoryRefresh: boolean;
|
||||
devToolsEnabled: boolean;
|
||||
contextIsolation: boolean;
|
||||
ctWhitelist: string[];
|
||||
configVersion: string;
|
||||
buildNumber: string;
|
||||
|
@ -45,97 +45,6 @@ const DEFAULT_HEIGHT: number = 900;
|
||||
|
||||
export class WindowHandler {
|
||||
|
||||
/**
|
||||
* Screen picker window opts
|
||||
*/
|
||||
private static getScreenPickerWindowOpts(): ICustomBrowserWindowConstructorOpts {
|
||||
return {
|
||||
alwaysOnTop: true,
|
||||
autoHideMenuBar: true,
|
||||
frame: false,
|
||||
height: isMac ? 519 : 523,
|
||||
width: 580,
|
||||
modal: false,
|
||||
resizable: true,
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
sandbox: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
winKey: getGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification settings window opts
|
||||
*/
|
||||
private static getNotificationSettingsOpts(): ICustomBrowserWindowConstructorOpts {
|
||||
return {
|
||||
width: 460,
|
||||
height: 360,
|
||||
show: false,
|
||||
modal: true,
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
fullscreenable: false,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
sandbox: true,
|
||||
nodeIntegration: false,
|
||||
devTools: false,
|
||||
contextIsolation: false,
|
||||
},
|
||||
winKey: getGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Screen sharing indicator window opts
|
||||
*/
|
||||
private static getScreenSharingIndicatorOpts(): ICustomBrowserWindowConstructorOpts {
|
||||
return {
|
||||
width: 620,
|
||||
height: 48,
|
||||
show: false,
|
||||
modal: true,
|
||||
frame: false,
|
||||
focusable: false,
|
||||
transparent: true,
|
||||
autoHideMenuBar: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
webPreferences: {
|
||||
sandbox: true,
|
||||
nodeIntegration: false,
|
||||
devTools: false,
|
||||
contextIsolation: false,
|
||||
},
|
||||
winKey: getGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic auth window opts
|
||||
*/
|
||||
private static getBasicAuthOpts(): ICustomBrowserWindowConstructorOpts {
|
||||
return {
|
||||
width: 360,
|
||||
height: isMac ? 270 : 295,
|
||||
show: false,
|
||||
modal: true,
|
||||
autoHideMenuBar: true,
|
||||
resizable: false,
|
||||
webPreferences: {
|
||||
sandbox: true,
|
||||
nodeIntegration: false,
|
||||
devTools: false,
|
||||
contextIsolation: false,
|
||||
},
|
||||
winKey: getGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the url is valid and
|
||||
* forcefully appends https if not present
|
||||
@ -159,6 +68,7 @@ export class WindowHandler {
|
||||
public willQuitApp: boolean = false;
|
||||
public spellchecker: SpellChecker | undefined;
|
||||
|
||||
private readonly contextIsolation: boolean;
|
||||
private readonly windowOpts: ICustomBrowserWindowConstructorOpts;
|
||||
private readonly globalConfig: IConfig;
|
||||
private readonly config: IConfig;
|
||||
@ -178,11 +88,21 @@ 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' ]);
|
||||
this.globalConfig = config.getGlobalConfigFields([ 'url', 'contextIsolation' ]);
|
||||
|
||||
this.windows = {};
|
||||
this.contextIsolation = this.globalConfig.contextIsolation || false;
|
||||
this.isCustomTitleBar = isWindowsOS && this.config.isCustomTitleBar;
|
||||
this.windowOpts = { ...this.getMainWindowOpts(), ...opts };
|
||||
this.windowOpts = {
|
||||
...this.getWindowOpts({
|
||||
frame: !this.isCustomTitleBar,
|
||||
minHeight: 300,
|
||||
minWidth: 300,
|
||||
title: 'Symphony',
|
||||
}, {
|
||||
preload: path.join(__dirname, '../renderer/_preload-main.js'),
|
||||
}), ...opts,
|
||||
};
|
||||
this.isAutoReload = false;
|
||||
this.isOnline = true;
|
||||
|
||||
@ -519,7 +439,16 @@ export class WindowHandler {
|
||||
this.screenPickerWindow.close();
|
||||
}
|
||||
|
||||
const opts = WindowHandler.getScreenPickerWindowOpts();
|
||||
const opts = this.getWindowOpts({
|
||||
alwaysOnTop: true,
|
||||
autoHideMenuBar: true,
|
||||
frame: false,
|
||||
height: isMac ? 519 : 523,
|
||||
width: 580,
|
||||
show: false,
|
||||
}, {
|
||||
devTools: false,
|
||||
});
|
||||
this.screenPickerWindow = createComponentWindow('screen-picker', opts);
|
||||
this.screenPickerWindow.webContents.once('did-finish-load', () => {
|
||||
if (!this.screenPickerWindow || !windowExists(this.screenPickerWindow)) {
|
||||
@ -553,7 +482,16 @@ export class WindowHandler {
|
||||
* @param callback
|
||||
*/
|
||||
public createBasicAuthWindow(window: ICustomBrowserWindow, hostname: string, isMultipleTries: boolean, clearSettings, callback): void {
|
||||
const opts = WindowHandler.getBasicAuthOpts();
|
||||
const opts = this.getWindowOpts({
|
||||
width: 360,
|
||||
height: isMac ? 270 : 295,
|
||||
show: false,
|
||||
modal: true,
|
||||
autoHideMenuBar: true,
|
||||
resizable: false,
|
||||
}, {
|
||||
devTools: false,
|
||||
});
|
||||
opts.parent = window;
|
||||
this.basicAuthWindow = createComponentWindow('basic-auth', opts);
|
||||
this.basicAuthWindow.setVisibleOnAllWorkspaces(true);
|
||||
@ -594,7 +532,18 @@ export class WindowHandler {
|
||||
* @param windowName
|
||||
*/
|
||||
public createNotificationSettingsWindow(windowName: string): void {
|
||||
const opts = WindowHandler.getNotificationSettingsOpts();
|
||||
const opts = this.getWindowOpts({
|
||||
width: 460,
|
||||
height: 360,
|
||||
show: false,
|
||||
modal: true,
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
fullscreenable: false,
|
||||
autoHideMenuBar: true,
|
||||
}, {
|
||||
devTools: false,
|
||||
});
|
||||
// This prevents creating multiple instances of the
|
||||
// notification configuration window
|
||||
if (this.notificationSettingsWindow && !this.notificationSettingsWindow.isDestroyed()) {
|
||||
@ -669,7 +618,22 @@ export class WindowHandler {
|
||||
|
||||
const screenRect = indicatorScreen.workArea;
|
||||
// Set stream id as winKey to link stream to the window
|
||||
let opts = { ...WindowHandler.getScreenSharingIndicatorOpts(), ...{ winKey: streamId } };
|
||||
let opts = {
|
||||
...this.getWindowOpts({
|
||||
width: 620,
|
||||
height: 48,
|
||||
show: false,
|
||||
modal: true,
|
||||
frame: false,
|
||||
focusable: false,
|
||||
transparent: true,
|
||||
autoHideMenuBar: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
}, {
|
||||
devTools: false,
|
||||
}), ...{ winKey: streamId },
|
||||
};
|
||||
if (opts.width && opts.height) {
|
||||
opts = Object.assign({}, opts, {
|
||||
x: screenRect.x + Math.round((screenRect.width - opts.width) / 2),
|
||||
@ -784,27 +748,6 @@ export class WindowHandler {
|
||||
this.mainWindow = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main window opts
|
||||
*/
|
||||
private getMainWindowOpts(): ICustomBrowserWindowConstructorOpts {
|
||||
return {
|
||||
alwaysOnTop: false,
|
||||
frame: !this.isCustomTitleBar,
|
||||
minHeight: 300,
|
||||
minWidth: 300,
|
||||
show: true,
|
||||
title: 'Symphony',
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
preload: path.join(__dirname, '../renderer/_preload-main.js'),
|
||||
sandbox: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
winKey: getGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if build is expired and show an error message
|
||||
* @param browserWindow Focused window instance
|
||||
@ -827,12 +770,35 @@ export class WindowHandler {
|
||||
type: 'error',
|
||||
title: i18n.t('Build expired')(),
|
||||
message: i18n.t('Sorry, this is a test build and it has expired. Please contact your administrator to get a production build.')(),
|
||||
buttons: [ i18n.t('Quit')()],
|
||||
buttons: [ i18n.t('Quit')() ],
|
||||
cancelId: 0,
|
||||
};
|
||||
|
||||
electron.dialog.showMessageBox(browserWindow, options, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns constructor opts for the browser window
|
||||
*
|
||||
* @param windowOpts {Electron.BrowserWindowConstructorOptions}
|
||||
* @param webPreferences {Electron.WebPreferences}
|
||||
*/
|
||||
private getWindowOpts(windowOpts: Electron.BrowserWindowConstructorOptions, webPreferences: Electron.WebPreferences): ICustomBrowserWindowConstructorOpts {
|
||||
const defaultPreferencesOpts = {
|
||||
...{
|
||||
sandbox: true,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: this.contextIsolation,
|
||||
}, ...webPreferences,
|
||||
};
|
||||
const defaultWindowOpts = {
|
||||
alwaysOnTop: false,
|
||||
webPreferences: defaultPreferencesOpts,
|
||||
winKey: getGuid(),
|
||||
};
|
||||
|
||||
return { ...defaultWindowOpts, ...windowOpts };
|
||||
}
|
||||
}
|
||||
|
||||
const windowHandler = new WindowHandler();
|
||||
|
Loading…
Reference in New Issue
Block a user