diff --git a/src/main/windows/callsWidgetWindow.test.js b/src/main/windows/callsWidgetWindow.test.js index 179eb4615c1..402867462bc 100644 --- a/src/main/windows/callsWidgetWindow.test.js +++ b/src/main/windows/callsWidgetWindow.test.js @@ -153,6 +153,13 @@ describe('main/windows/callsWidgetWindow', () => { value: originalEnv, }); }); + + it('widget window visibility should have been toggled', async () => { + callsWidgetWindow.onShow(); + expect(callsWidgetWindow.win.setVisibleOnAllWorkspaces).toHaveBeenCalledWith(true, {skipTransformProcessType: true, visibleOnFullScreen: true}); + expect(callsWidgetWindow.win.setAlwaysOnTop).toHaveBeenCalledWith(true, 'screen-saver'); + expect(callsWidgetWindow.win.focus).toHaveBeenCalled(); + }); }); describe('close', () => { @@ -416,7 +423,22 @@ describe('main/windows/callsWidgetWindow', () => { }; const callsWidgetWindow = new CallsWidgetWindow(); + callsWidgetWindow.win = { + setVisibleOnAllWorkspaces: jest.fn(), + setAlwaysOnTop: jest.fn(), + focus: jest.fn(), + }; + + expect(callsWidgetWindow.win.setVisibleOnAllWorkspaces).not.toHaveBeenCalled(); + expect(callsWidgetWindow.win.setAlwaysOnTop).not.toHaveBeenCalled(); + callsWidgetWindow.onPopOutCreate(popOut); + + // Verify widget visibility has been toggled + expect(callsWidgetWindow.win.setVisibleOnAllWorkspaces).toHaveBeenCalledWith(false); + expect(callsWidgetWindow.win.setAlwaysOnTop).toHaveBeenCalledWith(false); + expect(callsWidgetWindow.win.focus).not.toHaveBeenCalled(); + expect(callsWidgetWindow.popOut).toBe(popOut); expect(WebContentsEventManager.addWebContentsEventListeners).toHaveBeenCalledWith(popOut.webContents); expect(redirectListener).toBeDefined(); @@ -433,6 +455,11 @@ describe('main/windows/callsWidgetWindow', () => { closedListener(); expect(callsWidgetWindow.popOut).not.toBeDefined(); expect(mockContextMenuDispose).toHaveBeenCalled(); + + // Verify widget visibility has been toggled + expect(callsWidgetWindow.win.setVisibleOnAllWorkspaces).toHaveBeenCalledWith(true, {skipTransformProcessType: true, visibleOnFullScreen: true}); + expect(callsWidgetWindow.win.setAlwaysOnTop).toHaveBeenCalledWith(true, 'screen-saver'); + expect(callsWidgetWindow.win.focus).toHaveBeenCalled(); }); it('getViewURL', () => { diff --git a/src/main/windows/callsWidgetWindow.ts b/src/main/windows/callsWidgetWindow.ts index 37f04361720..fcb1952aff2 100644 --- a/src/main/windows/callsWidgetWindow.ts +++ b/src/main/windows/callsWidgetWindow.ts @@ -233,6 +233,23 @@ export class CallsWidgetWindow { ev.preventDefault(); }; + private setWidgetWindowStacking = ({onTop}: {onTop: boolean}) => { + log.debug('setWidgetWindowStacking', onTop); + + if (!this.win) { + return; + } + + if (onTop) { + this.win.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true, skipTransformProcessType: true}); + this.win.setAlwaysOnTop(true, 'screen-saver'); + this.win.focus(); + } else { + this.win.setAlwaysOnTop(false); + this.win.setVisibleOnAllWorkspaces(false); + } + }; + private onShow = () => { log.debug('onShow'); const mainWindow = MainWindow.get(); @@ -240,9 +257,7 @@ export class CallsWidgetWindow { return; } - this.win.focus(); - this.win.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true, skipTransformProcessType: true}); - this.win.setAlwaysOnTop(true, 'screen-saver'); + this.setWidgetWindowStacking({onTop: true}); const bounds = this.win.getBounds(); const mainBounds = mainWindow.getBounds(); @@ -288,6 +303,8 @@ export class CallsWidgetWindow { private onPopOutCreate = (win: BrowserWindow) => { this.popOut = win; + this.setWidgetWindowStacking({onTop: false}); + // Let the webContentsEventManager handle links that try to open a new window. webContentsEventManager.addWebContentsEventListeners(this.popOut.webContents); @@ -304,6 +321,7 @@ export class CallsWidgetWindow { this.popOut.on('closed', () => { delete this.popOut; contextMenu.dispose(); + this.setWidgetWindowStacking({onTop: true}); }); // Set the userAgent so that the widget's popout is considered a desktop window in the webapp code.