Skip to content

Commit 658af3d

Browse files
SDA-4847 - add generic listener for enter-full-screen & async leave-full-screen (#2338)
* SDA-4847 - add generic listener for enter-full-screen & async leave-full-screen * SDA-4847 - Fix uts * SDA-4847 - Fix uts on windows * SDA-4847 - Rebase
1 parent dfdc370 commit 658af3d

5 files changed

+75
-36
lines changed

spec/miniViewHandler.spec.ts

+34-19
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('MiniViewHandler', () => {
5353
unmaximize: jest.fn(),
5454
setSize: jest.fn(),
5555
setAlwaysOnTop: jest.fn(),
56+
once: jest.fn(),
5657
};
5758

5859
mockMainWebContents = {
@@ -73,12 +74,12 @@ describe('MiniViewHandler', () => {
7374
});
7475

7576
describe('activateMiniView', () => {
76-
it('should set correct bounds when mainWinPosInMiniView exists', () => {
77+
it('should set correct bounds when mainWinPosInMiniView exists', async () => {
7778
(config.getUserConfigFields as jest.Mock).mockReturnValue({
7879
mainWinPosInMiniView: { x: 10, y: 20, width: 500, height: 400 },
7980
});
8081

81-
miniViewHandler.activateMiniView();
82+
await miniViewHandler.activateMiniView();
8283

8384
expect(mockMainWindow.setBounds).toHaveBeenCalledWith({
8485
x: 10,
@@ -88,11 +89,11 @@ describe('MiniViewHandler', () => {
8889
});
8990
});
9091

91-
it('should set default width and preserve height when mainWinPosInMiniView does not exist or has width > DEFAULT_MINI_VIEW_WINDOW_WIDTH', () => {
92+
it('should set default width and preserve height when mainWinPosInMiniView does not exist or has width > DEFAULT_MINI_VIEW_WINDOW_WIDTH', async () => {
9293
(config.getUserConfigFields as jest.Mock).mockReturnValue({
9394
mainWinPosInMiniView: { x: 10, y: 20, width: 700, height: 400 },
9495
});
95-
miniViewHandler.activateMiniView();
96+
await miniViewHandler.activateMiniView();
9697

9798
expect(mockMainWindow.setSize).toHaveBeenCalledWith(
9899
DEFAULT_MINI_VIEW_WINDOW_WIDTH,
@@ -102,32 +103,46 @@ describe('MiniViewHandler', () => {
102103

103104
it('should call setIsMiniViewTransition and notifyClient with true', (done) => {
104105
jest.useFakeTimers();
105-
miniViewHandler.activateMiniView();
106-
106+
miniViewHandler.activateMiniView().then(() => {
107+
expect(windowHandler.setIsMiniViewTransition).toHaveBeenLastCalledWith(
108+
false,
109+
);
110+
expect(mockMainWebContents.send).toHaveBeenCalledWith(
111+
'set-mini-view',
112+
true,
113+
);
114+
done();
115+
});
107116
expect(windowHandler.setIsMiniViewTransition).toHaveBeenLastCalledWith(
108117
true,
109118
);
110-
111119
jest.runAllTimers();
112-
expect(windowHandler.setIsMiniViewTransition).toHaveBeenLastCalledWith(
113-
false,
114-
);
115-
expect(mockMainWebContents.send).toHaveBeenCalledWith(
116-
'set-mini-view',
117-
true,
118-
);
119-
done();
120120
});
121121

122-
it('should set fullscreen to false if currently is in fullscreen', () => {
122+
it('should set fullscreen to false if currently is in fullscreen', async () => {
123+
jest.useFakeTimers();
123124
(mockMainWindow.isFullScreen as jest.Mock).mockReturnValue(true);
124-
miniViewHandler.activateMiniView();
125+
(mockMainWindow.once as jest.Mock).mockImplementation(
126+
(event, callback) => {
127+
if (event === 'leave-full-screen') {
128+
callback();
129+
jest.runAllTimers();
130+
}
131+
},
132+
);
133+
await miniViewHandler.activateMiniView();
125134
expect(mockMainWindow.setFullScreen).toHaveBeenCalledWith(false);
135+
expect(mockMainWindow.once).toHaveBeenCalledWith(
136+
'leave-full-screen',
137+
expect.any(Function),
138+
);
126139
});
127140

128-
it('should call unmaximize if currently is maximized', () => {
141+
it('should call unmaximize if currently is maximized', async () => {
142+
jest.useFakeTimers();
129143
(mockMainWindow.isMaximized as jest.Mock).mockReturnValue(true);
130-
miniViewHandler.activateMiniView();
144+
await miniViewHandler.activateMiniView();
145+
jest.runAllTimers();
131146
expect(mockMainWindow.unmaximize).toHaveBeenCalled();
132147
expect(mainEvents.publish).toHaveBeenCalledWith('unmaximize');
133148
});

src/app/main-api-handler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ import { getCommandLineArgs } from '../common/utils';
6363
import callNotificationHelper from '../renderer/call-notification-helper';
6464
import { autoUpdate, AutoUpdateTrigger } from './auto-update-handler';
6565
import { SDAUserSessionActionTypes } from './bi/interface';
66-
import { miniViewHandler } from './mini-view-handler';
6766
import { displayMediaRequestHandler } from './display-media-request-handler';
67+
import { miniViewHandler } from './mini-view-handler';
6868
import { openfinHandler } from './openfin-handler';
6969
import { presenceStatus } from './presence-status-handler';
7070
import { appStats } from './stats';
@@ -399,7 +399,7 @@ ipcMain.on(
399399
(win) =>
400400
(win as ICustomBrowserWindow).winName &&
401401
(win as ICustomBrowserWindow).winName ===
402-
apiName.notificationWindowName,
402+
apiName.notificationWindowName,
403403
);
404404
notificationWindows.map((notificationWindow) => {
405405
const notificationWebContents = notificationWindow?.webContents;
@@ -468,8 +468,8 @@ ipcMain.on(
468468
const podUrl = urlFromCmd
469469
? urlFromCmd.substr(6)
470470
: userConfigURL
471-
? userConfigURL
472-
: globalConfigURL;
471+
? userConfigURL
472+
: globalConfigURL;
473473
const { subdomain, domain, tld } = whitelistHandler.parseDomain(podUrl);
474474
const localConfig = config.getConfigFields([
475475
'enableBrowserLogin',

src/app/mini-view-handler.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { BrowserWindow } from 'electron';
2+
3+
import { isMac } from '../common/env';
14
import { logger } from '../common/logger';
25
import { config } from './config-handler';
36
import { mainEvents } from './main-event-handler';
@@ -17,13 +20,13 @@ class MiniViewHandler {
1720
*
1821
* @returns {void}
1922
*/
20-
public activateMiniView = (): void => {
23+
public activateMiniView = async (): Promise<void> => {
2124
windowHandler.setIsMiniViewTransition(true);
2225
logger.info('mini-view-handler: activateMiniView called');
2326
const mainWindow = windowHandler.getMainWindow();
2427
if (mainWindow && windowExists(mainWindow)) {
2528
if (mainWindow.isFullScreen()) {
26-
mainWindow.setFullScreen(false);
29+
await this.exitFullscreenAsync(mainWindow);
2730
}
2831
if (mainWindow.isMaximized()) {
2932
mainWindow.unmaximize();
@@ -117,6 +120,28 @@ class MiniViewHandler {
117120
mainWebContents.send('set-mini-view', miniViewState);
118121
}
119122
};
123+
124+
private exitFullscreenAsync = (window: BrowserWindow): Promise<void> => {
125+
return new Promise<void>((resolve) => {
126+
window.once('leave-full-screen', () => {
127+
if (!window || !windowExists(window)) {
128+
logger.error(
129+
'mini-view-handler: window does not exist or is destroyed',
130+
);
131+
resolve();
132+
return;
133+
}
134+
if (isMac) {
135+
resolve();
136+
} else {
137+
setTimeout(() => {
138+
resolve();
139+
}, 0);
140+
}
141+
});
142+
window.setFullScreen(false);
143+
});
144+
};
120145
}
121146

122147
const miniViewHandler = new MiniViewHandler();

src/app/window-handler.ts

+10
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,16 @@ export class WindowHandler {
528528
}
529529
}
530530
});
531+
532+
this.mainWindow.on('enter-full-screen', () => {
533+
if (this.isMiniViewFeatureEnabled && this.isMiniViewEnabled) {
534+
miniViewHandler.notifyClient(false);
535+
const appMenu = this.appMenu;
536+
if (appMenu) {
537+
appMenu.buildMenu();
538+
}
539+
}
540+
});
531541
if (isMaximized || isMaximizedFlag) {
532542
this.mainWindow.maximize();
533543
logger.info(

src/app/window-utils.ts

-11
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { notification } from '../renderer/notification';
5555
import { autoLaunchInstance } from './auto-launch-controller';
5656
import { autoUpdate, AutoUpdateTrigger } from './auto-update-handler';
5757
import { mainEvents } from './main-event-handler';
58-
import { miniViewHandler } from './mini-view-handler';
5958
import { openfinHandler } from './openfin-handler';
6059
import { presenceStatus } from './presence-status-handler';
6160
import { presenceStatusStore } from './stores';
@@ -1408,16 +1407,6 @@ export const loadWebContentsView = async (
14081407
});
14091408
}, 500);
14101409
mainEvents.publish('enter-full-screen');
1411-
if (
1412-
windowHandler.getIsMiniViewFeatureEnabled() &&
1413-
windowHandler.getIsMiniViewEnabled()
1414-
) {
1415-
miniViewHandler.notifyClient(false);
1416-
const appMenu = windowHandler.appMenu;
1417-
if (appMenu) {
1418-
appMenu.buildMenu();
1419-
}
1420-
}
14211410
});
14221411
mainWindow.on('leave-full-screen', () => {
14231412
logger.info('EVENT leave-full-screen!!');

0 commit comments

Comments
 (0)