[MM-49739] Set parent window on calls expanded popout view (#2539)
* Set parent window on calls expanded popout view * Fix focus on calls popout window * Unregister event
This commit is contained in:
parent
97a31fc83b
commit
9213083335
|
@ -143,6 +143,7 @@ export const CALLS_WIDGET_RESIZE = 'calls-widget-resize';
|
||||||
export const CALLS_WIDGET_SHARE_SCREEN = 'calls-widget-share-screen';
|
export const CALLS_WIDGET_SHARE_SCREEN = 'calls-widget-share-screen';
|
||||||
export const CALLS_WIDGET_CHANNEL_LINK_CLICK = 'calls-widget-channel-link-click';
|
export const CALLS_WIDGET_CHANNEL_LINK_CLICK = 'calls-widget-channel-link-click';
|
||||||
export const CALLS_JOINED_CALL = 'calls-joined-call';
|
export const CALLS_JOINED_CALL = 'calls-joined-call';
|
||||||
|
export const CALLS_POPOUT_FOCUS = 'calls-popout-focus';
|
||||||
|
|
||||||
export const REQUEST_CLEAR_DOWNLOADS_DROPDOWN = 'request-clear-downloads-dropdown';
|
export const REQUEST_CLEAR_DOWNLOADS_DROPDOWN = 'request-clear-downloads-dropdown';
|
||||||
export const CLOSE_DOWNLOADS_DROPDOWN = 'close-downloads-dropdown';
|
export const CLOSE_DOWNLOADS_DROPDOWN = 'close-downloads-dropdown';
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {ipcRenderer} from 'electron';
|
||||||
import {
|
import {
|
||||||
CALLS_LEAVE_CALL,
|
CALLS_LEAVE_CALL,
|
||||||
CALLS_JOINED_CALL,
|
CALLS_JOINED_CALL,
|
||||||
|
CALLS_POPOUT_FOCUS,
|
||||||
CALLS_WIDGET_RESIZE,
|
CALLS_WIDGET_RESIZE,
|
||||||
CALLS_WIDGET_SHARE_SCREEN,
|
CALLS_WIDGET_SHARE_SCREEN,
|
||||||
CALLS_WIDGET_CHANNEL_LINK_CLICK,
|
CALLS_WIDGET_CHANNEL_LINK_CLICK,
|
||||||
|
@ -47,6 +48,7 @@ window.addEventListener('message', ({origin, data = {}} = {}) => {
|
||||||
case CALLS_WIDGET_CHANNEL_LINK_CLICK:
|
case CALLS_WIDGET_CHANNEL_LINK_CLICK:
|
||||||
case CALLS_WIDGET_RESIZE:
|
case CALLS_WIDGET_RESIZE:
|
||||||
case CALLS_JOINED_CALL:
|
case CALLS_JOINED_CALL:
|
||||||
|
case CALLS_POPOUT_FOCUS:
|
||||||
case CALLS_LEAVE_CALL: {
|
case CALLS_LEAVE_CALL: {
|
||||||
ipcRenderer.send(type, message);
|
ipcRenderer.send(type, message);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -53,6 +53,7 @@ describe('main/windows/callsWidgetWindow', () => {
|
||||||
baseWindow.setBounds = jest.fn();
|
baseWindow.setBounds = jest.fn();
|
||||||
baseWindow.webContents = {
|
baseWindow.webContents = {
|
||||||
setWindowOpenHandler: jest.fn(),
|
setWindowOpenHandler: jest.fn(),
|
||||||
|
on: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -288,5 +289,46 @@ describe('main/windows/callsWidgetWindow', () => {
|
||||||
widgetWindow.onJoinedCall(null, message);
|
widgetWindow.onJoinedCall(null, message);
|
||||||
expect(widgetWindow.mainView.view.webContents.send).toHaveBeenCalledWith(CALLS_JOINED_CALL, message);
|
expect(widgetWindow.mainView.view.webContents.send).toHaveBeenCalledWith(CALLS_JOINED_CALL, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('menubar disabled on popout', () => {
|
||||||
|
const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig);
|
||||||
|
expect(widgetWindow.onPopOutOpen()).toHaveProperty('action', 'allow');
|
||||||
|
expect(widgetWindow.onPopOutOpen().overrideBrowserWindowOptions).toHaveProperty('autoHideMenuBar', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('onPopOutFocus', () => {
|
||||||
|
baseWindow.webContents = {
|
||||||
|
...baseWindow.webContents,
|
||||||
|
send: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let isMinimized = false;
|
||||||
|
baseWindow.restore = jest.fn();
|
||||||
|
baseWindow.isMinimized = jest.fn(() => isMinimized);
|
||||||
|
|
||||||
|
const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig);
|
||||||
|
|
||||||
|
expect(baseWindow.webContents.setWindowOpenHandler).toHaveBeenCalledWith(widgetWindow.onPopOutOpen);
|
||||||
|
expect(baseWindow.webContents.on).toHaveBeenCalledWith('did-create-window', widgetWindow.onPopOutCreate);
|
||||||
|
|
||||||
|
expect(widgetWindow.popOut).toBeNull();
|
||||||
|
|
||||||
|
const popOut = new BrowserWindow();
|
||||||
|
widgetWindow.onPopOutFocus();
|
||||||
|
expect(popOut.focus).not.toHaveBeenCalled();
|
||||||
|
expect(popOut.restore).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
widgetWindow.onPopOutCreate(popOut);
|
||||||
|
expect(widgetWindow.popOut).toBe(popOut);
|
||||||
|
|
||||||
|
widgetWindow.onPopOutFocus();
|
||||||
|
expect(popOut.focus).toHaveBeenCalled();
|
||||||
|
expect(popOut.restore).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
isMinimized = true;
|
||||||
|
widgetWindow.onPopOutFocus();
|
||||||
|
expect(popOut.focus).toHaveBeenCalled();
|
||||||
|
expect(popOut.restore).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,9 +25,10 @@ import {
|
||||||
} from 'common/utils/constants';
|
} from 'common/utils/constants';
|
||||||
import Utils from 'common/utils/util';
|
import Utils from 'common/utils/util';
|
||||||
import {
|
import {
|
||||||
|
CALLS_JOINED_CALL,
|
||||||
|
CALLS_POPOUT_FOCUS,
|
||||||
CALLS_WIDGET_RESIZE,
|
CALLS_WIDGET_RESIZE,
|
||||||
CALLS_WIDGET_SHARE_SCREEN,
|
CALLS_WIDGET_SHARE_SCREEN,
|
||||||
CALLS_JOINED_CALL,
|
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
|
|
||||||
type LoadURLOpts = {
|
type LoadURLOpts = {
|
||||||
|
@ -37,6 +38,7 @@ type LoadURLOpts = {
|
||||||
export default class CallsWidgetWindow extends EventEmitter {
|
export default class CallsWidgetWindow extends EventEmitter {
|
||||||
public win: BrowserWindow;
|
public win: BrowserWindow;
|
||||||
private main: BrowserWindow;
|
private main: BrowserWindow;
|
||||||
|
private popOut: BrowserWindow | null = null;
|
||||||
private mainView: MattermostView;
|
private mainView: MattermostView;
|
||||||
private config: CallsWidgetWindowConfig;
|
private config: CallsWidgetWindowConfig;
|
||||||
private boundsErr: Rectangle = {
|
private boundsErr: Rectangle = {
|
||||||
|
@ -81,15 +83,10 @@ export default class CallsWidgetWindow extends EventEmitter {
|
||||||
ipcMain.on(CALLS_WIDGET_RESIZE, this.onResize);
|
ipcMain.on(CALLS_WIDGET_RESIZE, this.onResize);
|
||||||
ipcMain.on(CALLS_WIDGET_SHARE_SCREEN, this.onShareScreen);
|
ipcMain.on(CALLS_WIDGET_SHARE_SCREEN, this.onShareScreen);
|
||||||
ipcMain.on(CALLS_JOINED_CALL, this.onJoinedCall);
|
ipcMain.on(CALLS_JOINED_CALL, this.onJoinedCall);
|
||||||
|
ipcMain.on(CALLS_POPOUT_FOCUS, this.onPopOutFocus);
|
||||||
|
|
||||||
this.win.webContents.setWindowOpenHandler(() => {
|
this.win.webContents.setWindowOpenHandler(this.onPopOutOpen);
|
||||||
return {
|
this.win.webContents.on('did-create-window', this.onPopOutCreate);
|
||||||
action: 'allow',
|
|
||||||
overrideBrowserWindowOptions: {
|
|
||||||
autoHideMenuBar: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
@ -125,6 +122,7 @@ export default class CallsWidgetWindow extends EventEmitter {
|
||||||
ipcMain.off(CALLS_WIDGET_RESIZE, this.onResize);
|
ipcMain.off(CALLS_WIDGET_RESIZE, this.onResize);
|
||||||
ipcMain.off(CALLS_WIDGET_SHARE_SCREEN, this.onShareScreen);
|
ipcMain.off(CALLS_WIDGET_SHARE_SCREEN, this.onShareScreen);
|
||||||
ipcMain.off(CALLS_JOINED_CALL, this.onJoinedCall);
|
ipcMain.off(CALLS_JOINED_CALL, this.onJoinedCall);
|
||||||
|
ipcMain.off(CALLS_POPOUT_FOCUS, this.onPopOutFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWidgetURL() {
|
private getWidgetURL() {
|
||||||
|
@ -218,5 +216,28 @@ export default class CallsWidgetWindow extends EventEmitter {
|
||||||
|
|
||||||
this.setBounds(initialBounds);
|
this.setBounds(initialBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onPopOutOpen = () => {
|
||||||
|
return {
|
||||||
|
action: 'allow' as const,
|
||||||
|
overrideBrowserWindowOptions: {
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private onPopOutCreate = (win: BrowserWindow) => {
|
||||||
|
this.popOut = win;
|
||||||
|
}
|
||||||
|
|
||||||
|
private onPopOutFocus = () => {
|
||||||
|
if (!this.popOut) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.popOut.isMinimized()) {
|
||||||
|
this.popOut.restore();
|
||||||
|
}
|
||||||
|
this.popOut.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue