SDA-3976: Add few bugs fixed

This commit is contained in:
NguyenTranHoangSym 2022-11-28 11:39:12 +07:00 committed by Salah Benmoussati
parent 921fd5eeea
commit f5bca5f4fa
5 changed files with 57 additions and 26 deletions

View File

@ -398,23 +398,33 @@ describe('main api handler', () => {
it('should call `openScreenSnippet` correctly', () => { it('should call `openScreenSnippet` correctly', () => {
const spy = jest.spyOn(screenSnippet, 'capture'); const spy = jest.spyOn(screenSnippet, 'capture');
jest.spyOn(BrowserWindow, 'getFocusedWindow').mockImplementation(() => {
return {
winName: 'main',
};
});
const value = { const value = {
cmd: apiCmds.openScreenSnippet, cmd: apiCmds.openScreenSnippet,
}; };
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, undefined); expect(spy).toBeCalledWith(expectedValue, 'main', undefined);
}); });
it('should call `openScreenSnippet` with hideOnCapture correctly', () => { it('should call `openScreenSnippet` with hideOnCapture correctly', () => {
const spy = jest.spyOn(screenSnippet, 'capture'); const spy = jest.spyOn(screenSnippet, 'capture');
jest.spyOn(BrowserWindow, 'getFocusedWindow').mockImplementation(() => {
return {
winName: 'main',
};
});
const value = { const value = {
cmd: apiCmds.openScreenSnippet, cmd: apiCmds.openScreenSnippet,
hideOnCapture: true, hideOnCapture: true,
}; };
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, true); expect(spy).toBeCalledWith(expectedValue, 'main', true);
}); });
it('should call `closeWindow` correctly', () => { it('should call `closeWindow` correctly', () => {

View File

@ -91,6 +91,7 @@ ipcMain.on(
return; return;
} }
const mainWebContents = windowHandler.getMainWebContents(); const mainWebContents = windowHandler.getMainWebContents();
const currentWindow = BrowserWindow.getFocusedWindow();
logApiCallParams(arg); logApiCallParams(arg);
switch (arg.cmd) { switch (arg.cmd) {
case apiCmds.isOnline: case apiCmds.isOnline:
@ -203,7 +204,11 @@ ipcMain.on(
} }
break; break;
case apiCmds.openScreenSnippet: case apiCmds.openScreenSnippet:
screenSnippet.capture(event.sender, arg.hideOnCapture); screenSnippet.capture(
event.sender,
(currentWindow as ICustomBrowserWindow)?.winName,
arg.hideOnCapture,
);
break; break;
case apiCmds.closeScreenSnippet: case apiCmds.closeScreenSnippet:
screenSnippet.cancelCapture(); screenSnippet.cancelCapture();

View File

@ -30,8 +30,8 @@ import {
ScreenSnippetActionTypes, ScreenSnippetActionTypes,
} from './analytics-handler'; } from './analytics-handler';
import { updateAlwaysOnTop } from './window-actions'; import { updateAlwaysOnTop } from './window-actions';
import { ICustomBrowserWindow, windowHandler } from './window-handler'; import { windowHandler } from './window-handler';
import { windowExists } from './window-utils'; import { getWindowByName, windowExists } from './window-utils';
const readFile = util.promisify(fs.readFile); const readFile = util.promisify(fs.readFile);
@ -87,10 +87,19 @@ class ScreenSnippet {
* *
* @param webContents {WeContents} * @param webContents {WeContents}
*/ */
public async capture(webContents: WebContents, hideOnCapture?: boolean) { public async capture(
webContents: WebContents,
currentWindow?: string,
hideOnCapture?: boolean,
) {
const mainWindow = windowHandler.getMainWindow(); const mainWindow = windowHandler.getMainWindow();
if (hideOnCapture) { if (hideOnCapture) {
const curWindow = getWindowByName(currentWindow || '');
const mainWindow = windowHandler.getMainWindow();
mainWindow?.minimize(); mainWindow?.minimize();
if (currentWindow !== 'main') {
curWindow?.minimize();
}
} }
if (mainWindow && windowExists(mainWindow) && isWindowsOS) { if (mainWindow && windowExists(mainWindow) && isWindowsOS) {
@ -175,16 +184,13 @@ class ScreenSnippet {
} }
windowHandler.closeSnippingToolWindow(); windowHandler.closeSnippingToolWindow();
const windowName = this.focusedWindow
? (this.focusedWindow as ICustomBrowserWindow).winName
: '';
windowHandler.createSnippingToolWindow( windowHandler.createSnippingToolWindow(
this.outputFilePath, this.outputFilePath,
dimensions, dimensions,
windowName, currentWindow,
hideOnCapture, hideOnCapture,
); );
this.uploadSnippet(webContents, mainWindow); this.uploadSnippet(webContents, currentWindow, hideOnCapture);
this.closeSnippet(); this.closeSnippet();
this.copyToClipboard(); this.copyToClipboard();
this.saveAs(); this.saveAs();
@ -340,7 +346,8 @@ class ScreenSnippet {
*/ */
private uploadSnippet( private uploadSnippet(
webContents: WebContents, webContents: WebContents,
mainWindow: ICustomBrowserWindow | null, currentWindow?: string,
hideOnCapture?: boolean,
) { ) {
ipcMain.once( ipcMain.once(
'upload-snippet', 'upload-snippet',
@ -360,7 +367,14 @@ 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(); if (hideOnCapture) {
const curWindow = getWindowByName(currentWindow || '');
const mainWindow = windowHandler.getMainWindow();
mainWindow?.focus();
if (currentWindow !== 'main') {
curWindow?.focus();
}
}
await this.verifyAndUpdateAlwaysOnTop(); await this.verifyAndUpdateAlwaysOnTop();
} catch (error) { } catch (error) {
await this.verifyAndUpdateAlwaysOnTop(); await this.verifyAndUpdateAlwaysOnTop();
@ -437,7 +451,7 @@ class ScreenSnippet {
}, },
) => { ) => {
const filePath = path.join( const filePath = path.join(
this.tempDir, app.getPath('downloads'),
'symphonyImage-' + Date.now() + '.png', 'symphonyImage-' + Date.now() + '.png',
); );
const [, data] = saveAsData.clipboard.split(','); const [, data] = saveAsData.clipboard.split(',');

View File

@ -167,6 +167,7 @@ export class WindowHandler {
private finishedLoading: boolean = false; private finishedLoading: boolean = false;
private readonly opts: Electron.BrowserViewConstructorOptions | undefined; private readonly opts: Electron.BrowserViewConstructorOptions | undefined;
private hideOnCapture: boolean = false; private hideOnCapture: boolean = false;
private currentWindow?: string = undefined;
constructor(opts?: Electron.BrowserViewConstructorOptions) { constructor(opts?: Electron.BrowserViewConstructorOptions) {
this.opts = opts; this.opts = opts;
@ -1193,7 +1194,7 @@ export class WindowHandler {
height: number; height: number;
width: number; width: number;
}, },
windowName: string, currentWindow?: string,
hideOnCapture?: boolean, hideOnCapture?: boolean,
): void { ): void {
// Prevents creating multiple instances // Prevents creating multiple instances
@ -1280,12 +1281,12 @@ export class WindowHandler {
toolWidth = scaledImageDimensions.width; toolWidth = scaledImageDimensions.width;
} }
const selectedParentWindow = getWindowByName(windowName); this.currentWindow = currentWindow || '';
const opts: ICustomBrowserWindowConstructorOpts = this.getWindowOpts( const opts: ICustomBrowserWindowConstructorOpts = this.getWindowOpts(
{ {
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,
parent: selectedParentWindow, parent: getWindowByName(this.currentWindow),
modal: true, modal: true,
alwaysOnTop: hideOnCapture, alwaysOnTop: hideOnCapture,
resizable: false, resizable: false,
@ -1304,10 +1305,6 @@ export class WindowHandler {
opts.alwaysOnTop = true; opts.alwaysOnTop = true;
} }
if (this.mainWindow) {
opts.parent = this.mainWindow;
}
this.snippingToolWindow = createComponentWindow('snipping-tool', opts); this.snippingToolWindow = createComponentWindow('snipping-tool', opts);
this.moveWindow(this.snippingToolWindow); this.moveWindow(this.snippingToolWindow);
this.snippingToolWindow.setVisibleOnAllWorkspaces(true); this.snippingToolWindow.setVisibleOnAllWorkspaces(true);
@ -1368,15 +1365,20 @@ 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();
this.deleteFile(snipImage); this.deleteFile(snipImage);
this.removeWindow(opts.winKey); this.removeWindow(opts.winKey);
this.screenPickerWindow = null; this.screenPickerWindow = null;
if (this.hideOnCapture) {
const curWindow = getWindowByName(currentWindow || '');
const mainWindow = windowHandler.getMainWindow();
mainWindow?.focus();
if (currentWindow !== 'main') {
curWindow?.focus();
}
}
}); });
} }

View File

@ -142,7 +142,7 @@ body.using-mouse :focus {
background-color: @electricity-ui-40; background-color: @electricity-ui-40;
} }
.add-to-chat-button:focus { .add-to-chat-button:active {
background-color: @electricity-ui-60; background-color: @electricity-ui-60;
} }
@ -220,7 +220,7 @@ body.using-mouse :focus {
background: @electricity-ui-40; background: @electricity-ui-40;
} }
.menu-button:focus { .menu-button:active {
background: @electricity-ui-60; background: @electricity-ui-60;
} }