SDA-4960 - Implement state tracking to manage the visibility of titleBarView (#2455)

This commit is contained in:
Kiran Niranjan authored and GitHub committed 2025-08-18 13:43:56 +05:30
1 parent 36641ca28c
commit dc72015753
1 file changed
+28 -3
+28 -3
View File
@@ -1423,6 +1423,11 @@ export const loadWebContentsView = async (
mainWindow.contentView.addChildView(titleBarView);
mainWindow.contentView.addChildView(mainView);
// Track title bar state and any pending fullscreen timers to avoid race conditions
let enterFullScreenTimeout: NodeJS.Timeout | null = null;
let isTitleBarAttached = true;
mainWindow.on('enter-full-screen', () => {
if (
!titleBarView ||
@@ -1432,11 +1437,22 @@ export const loadWebContentsView = async (
) {
return;
}
if (enterFullScreenTimeout) {
clearTimeout(enterFullScreenTimeout);
enterFullScreenTimeout = null;
}
// Workaround: Need to delay getting the window bounds
// to get updated window bounds
setTimeout(() => {
enterFullScreenTimeout = setTimeout(() => {
if (!mainWindow.isFullScreen()) {
return;
}
const [width, height] = mainWindow.getSize();
mainWindow.contentView.removeChildView(titleBarView);
// Remove title bar only if it's currently attached
if (isTitleBarAttached) {
mainWindow.contentView.removeChildView(titleBarView);
isTitleBarAttached = false;
}
if (!mainView || !viewExists(mainView)) {
return;
}
@@ -1459,6 +1475,11 @@ export const loadWebContentsView = async (
) {
return;
}
// If there is a pending removal from a prior enter-full-screen, cancel it
if (enterFullScreenTimeout) {
clearTimeout(enterFullScreenTimeout);
enterFullScreenTimeout = null;
}
let width: number;
let height: number;
if (mainWindow.isMaximized()) {
@@ -1471,7 +1492,11 @@ export const loadWebContentsView = async (
} else {
[width, height] = mainWindow.getSize();
}
mainWindow.contentView.addChildView(titleBarView);
// Add title bar only if it's not already attached
if (!isTitleBarAttached) {
mainWindow.contentView.addChildView(titleBarView);
isTitleBarAttached = true;
}
const titleBarViewBounds = titleBarView.getBounds();
titleBarView.setBounds({
...titleBarViewBounds,