From 4da7cd6d17c540a1da86dfca136697aa6a5e66bf Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 30 May 2019 17:24:04 +0530 Subject: [PATCH] Typescript (Fix issues with setting the window origin) (#663) * Typescript - Fix issues with setting the window origin * Typescript - Fix lint issue * Typescript - Fix frequent window activation --- src/app/main-api-handler.ts | 4 ++++ src/app/window-handler.ts | 4 ++-- src/common/api-interface.ts | 1 + src/renderer/app-bridge.ts | 11 ++++++++--- src/renderer/desktop-capturer.ts | 2 +- src/renderer/preload-main.ts | 9 ++------- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index 54864901..db96334a 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -143,6 +143,10 @@ ipcMain.on(apiName.symphonyApi, (event: Electron.Event, arg: IApiArgs) => { memoryMonitor.setMemoryInfo(arg.memoryInfo); } break; + case apiCmds.getConfigUrl: + const { url } = config.getGlobalConfigFields([ 'url' ]); + event.returnValue = url; + break; default: } diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index f1142778..48aa2706 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -272,7 +272,6 @@ export class WindowHandler { isWindowsOS, locale: i18n.getLocale(), resources: i18n.loadedResources, - origin: this.globalConfig.url, enableCustomTitleBar: this.isCustomTitleBar, isMainWindow: true, }); @@ -394,7 +393,8 @@ export class WindowHandler { } // Ready to show the window - if (!this.isAutoReload) { + // activate the window only if it is not visible to the user + if (!this.isAutoReload && !this.mainWindow.isVisible()) { this.mainWindow.show(); } } diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index ccb4aaa7..42bff55a 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -30,6 +30,7 @@ export enum apiCmds { isMisspelled = 'is-misspelled', memoryInfo = 'memory-info', swiftSearch = 'swift-search', + getConfigUrl = 'get-config-url', } export enum apiName { diff --git a/src/renderer/app-bridge.ts b/src/renderer/app-bridge.ts index 5c76403e..11a83f42 100644 --- a/src/renderer/app-bridge.ts +++ b/src/renderer/app-bridge.ts @@ -1,7 +1,8 @@ -import { remote } from 'electron'; +import { ipcRenderer, remote } from 'electron'; import { apiCmds, + apiName, IBoundsChange, ILogMsg, INotificationData, IScreenSharingIndicator, IScreenSharingIndicatorOptions, @@ -23,7 +24,7 @@ try { console.warn("Failed to initialize swift search. You'll need to include the search dependency. Contact the developers for more details"); } -export default class AppBridge { +export class AppBridge { /** * Validates the incoming postMessage @@ -59,7 +60,7 @@ export default class AppBridge { constructor() { // starts with corporate pod and // will be updated with the global config url - this.origin = 'https://corporate.symphony.com'; + this.origin = ipcRenderer.sendSync(apiName.symphonyApi, { cmd: apiCmds.getConfigUrl }); if (ssInstance && typeof ssInstance.setBroadcastMessage === 'function') { ssInstance.setBroadcastMessage(this.broadcastMessage); } @@ -230,3 +231,7 @@ export default class AppBridge { } } + +const appBridge = new AppBridge(); + +export default appBridge; diff --git a/src/renderer/desktop-capturer.ts b/src/renderer/desktop-capturer.ts index 10bbedf2..488ee062 100644 --- a/src/renderer/desktop-capturer.ts +++ b/src/renderer/desktop-capturer.ts @@ -10,7 +10,7 @@ import { apiCmds, apiName } from '../common/api-interface'; import { isWindowsOS } from '../common/env'; import { i18n } from '../common/i18n-preload'; -const includes = [].includes; +const includes = [''].includes; let nextId = 0; let isScreenShareEnabled = false; diff --git a/src/renderer/preload-main.ts b/src/renderer/preload-main.ts index 4ff2b3af..341ac7e3 100644 --- a/src/renderer/preload-main.ts +++ b/src/renderer/preload-main.ts @@ -4,7 +4,7 @@ import * as ReactDOM from 'react-dom'; import { apiCmds, apiName } from '../common/api-interface'; import { i18n } from '../common/i18n-preload'; -import AppBridge from './app-bridge'; +import './app-bridge'; import DownloadManager from './components/download-manager'; import SnackBar from './components/snack-bar'; import WindowsTitleBar from './components/windows-title-bar'; @@ -15,7 +15,6 @@ interface ISSFWindow extends Window { } const ssfWindow: ISSFWindow = window; -const appBridge = new AppBridge(); const memoryInfoFetchInterval = 60 * 60 * 1000; /** @@ -43,11 +42,7 @@ const createAPI = () => { createAPI(); // When the window is completely loaded -ipcRenderer.on('page-load', (_event, { locale, resources, origin, enableCustomTitleBar, isMainWindow }) => { - // origin for postMessage targetOrigin communication - if (origin) { - appBridge.origin = origin; - } +ipcRenderer.on('page-load', (_event, { locale, resources, enableCustomTitleBar, isMainWindow }) => { i18n.setResource(locale, resources);