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,12 +106,17 @@ 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;
|
||||||
}
|
}
|
||||||
const {
|
const {
|
||||||
message,
|
message,
|
||||||
data,
|
data,
|
||||||
|
@ -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;
|
||||||
const OS_PADDING = 25;
|
logger.error('window-handler: Could not open snipping tool window');
|
||||||
const snippetImageHeight = dimensions?.height || 0;
|
}
|
||||||
const snippetImageWidth = dimensions?.width || 0;
|
|
||||||
let annotateAreaHeight = snippetImageHeight;
|
const OS_PADDING = 25;
|
||||||
let annotateAreaWidth = snippetImageWidth;
|
const MIN_TOOL_HEIGHT = 312;
|
||||||
|
const MIN_TOOL_WIDTH = 320;
|
||||||
if (parentWindow) {
|
const BUTTON_BAR_TOP_HEIGHT = 48;
|
||||||
const { bounds: { height: sHeight, width: sWidth } } = electron.screen.getDisplayMatching(parentWindow.getBounds());
|
const BUTTON_BAR_BOTTOM_HEIGHT = 72;
|
||||||
|
const BUTTON_BARS_HEIGHT = BUTTON_BAR_TOP_HEIGHT + BUTTON_BAR_BOTTOM_HEIGHT;
|
||||||
// This calculation is to make sure the
|
|
||||||
// snippet window does not cover the entire screen
|
const display = electron.screen.getDisplayMatching(parentWindow.getBounds());
|
||||||
const maxScreenHeight: number = calculatePercentage(sHeight, 90);
|
const workAreaSize = display.workAreaSize;
|
||||||
if (annotateAreaHeight > maxScreenHeight) {
|
const maxToolHeight = Math.floor(calculatePercentage(workAreaSize.height, 90));
|
||||||
annotateAreaHeight = maxScreenHeight;
|
const maxToolWidth = Math.floor(calculatePercentage(workAreaSize.width, 90));
|
||||||
}
|
const availableAnnotateAreaHeight = maxToolHeight - BUTTON_BARS_HEIGHT;
|
||||||
const maxScreenWidth: number = calculatePercentage(sWidth, 90);
|
const availableAnnotateAreaWidth = maxToolWidth;
|
||||||
if (annotateAreaWidth > maxScreenWidth) {
|
|
||||||
annotateAreaWidth = maxScreenWidth;
|
const annotateAreaHeight = snipDimensions.height > availableAnnotateAreaHeight ?
|
||||||
}
|
availableAnnotateAreaHeight :
|
||||||
|
snipDimensions.height;
|
||||||
// decrease image height when there is no space for the container window
|
const annotateAreaWidth = snipDimensions.width > availableAnnotateAreaWidth ?
|
||||||
if ((sHeight - annotateAreaHeight) < CONTAINER_HEIGHT) {
|
availableAnnotateAreaWidth :
|
||||||
annotateAreaHeight -= CONTAINER_HEIGHT;
|
snipDimensions.width;
|
||||||
}
|
|
||||||
|
let toolHeight: number;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snipDimensions.width >= maxToolWidth) {
|
||||||
|
toolWidth = maxToolWidth;
|
||||||
|
} 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