Skip to content

Commit

Permalink
SDA-4433 - Revert SDA-4418 (finos#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan authored Jan 3, 2024
1 parent e827b72 commit 5f92dc3
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions src/app/window-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import electron = require('electron');
import fetch from 'electron-fetch';
import { filesize } from 'filesize';
import * as fs from 'fs';
import * as debounce from 'lodash.debounce';
import * as path from 'path';
import { format, parse } from 'url';
import { apiName, EPresenceStatusGroup } from '../common/api-interface';
Expand Down Expand Up @@ -87,7 +86,7 @@ const DOWNLOAD_MANAGER_NAMESPACE = 'DownloadManager';
const TITLE_BAR_EVENTS = [
'maximize',
'unmaximize',
'moved',
'move',
'enter-full-screen',
'leave-full-screen',
];
Expand Down Expand Up @@ -1316,7 +1315,6 @@ export const loadBrowserViews = async (
}, 500);
mainEvents.publish('enter-full-screen');
});

mainWindow?.on('leave-full-screen', () => {
logger.info('EVENT leave-full-screen!!');
if (
Expand Down Expand Up @@ -1363,46 +1361,41 @@ export const loadBrowserViews = async (
mainEvents.publish('leave-full-screen');
});

mainWindow?.on('maximize', async () => {
const width = await mainWindow?.webContents.executeJavaScript(
'window.innerWidth',
);
const height = await mainWindow?.webContents.executeJavaScript(
'window.innerHeight',
);
const titleBarDisplayed = mainWindow.getBrowserViews().length > 1;
mainWindow?.on('maximize', () => {
if (!mainView || !viewExists(mainView)) {
return;
}
const winBounds: Rectangle = mainWindow.getBounds();
const currentScreenBounds: Rectangle = screen.getDisplayMatching({
...winBounds,
}).workArea;
mainView.setBounds({
height: titleBarDisplayed ? height - TITLE_BAR_HEIGHT : height,
width,
width: currentScreenBounds.width,
height: currentScreenBounds.height - TITLE_BAR_HEIGHT,
x: 0,
y: titleBarDisplayed ? TITLE_BAR_HEIGHT : 0,
y: TITLE_BAR_HEIGHT,
});

titleBarView?.setBounds({
titleBarView.setBounds({
width: currentScreenBounds.width,
height: TITLE_BAR_HEIGHT,
width,
x: 0,
y: 0,
});
});
const resizeWindow = async () => {
const width = await mainWindow?.webContents.executeJavaScript(
'window.innerWidth',
);
const height = await mainWindow?.webContents.executeJavaScript(
'window.innerHeight',
);
const titleBarDisplayed = mainWindow.getBrowserViews().length > 1;
mainWindow?.on('unmaximize', () => {
if (!mainView || !viewExists(mainView)) {
return;
}
const [width, height] = mainWindow.getSize();
mainView.setBounds({
height: titleBarDisplayed ? height - TITLE_BAR_HEIGHT : height,
width,
height: height - TITLE_BAR_HEIGHT,
x: 0,
y: titleBarDisplayed ? TITLE_BAR_HEIGHT : 0,
y: TITLE_BAR_HEIGHT,
});

titleBarView?.setBounds({
height: TITLE_BAR_HEIGHT,
titleBarView.setBounds({
width,
height: TITLE_BAR_HEIGHT,
x: 0,
y: 0,
});
Expand All @@ -1411,12 +1404,7 @@ export const loadBrowserViews = async (
mainView.webContents.toggleDevTools();
mainView.webContents.toggleDevTools();
}
};
const onResize = debounce(async () => {
resizeWindow();
}, 100);
mainWindow?.on('resize', onResize);
mainWindow?.on('unmaximize', resizeWindow);
});

if (mainWindow?.isMaximized()) {
mainEvents.publish('maximize');
Expand All @@ -1431,7 +1419,9 @@ export const loadBrowserViews = async (
...{ x: 0, y: 0, height: TITLE_BAR_HEIGHT },
});
titleBarView.setAutoResize({
width: false,
vertical: false,
horizontal: true,
width: true,
height: false,
});

Expand All @@ -1442,8 +1432,8 @@ export const loadBrowserViews = async (
y: TITLE_BAR_HEIGHT,
});
mainView.setAutoResize({
width: false,
height: false,
width: true,
height: true,
});

windowHandler.setMainView(mainView);
Expand Down

0 comments on commit 5f92dc3

Please sign in to comment.