mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 17:31:36 -06:00
SDA-3976: Add few bugs fixed
This commit is contained in:
parent
921fd5eeea
commit
f5bca5f4fa
@ -398,23 +398,33 @@ describe('main api handler', () => {
|
||||
|
||||
it('should call `openScreenSnippet` correctly', () => {
|
||||
const spy = jest.spyOn(screenSnippet, 'capture');
|
||||
jest.spyOn(BrowserWindow, 'getFocusedWindow').mockImplementation(() => {
|
||||
return {
|
||||
winName: 'main',
|
||||
};
|
||||
});
|
||||
const value = {
|
||||
cmd: apiCmds.openScreenSnippet,
|
||||
};
|
||||
const expectedValue = { send: expect.any(Function) };
|
||||
ipcMain.send(apiName.symphonyApi, value);
|
||||
expect(spy).toBeCalledWith(expectedValue, undefined);
|
||||
expect(spy).toBeCalledWith(expectedValue, 'main', undefined);
|
||||
});
|
||||
|
||||
it('should call `openScreenSnippet` with hideOnCapture correctly', () => {
|
||||
const spy = jest.spyOn(screenSnippet, 'capture');
|
||||
jest.spyOn(BrowserWindow, 'getFocusedWindow').mockImplementation(() => {
|
||||
return {
|
||||
winName: 'main',
|
||||
};
|
||||
});
|
||||
const value = {
|
||||
cmd: apiCmds.openScreenSnippet,
|
||||
hideOnCapture: true,
|
||||
};
|
||||
const expectedValue = { send: expect.any(Function) };
|
||||
ipcMain.send(apiName.symphonyApi, value);
|
||||
expect(spy).toBeCalledWith(expectedValue, true);
|
||||
expect(spy).toBeCalledWith(expectedValue, 'main', true);
|
||||
});
|
||||
|
||||
it('should call `closeWindow` correctly', () => {
|
||||
|
@ -91,6 +91,7 @@ ipcMain.on(
|
||||
return;
|
||||
}
|
||||
const mainWebContents = windowHandler.getMainWebContents();
|
||||
const currentWindow = BrowserWindow.getFocusedWindow();
|
||||
logApiCallParams(arg);
|
||||
switch (arg.cmd) {
|
||||
case apiCmds.isOnline:
|
||||
@ -203,7 +204,11 @@ ipcMain.on(
|
||||
}
|
||||
break;
|
||||
case apiCmds.openScreenSnippet:
|
||||
screenSnippet.capture(event.sender, arg.hideOnCapture);
|
||||
screenSnippet.capture(
|
||||
event.sender,
|
||||
(currentWindow as ICustomBrowserWindow)?.winName,
|
||||
arg.hideOnCapture,
|
||||
);
|
||||
break;
|
||||
case apiCmds.closeScreenSnippet:
|
||||
screenSnippet.cancelCapture();
|
||||
|
@ -30,8 +30,8 @@ import {
|
||||
ScreenSnippetActionTypes,
|
||||
} from './analytics-handler';
|
||||
import { updateAlwaysOnTop } from './window-actions';
|
||||
import { ICustomBrowserWindow, windowHandler } from './window-handler';
|
||||
import { windowExists } from './window-utils';
|
||||
import { windowHandler } from './window-handler';
|
||||
import { getWindowByName, windowExists } from './window-utils';
|
||||
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
|
||||
@ -87,10 +87,19 @@ class ScreenSnippet {
|
||||
*
|
||||
* @param webContents {WeContents}
|
||||
*/
|
||||
public async capture(webContents: WebContents, hideOnCapture?: boolean) {
|
||||
public async capture(
|
||||
webContents: WebContents,
|
||||
currentWindow?: string,
|
||||
hideOnCapture?: boolean,
|
||||
) {
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
if (hideOnCapture) {
|
||||
const curWindow = getWindowByName(currentWindow || '');
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
mainWindow?.minimize();
|
||||
if (currentWindow !== 'main') {
|
||||
curWindow?.minimize();
|
||||
}
|
||||
}
|
||||
|
||||
if (mainWindow && windowExists(mainWindow) && isWindowsOS) {
|
||||
@ -175,16 +184,13 @@ class ScreenSnippet {
|
||||
}
|
||||
|
||||
windowHandler.closeSnippingToolWindow();
|
||||
const windowName = this.focusedWindow
|
||||
? (this.focusedWindow as ICustomBrowserWindow).winName
|
||||
: '';
|
||||
windowHandler.createSnippingToolWindow(
|
||||
this.outputFilePath,
|
||||
dimensions,
|
||||
windowName,
|
||||
currentWindow,
|
||||
hideOnCapture,
|
||||
);
|
||||
this.uploadSnippet(webContents, mainWindow);
|
||||
this.uploadSnippet(webContents, currentWindow, hideOnCapture);
|
||||
this.closeSnippet();
|
||||
this.copyToClipboard();
|
||||
this.saveAs();
|
||||
@ -340,7 +346,8 @@ class ScreenSnippet {
|
||||
*/
|
||||
private uploadSnippet(
|
||||
webContents: WebContents,
|
||||
mainWindow: ICustomBrowserWindow | null,
|
||||
currentWindow?: string,
|
||||
hideOnCapture?: boolean,
|
||||
) {
|
||||
ipcMain.once(
|
||||
'upload-snippet',
|
||||
@ -360,7 +367,14 @@ class ScreenSnippet {
|
||||
'screen-snippet-handler: Snippet uploaded correctly, sending payload to SFE',
|
||||
);
|
||||
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();
|
||||
} catch (error) {
|
||||
await this.verifyAndUpdateAlwaysOnTop();
|
||||
@ -437,7 +451,7 @@ class ScreenSnippet {
|
||||
},
|
||||
) => {
|
||||
const filePath = path.join(
|
||||
this.tempDir,
|
||||
app.getPath('downloads'),
|
||||
'symphonyImage-' + Date.now() + '.png',
|
||||
);
|
||||
const [, data] = saveAsData.clipboard.split(',');
|
||||
|
@ -167,6 +167,7 @@ export class WindowHandler {
|
||||
private finishedLoading: boolean = false;
|
||||
private readonly opts: Electron.BrowserViewConstructorOptions | undefined;
|
||||
private hideOnCapture: boolean = false;
|
||||
private currentWindow?: string = undefined;
|
||||
|
||||
constructor(opts?: Electron.BrowserViewConstructorOptions) {
|
||||
this.opts = opts;
|
||||
@ -1193,7 +1194,7 @@ export class WindowHandler {
|
||||
height: number;
|
||||
width: number;
|
||||
},
|
||||
windowName: string,
|
||||
currentWindow?: string,
|
||||
hideOnCapture?: boolean,
|
||||
): void {
|
||||
// Prevents creating multiple instances
|
||||
@ -1280,12 +1281,12 @@ export class WindowHandler {
|
||||
toolWidth = scaledImageDimensions.width;
|
||||
}
|
||||
|
||||
const selectedParentWindow = getWindowByName(windowName);
|
||||
this.currentWindow = currentWindow || '';
|
||||
const opts: ICustomBrowserWindowConstructorOpts = this.getWindowOpts(
|
||||
{
|
||||
width: toolWidth,
|
||||
height: toolHeight,
|
||||
parent: selectedParentWindow,
|
||||
parent: getWindowByName(this.currentWindow),
|
||||
modal: true,
|
||||
alwaysOnTop: hideOnCapture,
|
||||
resizable: false,
|
||||
@ -1304,10 +1305,6 @@ export class WindowHandler {
|
||||
opts.alwaysOnTop = true;
|
||||
}
|
||||
|
||||
if (this.mainWindow) {
|
||||
opts.parent = this.mainWindow;
|
||||
}
|
||||
|
||||
this.snippingToolWindow = createComponentWindow('snipping-tool', opts);
|
||||
this.moveWindow(this.snippingToolWindow);
|
||||
this.snippingToolWindow.setVisibleOnAllWorkspaces(true);
|
||||
@ -1368,15 +1365,20 @@ 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();
|
||||
this.deleteFile(snipImage);
|
||||
this.removeWindow(opts.winKey);
|
||||
this.screenPickerWindow = null;
|
||||
if (this.hideOnCapture) {
|
||||
const curWindow = getWindowByName(currentWindow || '');
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
mainWindow?.focus();
|
||||
if (currentWindow !== 'main') {
|
||||
curWindow?.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ body.using-mouse :focus {
|
||||
background-color: @electricity-ui-40;
|
||||
}
|
||||
|
||||
.add-to-chat-button:focus {
|
||||
.add-to-chat-button:active {
|
||||
background-color: @electricity-ui-60;
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ body.using-mouse :focus {
|
||||
background: @electricity-ui-40;
|
||||
}
|
||||
|
||||
.menu-button:focus {
|
||||
.menu-button:active {
|
||||
background: @electricity-ui-60;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user