Merge remote-tracking branch 'sym/master'

This commit is contained in:
Vishwas Shashidhar 2020-04-01 11:00:00 +05:30
commit bc34c6d59b
2 changed files with 69 additions and 75 deletions

View File

@ -16,6 +16,12 @@ export enum CloudConfigDataTypes {
DISABLED = 'DISABLED', DISABLED = 'DISABLED',
} }
export enum ClientSwitchType {
CLIENT_1_5 = 'CLIENT_1_5',
CLIENT_2_0 = 'CLIENT_2_0',
CLIENT_2_0_DAILY = 'CLIENT_2_0_DAILY',
}
export interface IGlobalConfig { export interface IGlobalConfig {
url: string; url: string;
contextIsolation: boolean; contextIsolation: boolean;
@ -42,6 +48,7 @@ export interface IConfig {
notificationSettings: INotificationSetting; notificationSettings: INotificationSetting;
mainWinPos?: ICustomRectangle; mainWinPos?: ICustomRectangle;
locale?: string; locale?: string;
clientSwitch: ClientSwitchType;
} }
export interface ICloudConfig { export interface ICloudConfig {

View File

@ -1,6 +1,14 @@
import { ChildProcess, ExecException, execFile } from 'child_process'; import { ChildProcess, ExecException, execFile } from 'child_process';
import * as electron from 'electron'; import * as electron from 'electron';
import { app, BrowserWindow, BrowserWindowConstructorOptions, crashReporter, DesktopCapturerSource, globalShortcut, ipcMain } from 'electron'; import {
app,
BrowserWindow,
BrowserWindowConstructorOptions,
crashReporter,
DesktopCapturerSource,
globalShortcut,
ipcMain,
} from 'electron';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { format, parse } from 'url'; import { format, parse } from 'url';
@ -13,7 +21,7 @@ import { getCommandLineArgs, getGuid } from '../common/utils';
import { notification } from '../renderer/notification'; import { notification } from '../renderer/notification';
import { AppMenu } from './app-menu'; import { AppMenu } from './app-menu';
import { handleChildWindow } from './child-window-handler'; import { handleChildWindow } from './child-window-handler';
import { CloudConfigDataTypes, config, IConfig, IGlobalConfig } from './config-handler'; import { ClientSwitchType, CloudConfigDataTypes, config, IConfig, IGlobalConfig } from './config-handler';
import { SpellChecker } from './spell-check-handler'; import { SpellChecker } from './spell-check-handler';
import { checkIfBuildExpired } from './ttl-handler'; import { checkIfBuildExpired } from './ttl-handler';
import { versionHandler } from './version-handler'; import { versionHandler } from './version-handler';
@ -46,14 +54,6 @@ export interface ICustomBrowserWindow extends Electron.BrowserWindow {
const DEFAULT_WIDTH: number = 900; const DEFAULT_WIDTH: number = 900;
const DEFAULT_HEIGHT: number = 900; const DEFAULT_HEIGHT: number = 900;
enum ClientVersionTypes {
CLIENT_1_5 = 'client_1_5',
CLIENT_MANA_STABLE = 'client_mana_stable',
CLIENT_MANA_DAILY = 'client_mana_daily',
}
let currentClient = ClientVersionTypes.CLIENT_1_5;
export class WindowHandler { export class WindowHandler {
/** /**
@ -76,6 +76,8 @@ export class WindowHandler {
public isAutoReload: boolean; public isAutoReload: boolean;
public isOnline: boolean; public isOnline: boolean;
public url: string | undefined; public url: string | undefined;
public startUrl!: string;
public currentClient: ClientSwitchType = ClientSwitchType.CLIENT_1_5;
public willQuitApp: boolean = false; public willQuitApp: boolean = false;
public spellchecker: SpellChecker | undefined; public spellchecker: SpellChecker | undefined;
public isCustomTitleBar: boolean; public isCustomTitleBar: boolean;
@ -101,7 +103,7 @@ export class WindowHandler {
constructor(opts?: Electron.BrowserViewConstructorOptions) { constructor(opts?: Electron.BrowserViewConstructorOptions) {
// Use these variables only on initial setup // Use these variables only on initial setup
this.config = config.getConfigFields([ 'isCustomTitleBar', 'mainWinPos', 'minimizeOnClose', 'notificationSettings', 'alwaysOnTop', 'locale', 'customFlags' ]); this.config = config.getConfigFields([ 'isCustomTitleBar', 'mainWinPos', 'minimizeOnClose', 'notificationSettings', 'alwaysOnTop', 'locale', 'customFlags', 'clientSwitch' ]);
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 { disableThrottling } = config.getCloudConfigFields([ 'disableThrottling' ]) as any;
@ -156,7 +158,7 @@ export class WindowHandler {
/** /**
* Starting point of the app * Starting point of the app
*/ */
public createApplication() { public async createApplication() {
this.updateVersionInfo(); this.updateVersionInfo();
this.spellchecker = new SpellChecker(); this.spellchecker = new SpellChecker();
@ -226,6 +228,7 @@ export class WindowHandler {
} }
} }
this.startUrl = this.url;
// loads the main window with url from config/cmd line // loads the main window with url from config/cmd line
this.mainWindow.loadURL(this.url); this.mainWindow.loadURL(this.url);
// check for build expiry in case of test builds // check for build expiry in case of test builds
@ -241,6 +244,13 @@ export class WindowHandler {
} }
this.url = this.mainWindow.webContents.getURL(); this.url = this.mainWindow.webContents.getURL();
logger.info(`window-handler: client switch from config is ${this.config.clientSwitch}`);
const parsedUrl = parse(this.url);
if (this.url.startsWith('https://corporate.symphony.com') && this.url.indexOf(`https://${parsedUrl.hostname}/client/index.html`) !== -1) {
this.switchClient(this.config.clientSwitch ? this.config.clientSwitch : ClientSwitchType.CLIENT_2_0);
}
// Injects custom title bar and snack bar css into the webContents // Injects custom title bar and snack bar css into the webContents
await injectStyles(this.mainWindow, this.isCustomTitleBar); await injectStyles(this.mainWindow, this.isCustomTitleBar);
@ -990,10 +1000,10 @@ export class WindowHandler {
globalShortcut.register('CmdOrCtrl+R', this.onReload); globalShortcut.register('CmdOrCtrl+R', this.onReload);
// Hack to switch between Client 1.5, Mana-stable and Mana-daily // Hack to switch between Client 1.5, Mana-stable and Mana-daily
if (this.globalConfig.url && this.globalConfig.url.startsWith('https://corporate.symphony.com')) { if (this.url && this.url.startsWith('https://corporate.symphony.com')) {
globalShortcut.register(isMac ? 'Cmd+Alt+1' : 'Ctrl+Shift+1', this.onClient1_5); globalShortcut.register(isMac ? 'Cmd+Alt+1' : 'Ctrl+Shift+1', () => this.switchClient(ClientSwitchType.CLIENT_1_5));
globalShortcut.register(isMac ? 'Cmd+Alt+2' : 'Ctrl+Shift+2', this.onClientManaStable); globalShortcut.register(isMac ? 'Cmd+Alt+2' : 'Ctrl+Shift+2', () => this.switchClient(ClientSwitchType.CLIENT_2_0));
globalShortcut.register(isMac ? 'Cmd+Alt+3' : 'Ctrl+Shift+3', this.onClientManaDaily); globalShortcut.register(isMac ? 'Cmd+Alt+3' : 'Ctrl+Shift+3', () => this.switchClient(ClientSwitchType.CLIENT_2_0_DAILY));
} else { } else {
logger.info('Switch between clients not supported for this POD-url'); logger.info('Switch between clients not supported for this POD-url');
} }
@ -1067,72 +1077,49 @@ export class WindowHandler {
} }
/** /**
* HACK SWITCH to Client 1.5 * Switch between clients 1.5, 2.0 and 2.0 daily
* @param clientSwitch client switch you want to switch to.
*/ */
private async onClient1_5(): Promise <void> { private async switchClient(clientSwitch: ClientSwitchType): Promise<void> {
logger.info('window handler: go to Client 1.5');
logger.info('window handler: currentClient: ' + currentClient);
if (currentClient === ClientVersionTypes.CLIENT_1_5) {
return;
}
currentClient = ClientVersionTypes.CLIENT_1_5;
const focusedWindow = BrowserWindow.getFocusedWindow();
const dogfoodUrl = `https://corporate.symphony.com/`;
if (focusedWindow && windowExists(focusedWindow)) {
await focusedWindow.loadURL(dogfoodUrl);
} else {
logger.error('window handler: Could not go to client 1.5');
}
}
/** if (this.currentClient && this.currentClient === clientSwitch) {
* HACK SWITCH to Client Mana-stable logger.info(`window handler: already in the same client ${clientSwitch}. Not switching!`);
*/
private async onClientManaStable(): Promise <void> {
logger.info('window handler: go to Client Mana-stable');
logger.info('window handler: currentClient: ' + currentClient);
if (currentClient === ClientVersionTypes.CLIENT_MANA_STABLE) {
return; return;
} }
currentClient = ClientVersionTypes.CLIENT_MANA_STABLE; logger.info(`window handler: switch to client ${clientSwitch}`);
logger.info(`window handler: currentClient: ${this.currentClient}`);
this.currentClient = clientSwitch;
const focusedWindow = BrowserWindow.getFocusedWindow(); const focusedWindow = BrowserWindow.getFocusedWindow();
let csrfToken;
if (focusedWindow && windowExists(focusedWindow)) { if (!(focusedWindow && windowExists(focusedWindow))) {
try { return;
csrfToken = await focusedWindow.webContents.executeJavaScript(`localStorage.getItem('x-km-csrf-token')`); }
} catch (e) { try {
logger.error(e); if (!this.url) {
this.url = this.globalConfig.url;
} }
const dogfoodUrl = `https://corporate.symphony.com/client-bff/index.html?x-km-csrf-token=${csrfToken}`; const parsedUrl = parse(this.url);
await focusedWindow.loadURL(dogfoodUrl); const manaPath = 'client-bff';
} else { const manaChannel = 'daily';
logger.error('window handler: Could not go to client Mana-stable'); const csrfToken = await focusedWindow.webContents.executeJavaScript(`localStorage.getItem('x-km-csrf-token')`);
} switch (this.currentClient) {
} case ClientSwitchType.CLIENT_1_5:
this.url = this.startUrl;
/** break;
* HACK SWITCH to Client Mana-daily case ClientSwitchType.CLIENT_2_0:
*/ this.url = `https://${parsedUrl.hostname}/${manaPath}/index.html?x-km-csrf-token=${csrfToken}`;
private async onClientManaDaily(): Promise <void> { break;
logger.info('window handler: go to Client Mana-daily'); case ClientSwitchType.CLIENT_2_0_DAILY:
logger.info('window handler: currentClient: ' + currentClient); this.url = `https://${parsedUrl.hostname}/${manaPath}/${manaChannel}/index.html?x-km-csrf-token=${csrfToken}`;
if (currentClient === ClientVersionTypes.CLIENT_MANA_DAILY) { break;
return; default:
} this.url = this.globalConfig.url;
currentClient = ClientVersionTypes.CLIENT_MANA_DAILY;
const focusedWindow = BrowserWindow.getFocusedWindow();
let csrfToken;
if (focusedWindow && windowExists(focusedWindow)) {
try {
csrfToken = await focusedWindow.webContents.executeJavaScript(`localStorage.getItem('x-km-csrf-token')`);
} catch (e) {
logger.error(e);
} }
await config.updateUserConfig({ clientSwitch });
const dogfoodUrl = `https://corporate.symphony.com/client-bff/daily/index.html?x-km-csrf-token=${csrfToken}`; this.config.clientSwitch = clientSwitch;
await focusedWindow.loadURL(dogfoodUrl); await focusedWindow.loadURL(this.url);
} else { } catch (e) {
logger.error('window handler: Could not go to client Mana-stable'); logger.error(`window-handler: failed to switch client because of error ${e}`);
} }
} }