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) }; const expectedValue = { send: expect.any(Function) };
ipcMain.send(apiName.symphonyApi, value); 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', () => { it('should call `closeWindow` correctly', () => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -364,19 +364,32 @@ export class SSFApi {
public ScreenSnippet = ScreenSnippetBcHandler; 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( public openScreenSnippet(
screenSnippetCallback: (arg: IScreenSnippet) => void, screenSnippetCallback: (arg: IScreenSnippet) => void,
): void;
public openScreenSnippet(
screenSnippetCallback: (arg: IScreenSnippet) => void,
hideOnCapture?: boolean,
): void { ): void {
if (typeof screenSnippetCallback === 'function') { if (typeof screenSnippetCallback === 'function') {
local.screenSnippetCallback = screenSnippetCallback; local.screenSnippetCallback = screenSnippetCallback;
local.ipcRenderer.send(apiName.symphonyApi, { if (hideOnCapture) {
cmd: apiCmds.openScreenSnippet, local.ipcRenderer.send(apiName.symphonyApi, {
}); cmd: apiCmds.openScreenSnippet,
hideOnCapture,
});
} else {
local.ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openScreenSnippet,
});
}
} }
} }