SDA-3933: Add api to hide SDA

This commit is contained in:
NguyenTranHoangSym 2022-11-22 17:02:16 +07:00 committed by Salah Benmoussati
parent a8e7360c23
commit 6d4c198e79
7 changed files with 55 additions and 14 deletions

View File

@ -403,7 +403,18 @@ describe('main api handler', () => {
};
const expectedValue = { send: expect.any(Function) };
ipcMain.send(apiName.symphonyApi, value);
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith(expectedValue, undefined);
});
it('should call `openScreenSnippet` with hideOnCapture correctly', () => {
const spy = jest.spyOn(screenSnippet, 'capture');
const value = {
cmd: apiCmds.openScreenSnippet,
hideOnCapture: true,
};
const expectedValue = { send: expect.any(Function) };
ipcMain.send(apiName.symphonyApi, value);
expect(spy).toBeCalledWith(expectedValue, true);
});
it('should call `closeWindow` correctly', () => {

View File

@ -203,7 +203,7 @@ ipcMain.on(
}
break;
case apiCmds.openScreenSnippet:
screenSnippet.capture(event.sender);
screenSnippet.capture(event.sender, arg.hideOnCapture);
break;
case apiCmds.closeScreenSnippet:
screenSnippet.cancelCapture();

View File

@ -87,8 +87,12 @@ class ScreenSnippet {
*
* @param webContents {WeContents}
*/
public async capture(webContents: WebContents) {
public async capture(webContents: WebContents, hideOnCapture?: boolean) {
const mainWindow = windowHandler.getMainWindow();
if (hideOnCapture) {
mainWindow?.minimize();
}
if (mainWindow && windowExists(mainWindow) && isWindowsOS) {
this.shouldUpdateAlwaysOnTop = mainWindow.isAlwaysOnTop();
if (this.shouldUpdateAlwaysOnTop) {
@ -178,8 +182,9 @@ class ScreenSnippet {
this.outputFilePath,
dimensions,
windowName,
hideOnCapture,
);
this.uploadSnippet(webContents);
this.uploadSnippet(webContents, mainWindow);
this.closeSnippet();
this.copyToClipboard();
this.saveAs();
@ -333,7 +338,10 @@ class ScreenSnippet {
* Uploads a screen snippet
* @param webContents A browser window's web contents object
*/
private uploadSnippet(webContents: WebContents) {
private uploadSnippet(
webContents: WebContents,
mainWindow: ICustomBrowserWindow | null,
) {
ipcMain.once(
'upload-snippet',
async (
@ -352,6 +360,7 @@ class ScreenSnippet {
'screen-snippet-handler: Snippet uploaded correctly, sending payload to SFE',
);
webContents.send('screen-snippet-data', payload);
mainWindow?.restore();
await this.verifyAndUpdateAlwaysOnTop();
} catch (error) {
await this.verifyAndUpdateAlwaysOnTop();

View File

@ -166,6 +166,7 @@ export class WindowHandler {
private snippingToolWindow: Electron.BrowserWindow | null = null;
private finishedLoading: boolean = false;
private readonly opts: Electron.BrowserViewConstructorOptions | undefined;
private hideOnCapture: boolean = false;
constructor(opts?: Electron.BrowserViewConstructorOptions) {
this.opts = opts;
@ -1193,6 +1194,7 @@ export class WindowHandler {
width: number;
},
windowName: string,
hideOnCapture?: boolean,
): void {
// Prevents creating multiple instances
if (didVerifyAndRestoreWindow(this.snippingToolWindow)) {
@ -1200,6 +1202,8 @@ export class WindowHandler {
return;
}
this.hideOnCapture = !!hideOnCapture;
logger.info(
'window-handler, createSnippingToolWindow: Receiving snippet props: ' +
JSON.stringify({
@ -1283,7 +1287,7 @@ export class WindowHandler {
height: toolHeight,
parent: selectedParentWindow,
modal: true,
alwaysOnTop: false,
alwaysOnTop: hideOnCapture,
resizable: false,
fullscreenable: false,
},
@ -1364,6 +1368,9 @@ export class WindowHandler {
logger.info(
'window-handler, createSnippingToolWindow: Closing snipping window, attempting to delete temp snip image',
);
if (this.hideOnCapture) {
this.mainWindow?.restore();
}
ipcMain.removeAllListeners(ScreenShotAnnotation.COPY_TO_CLIPBOARD);
ipcMain.removeAllListeners(ScreenShotAnnotation.SAVE_AS);
this.snippingToolWindow?.close();

View File

@ -126,6 +126,7 @@ export interface IApiArgs {
pipe: string;
data: Uint8Array;
autoUpdateTrigger: AutoUpdateTrigger;
hideOnCapture: boolean;
}
export type Themes = 'light' | 'dark';
@ -142,7 +143,7 @@ export interface IBadgeCount {
/**
* Screen snippet
*/
export type ScreenSnippetDataType = 'ERROR' | 'image/png;base64';
export type ScreenSnippetDataType = 'ERROR' | 'image/png;base64' | 'HIDE_SDA';
export interface IScreenSnippet {
data?: string;
message?: string;

View File

@ -38,7 +38,7 @@ export class AppBridge {
public origin: string = '';
private readonly callbackHandlers = {
onMessage: (event) => this.handleMessage(event),
onMessage: (event: MessageEvent) => this.handleMessage(event),
onActivityCallback: (idleTime: number) => this.activityCallback(idleTime),
onScreenSnippetCallback: (arg: IScreenSnippet) =>
this.screenSnippetCallback(arg),
@ -95,7 +95,7 @@ export class AppBridge {
*
* @param event
*/
private async handleMessage(event): Promise<void> {
private async handleMessage(event: MessageEvent): Promise<void> {
if (!AppBridge.isValidEvent(event)) {
return;
}

View File

@ -364,19 +364,32 @@ export class SSFApi {
public ScreenSnippet = ScreenSnippetBcHandler;
/**
* Allow user to capture portion of screen
* Allow user to capture portion of screen.
* There is a method overload of this with additional param allows user to hide SDA,
* if none is provided then the old logic will be triggered.
*
* @param screenSnippetCallback {function}
* @param openScreenSnippet {function}
*/
public openScreenSnippet(
screenSnippetCallback: (arg: IScreenSnippet) => void,
): void;
public openScreenSnippet(
screenSnippetCallback: (arg: IScreenSnippet) => void,
hideOnCapture?: boolean,
): void {
if (typeof screenSnippetCallback === 'function') {
local.screenSnippetCallback = screenSnippetCallback;
local.ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openScreenSnippet,
});
if (hideOnCapture) {
local.ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openScreenSnippet,
hideOnCapture,
});
} else {
local.ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openScreenSnippet,
});
}
}
}