diff --git a/spec/mainApiHandler.spec.ts b/spec/mainApiHandler.spec.ts index 4473cb62..91f56389 100644 --- a/spec/mainApiHandler.spec.ts +++ b/spec/mainApiHandler.spec.ts @@ -44,6 +44,7 @@ jest.mock('../src/app/window-handler', () => { createScreenSharingIndicatorWindow: jest.fn(), isOnline: false, updateVersionInfo: jest.fn(), + isMana: false, }, }; }); @@ -405,5 +406,15 @@ describe('main api handler', () => { ipcMain.send(apiName.symphonyApi, value); expect(spy).toBeCalledWith(...expectedValue); }); + + it('should call `setIsMana` correctly', () => { + const value = { + cmd: apiCmds.setIsMana, + isMana: true, + }; + expect(windowHandler.isMana).toBe(false); + ipcMain.send(apiName.symphonyApi, value); + expect(windowHandler.isMana).toBe(true); + }); }); }); diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index b9a97f04..491f8e5e 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -201,7 +201,15 @@ ipcMain.on(apiName.symphonyApi, async (event: Electron.IpcMainEvent, arg: IApiAr if (windowHandler.appMenu) { windowHandler.appMenu.buildMenu(); } + break; + case apiCmds.setIsMana: + if (typeof arg.isMana === 'boolean') { + windowHandler.isMana = arg.isMana; + logger.info('window-handler: isMana: ' + windowHandler.isMana); + } + break; default: + break; } }); diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index 77c6e762..6b9723cc 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -425,6 +425,8 @@ export class WindowHandler { }); this.mainWindow.webContents.on('did-finish-load', async () => { + // reset to false when the client reloads + this.isMana = false; logger.info(`window-handler: main window web contents finished loading!`); // early exit if the window has already been destroyed if (!this.mainWindow || !windowExists(this.mainWindow)) { @@ -435,13 +437,6 @@ export class WindowHandler { } this.url = this.mainWindow.webContents.getURL(); logger.info('window-handler: did-finish-load, url: ' + this.url); - const manaPath = 'client-bff'; - if (this.url.includes(manaPath)) { - this.isMana = true; - } else { - this.isMana = false; - } - logger.info('window-handler: isMana: ' + this.isMana); // Injects custom title bar and snack bar css into the webContents await injectStyles(this.mainWindow, this.isCustomTitleBar); diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index 6d706a77..f1e657fd 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -669,9 +669,7 @@ export const monitorNetworkInterception = (url: string) => { if (!mainWindow || !windowExists(mainWindow)) { return; } - const manaUrl: string = await mainWindow.webContents.executeJavaScript('document.location.href'); - const isMana = manaUrl && manaUrl.includes('client-bff'); - if (!isMana && windowHandler.isWebPageLoading + if (!windowHandler.isMana && windowHandler.isWebPageLoading && (details.error === 'net::ERR_INTERNET_DISCONNECTED' || details.error === 'net::ERR_NETWORK_CHANGED' || details.error === 'net::ERR_NAME_NOT_RESOLVED')) { diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index ebc65a7b..835d15d3 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -43,6 +43,7 @@ export enum apiCmds { showDownloadedItem = 'show-downloaded-item', clearDownloadedItems = 'clear-downloaded-items', restartApp = 'restart-app', + setIsMana = 'set-is-mana', } export enum apiName { @@ -78,6 +79,7 @@ export interface IApiArgs { logName: string; logs: ILogs; cloudConfig: object; + isMana: boolean; } export type WindowTypes = 'screen-picker' | 'screen-sharing-indicator' | 'notification-settings'; diff --git a/src/renderer/preload-main.ts b/src/renderer/preload-main.ts index 580dce83..c7aec3d5 100644 --- a/src/renderer/preload-main.ts +++ b/src/renderer/preload-main.ts @@ -51,6 +51,7 @@ createAPI(); if (ssfWindow.ssf) { // New context bridge api that exposes all the methods on to window object contextBridge.exposeInMainWorld('manaSSF', { + setIsMana: ssfWindow.ssf.setIsMana, CryptoLib: ssfWindow.ssf.CryptoLib, Search: ssfWindow.ssf.Search, Notification: ssfWindow.ssf.Notification, diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index 94594499..c884f3a6 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -579,6 +579,17 @@ export class SSFApi { }); } + /** + * Sets whether the client is running on mana + * @param isMana + */ + public setIsMana(isMana: boolean): void { + ipcRenderer.send(apiName.symphonyApi, { + cmd: apiCmds.setIsMana, + isMana, + }); + } + } /**