feat: SDA-2652 - add new API to set if running in mana client (#1113)

This commit is contained in:
Kiran Niranjan 2020-11-17 11:51:31 +05:30 committed by GitHub
parent 18e4b79f8e
commit 33ed6f709c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 10 deletions

View File

@ -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);
});
});
});

View File

@ -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;
}
});

View File

@ -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);

View File

@ -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')) {

View File

@ -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';

View File

@ -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,

View File

@ -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,
});
}
}
/**