mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-29 20:24:10 -06:00
Merge pull request #1136 from psjostrom/master
fix: SDA-2747 Refactoring opening of snippet tool
This commit is contained in:
commit
6a275aee52
@ -106,9 +106,14 @@ class ScreenSnippet {
|
|||||||
try {
|
try {
|
||||||
await this.execCmd(this.captureUtil, this.captureUtilArgs);
|
await this.execCmd(this.captureUtil, this.captureUtilArgs);
|
||||||
if (windowHandler.isMana) {
|
if (windowHandler.isMana) {
|
||||||
windowHandler.closeSnippingToolWindow();
|
|
||||||
const dimensions = this.getImageSize();
|
const dimensions = this.getImageSize();
|
||||||
windowHandler.createSnippingToolWindow(this.outputFileName, dimensions);
|
const imageSize = { width: dimensions?.width || -1, height: dimensions?.height || -1 };
|
||||||
|
if (imageSize.width === -1 || imageSize.width === -1) {
|
||||||
|
logger.error('screen-snippet-handler: Could not get image size');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
windowHandler.closeSnippingToolWindow();
|
||||||
|
windowHandler.createSnippingToolWindow(this.outputFileName, imageSize);
|
||||||
this.uploadSnippet(webContents);
|
this.uploadSnippet(webContents);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -962,53 +962,62 @@ export class WindowHandler {
|
|||||||
*/
|
*/
|
||||||
public createSnippingToolWindow(
|
public createSnippingToolWindow(
|
||||||
snipImage: string,
|
snipImage: string,
|
||||||
dimensions?: {
|
snipDimensions: {
|
||||||
height: number | undefined;
|
height: number;
|
||||||
width: number | undefined;
|
width: number;
|
||||||
},
|
},
|
||||||
): void {
|
): void {
|
||||||
// Prevents creating multiple instances
|
|
||||||
if (didVerifyAndRestoreWindow(this.snippingToolWindow)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentWindow = BrowserWindow.getFocusedWindow();
|
const parentWindow = BrowserWindow.getFocusedWindow();
|
||||||
const MIN_HEIGHT = 312;
|
// Prevents creating multiple instances
|
||||||
const MIN_WIDTH = 320;
|
if (didVerifyAndRestoreWindow(this.snippingToolWindow) || !parentWindow) {
|
||||||
const CONTAINER_HEIGHT = 175;
|
return;
|
||||||
|
logger.error('window-handler: Could not open snipping tool window');
|
||||||
|
}
|
||||||
|
|
||||||
const OS_PADDING = 25;
|
const OS_PADDING = 25;
|
||||||
const snippetImageHeight = dimensions?.height || 0;
|
const MIN_TOOL_HEIGHT = 312;
|
||||||
const snippetImageWidth = dimensions?.width || 0;
|
const MIN_TOOL_WIDTH = 320;
|
||||||
let annotateAreaHeight = snippetImageHeight;
|
const BUTTON_BAR_TOP_HEIGHT = 48;
|
||||||
let annotateAreaWidth = snippetImageWidth;
|
const BUTTON_BAR_BOTTOM_HEIGHT = 72;
|
||||||
|
const BUTTON_BARS_HEIGHT = BUTTON_BAR_TOP_HEIGHT + BUTTON_BAR_BOTTOM_HEIGHT;
|
||||||
|
|
||||||
if (parentWindow) {
|
const display = electron.screen.getDisplayMatching(parentWindow.getBounds());
|
||||||
const { bounds: { height: sHeight, width: sWidth } } = electron.screen.getDisplayMatching(parentWindow.getBounds());
|
const workAreaSize = display.workAreaSize;
|
||||||
|
const maxToolHeight = Math.floor(calculatePercentage(workAreaSize.height, 90));
|
||||||
|
const maxToolWidth = Math.floor(calculatePercentage(workAreaSize.width, 90));
|
||||||
|
const availableAnnotateAreaHeight = maxToolHeight - BUTTON_BARS_HEIGHT;
|
||||||
|
const availableAnnotateAreaWidth = maxToolWidth;
|
||||||
|
|
||||||
// This calculation is to make sure the
|
const annotateAreaHeight = snipDimensions.height > availableAnnotateAreaHeight ?
|
||||||
// snippet window does not cover the entire screen
|
availableAnnotateAreaHeight :
|
||||||
const maxScreenHeight: number = calculatePercentage(sHeight, 90);
|
snipDimensions.height;
|
||||||
if (annotateAreaHeight > maxScreenHeight) {
|
const annotateAreaWidth = snipDimensions.width > availableAnnotateAreaWidth ?
|
||||||
annotateAreaHeight = maxScreenHeight;
|
availableAnnotateAreaWidth :
|
||||||
}
|
snipDimensions.width;
|
||||||
const maxScreenWidth: number = calculatePercentage(sWidth, 90);
|
|
||||||
if (annotateAreaWidth > maxScreenWidth) {
|
let toolHeight: number;
|
||||||
annotateAreaWidth = maxScreenWidth;
|
let toolWidth: number;
|
||||||
|
|
||||||
|
if (snipDimensions.height + BUTTON_BARS_HEIGHT >= maxToolHeight) {
|
||||||
|
toolHeight = maxToolHeight + OS_PADDING;
|
||||||
|
} else if (snipDimensions.height + BUTTON_BARS_HEIGHT <= MIN_TOOL_HEIGHT) {
|
||||||
|
toolHeight = MIN_TOOL_HEIGHT + OS_PADDING;
|
||||||
|
} else {
|
||||||
|
toolHeight = snipDimensions.height + BUTTON_BARS_HEIGHT + OS_PADDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrease image height when there is no space for the container window
|
if (snipDimensions.width >= maxToolWidth) {
|
||||||
if ((sHeight - annotateAreaHeight) < CONTAINER_HEIGHT) {
|
toolWidth = maxToolWidth;
|
||||||
annotateAreaHeight -= CONTAINER_HEIGHT;
|
} else if (snipDimensions.width <= MIN_TOOL_WIDTH) {
|
||||||
|
toolWidth = MIN_TOOL_WIDTH;
|
||||||
|
} else {
|
||||||
|
toolWidth = snipDimensions.width;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const windowHeight = annotateAreaHeight + CONTAINER_HEIGHT - OS_PADDING;
|
|
||||||
|
|
||||||
const opts: ICustomBrowserWindowConstructorOpts = this.getWindowOpts(
|
const opts: ICustomBrowserWindowConstructorOpts = this.getWindowOpts(
|
||||||
{
|
{
|
||||||
width: annotateAreaWidth < MIN_WIDTH ? MIN_WIDTH : annotateAreaWidth,
|
width: toolWidth,
|
||||||
height: windowHeight < MIN_HEIGHT ? MIN_HEIGHT : windowHeight,
|
height: toolHeight,
|
||||||
minHeight: MIN_HEIGHT,
|
|
||||||
minWidth: MIN_WIDTH,
|
|
||||||
modal: false,
|
modal: false,
|
||||||
alwaysOnTop: false,
|
alwaysOnTop: false,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
@ -1032,15 +1041,19 @@ export class WindowHandler {
|
|||||||
this.moveWindow(this.snippingToolWindow);
|
this.moveWindow(this.snippingToolWindow);
|
||||||
this.snippingToolWindow.setVisibleOnAllWorkspaces(true);
|
this.snippingToolWindow.setVisibleOnAllWorkspaces(true);
|
||||||
|
|
||||||
|
this.snippingToolWindow.webContents.openDevTools();
|
||||||
|
|
||||||
this.snippingToolWindow.webContents.once('did-finish-load', async () => {
|
this.snippingToolWindow.webContents.once('did-finish-load', async () => {
|
||||||
const snippingToolInfo = {
|
const snippingToolInfo = {
|
||||||
snipImage,
|
snipImage,
|
||||||
annotateAreaHeight,
|
annotateAreaHeight,
|
||||||
annotateAreaWidth,
|
annotateAreaWidth,
|
||||||
snippetImageHeight,
|
snippetImageHeight: snipDimensions.height,
|
||||||
snippetImageWidth,
|
snippetImageWidth: snipDimensions.width,
|
||||||
};
|
};
|
||||||
if (this.snippingToolWindow && windowExists(this.snippingToolWindow)) {
|
if (this.snippingToolWindow && windowExists(this.snippingToolWindow)) {
|
||||||
|
logger.info('window-handler: Opening snipping tool window with size: ', { toolHeight, toolWidth });
|
||||||
|
logger.info('window-handler: Opening snipping tool content with metadata: ', snippingToolInfo);
|
||||||
this.snippingToolWindow.webContents.send(
|
this.snippingToolWindow.webContents.send(
|
||||||
'snipping-tool-data',
|
'snipping-tool-data',
|
||||||
snippingToolInfo,
|
snippingToolInfo,
|
||||||
|
Loading…
Reference in New Issue
Block a user