[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

@@ -91,8 +91,6 @@ describe('main/windows/callsWidgetWindow', () => {
expect(BrowserWindow).toHaveBeenCalledWith(expect.objectContaining({
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT,
minWidth: MINIMUM_CALLS_WIDGET_WIDTH,
minHeight: MINIMUM_CALLS_WIDGET_HEIGHT,
fullscreen: false,
resizable: false,
frame: false,
@@ -181,57 +179,87 @@ describe('main/windows/callsWidgetWindow', () => {
winBounds = bounds;
});
baseWindow.webContents.getZoomFactor = jest.fn(() => 1.0);
const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig);
widgetWindow.win.emit('ready-to-show');
expect(baseWindow.setBounds).toHaveBeenCalledTimes(2);
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 720 - MINIMUM_CALLS_WIDGET_HEIGHT - 12,
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT,
});
widgetWindow.onResize(null, {
element: 'calls-widget-menu',
element: 'calls-widget',
width: 300,
height: 100,
});
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 518,
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT + 100,
y: 720 - 100 - 12,
width: 300,
height: 100,
});
});
it('zoom', () => {
baseWindow.show = jest.fn(() => {
baseWindow.emit('show');
});
widgetWindow.onResize(null, {
element: 'calls-widget-audio-menu',
width: 100,
});
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 518,
width: MINIMUM_CALLS_WIDGET_WIDTH + 100,
height: MINIMUM_CALLS_WIDGET_HEIGHT + 100,
});
widgetWindow.onResize(null, {
element: 'calls-widget-audio-menu',
width: 0,
});
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 518,
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT + 100,
});
widgetWindow.onResize(null, {
element: 'calls-widget-menu',
height: 0,
});
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 618,
let winBounds = {
x: 0,
y: 0,
width: MINIMUM_CALLS_WIDGET_WIDTH,
height: MINIMUM_CALLS_WIDGET_HEIGHT,
};
baseWindow.getBounds = jest.fn(() => {
return winBounds;
});
baseWindow.setBounds = jest.fn((bounds) => {
winBounds = bounds;
});
baseWindow.webContents.getZoomFactor = jest.fn(() => 1.0);
const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig);
widgetWindow.win.emit('ready-to-show');
expect(baseWindow.setBounds).toHaveBeenCalledTimes(1);
expect(baseWindow.webContents.getZoomFactor).toHaveBeenCalledTimes(0);
baseWindow.webContents.getZoomFactor = jest.fn(() => 2.0);
widgetWindow.onResize(null, {
element: 'calls-widget',
width: 300,
height: 100,
});
expect(baseWindow.webContents.getZoomFactor).toHaveBeenCalledTimes(1);
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 720 - 200 - 12,
width: 600,
height: 200,
});
baseWindow.webContents.getZoomFactor = jest.fn(() => 0.5);
widgetWindow.onResize(null, {
element: 'calls-widget',
width: 300,
height: 100,
});
expect(baseWindow.webContents.getZoomFactor).toHaveBeenCalledTimes(1);
expect(baseWindow.setBounds).toHaveBeenCalledWith({
x: 12,
y: 720 - 50 - 12,
width: 150,
height: 50,
});
});

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) => {