[MM-48658] Improve global widget resizing logic (#2545)

* Improved global widget resizing

* Remove min width/height

* Fix test
This commit is contained in:
Claudio Costa
2023-02-07 10:00:42 -06:00
committed by GitHub
parent 07e41ec678
commit 06eb76dc21
2 changed files with 75 additions and 76 deletions

View File

@@ -47,11 +47,6 @@ export default class CallsWidgetWindow extends EventEmitter {
width: 0,
height: 0,
};
private offsetsMap = {
'calls-widget-menu': {
height: 0,
},
};
constructor(mainWindow: BrowserWindow, mainView: MattermostView, config: CallsWidgetWindowConfig) {
super();
@@ -62,8 +57,6 @@ export default class CallsWidgetWindow extends EventEmitter {
this.win = new BrowserWindow({
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT,
minWidth: MINIMUM_CALLS_WIDGET_WIDTH,
minHeight: MINIMUM_CALLS_WIDGET_HEIGHT,
title: 'Calls Widget',
fullscreen: false,
resizable: false,
@@ -137,40 +130,18 @@ export default class CallsWidgetWindow extends EventEmitter {
}
private onResize = (event: IpcMainEvent, msg: CallsWidgetResizeMessage) => {
log.debug('CallsWidgetWindow.onResize');
log.debug('CallsWidgetWindow.onResize', msg);
const zoomFactor = this.win.webContents.getZoomFactor();
const currBounds = this.win.getBounds();
const newBounds = {
x: currBounds.x,
y: currBounds.y - (Math.ceil(msg.height * zoomFactor) - currBounds.height),
width: Math.ceil(msg.width * zoomFactor),
height: Math.ceil(msg.height * zoomFactor),
};
switch (msg.element) {
case 'calls-widget-audio-menu': {
const newBounds = {
x: currBounds.x,
y: currBounds.y,
width: msg.width > 0 ? currBounds.width + msg.width : MINIMUM_CALLS_WIDGET_WIDTH,
height: currBounds.height,
};
this.setBounds(newBounds);
break;
}
case 'calls-widget-menu': {
const hOff = this.offsetsMap[msg.element].height;
const newBounds = {
x: currBounds.x,
y: msg.height === 0 ? currBounds.y + hOff : currBounds.y - (msg.height - hOff),
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT + msg.height,
};
this.setBounds(newBounds);
this.offsetsMap[msg.element].height = msg.height;
break;
}
}
this.setBounds(newBounds);
}
private onShareScreen = (ev: IpcMainEvent, viewName: string, message: CallsWidgetShareScreenMessage) => {