SDA-4418 BrowserViews auto-resize disabled and handled by ourselves (#2039)

* SDA-4418 BrowserViews auto-resize disabled and handled by ourselves

* Devtools resizing
This commit is contained in:
Salah Benmoussati 2023-12-21 15:25:24 +01:00 committed by GitHub
parent 38a78d02b8
commit a2025f748e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 32 deletions

8
package-lock.json generated
View File

@ -21,6 +21,7 @@
"electron-updater": "^6.1.3", "electron-updater": "^6.1.3",
"filesize": "^10.0.6", "filesize": "^10.0.6",
"lazy-brush": "^1.0.1", "lazy-brush": "^1.0.1",
"lodash.debounce": "^4.0.8",
"react": "16.14.0", "react": "16.14.0",
"react-dom": "16.14.0", "react-dom": "16.14.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
@ -12163,8 +12164,8 @@
}, },
"node_modules/lodash.debounce": { "node_modules/lodash.debounce": {
"version": "4.0.8", "version": "4.0.8",
"dev": true, "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
"license": "MIT" "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow=="
}, },
"node_modules/lodash.defaults": { "node_modules/lodash.defaults": {
"version": "4.2.0", "version": "4.2.0",
@ -26729,7 +26730,8 @@
}, },
"lodash.debounce": { "lodash.debounce": {
"version": "4.0.8", "version": "4.0.8",
"dev": true "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
"integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow=="
}, },
"lodash.defaults": { "lodash.defaults": {
"version": "4.2.0" "version": "4.2.0"

View File

@ -222,6 +222,7 @@
"electron-updater": "^6.1.3", "electron-updater": "^6.1.3",
"filesize": "^10.0.6", "filesize": "^10.0.6",
"lazy-brush": "^1.0.1", "lazy-brush": "^1.0.1",
"lodash.debounce": "^4.0.8",
"react": "16.14.0", "react": "16.14.0",
"react-dom": "16.14.0", "react-dom": "16.14.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",

View File

@ -16,6 +16,7 @@ import electron = require('electron');
import fetch from 'electron-fetch'; import fetch from 'electron-fetch';
import { filesize } from 'filesize'; import { filesize } from 'filesize';
import * as fs from 'fs'; import * as fs from 'fs';
import * as debounce from 'lodash.debounce';
import * as path from 'path'; import * as path from 'path';
import { format, parse } from 'url'; import { format, parse } from 'url';
import { apiName, EPresenceStatusGroup } from '../common/api-interface'; import { apiName, EPresenceStatusGroup } from '../common/api-interface';
@ -86,7 +87,7 @@ const DOWNLOAD_MANAGER_NAMESPACE = 'DownloadManager';
const TITLE_BAR_EVENTS = [ const TITLE_BAR_EVENTS = [
'maximize', 'maximize',
'unmaximize', 'unmaximize',
'move', 'moved',
'enter-full-screen', 'enter-full-screen',
'leave-full-screen', 'leave-full-screen',
]; ];
@ -1315,7 +1316,9 @@ export const loadBrowserViews = async (
}, 500); }, 500);
mainEvents.publish('enter-full-screen'); mainEvents.publish('enter-full-screen');
}); });
mainWindow?.on('leave-full-screen', () => { mainWindow?.on('leave-full-screen', () => {
logger.info('EVENT leave-full-screen!!');
if ( if (
!titleBarView || !titleBarView ||
!viewExists(titleBarView) || !viewExists(titleBarView) ||
@ -1360,41 +1363,46 @@ export const loadBrowserViews = async (
mainEvents.publish('leave-full-screen'); mainEvents.publish('leave-full-screen');
}); });
mainWindow?.on('maximize', () => { mainWindow?.on('maximize', async () => {
if (!mainView || !viewExists(mainView)) { const width = await mainWindow?.webContents.executeJavaScript(
return; 'window.innerWidth',
} );
const winBounds: Rectangle = mainWindow.getBounds(); const height = await mainWindow?.webContents.executeJavaScript(
const currentScreenBounds: Rectangle = screen.getDisplayMatching({ 'window.innerHeight',
...winBounds, );
}).workArea; const titleBarDisplayed = mainWindow.getBrowserViews().length > 1;
mainView.setBounds({ mainView.setBounds({
width: currentScreenBounds.width, height: titleBarDisplayed ? height - TITLE_BAR_HEIGHT : height,
height: currentScreenBounds.height - TITLE_BAR_HEIGHT, width,
x: 0, x: 0,
y: TITLE_BAR_HEIGHT, y: titleBarDisplayed ? TITLE_BAR_HEIGHT : 0,
}); });
titleBarView.setBounds({
width: currentScreenBounds.width, titleBarView?.setBounds({
height: TITLE_BAR_HEIGHT, height: TITLE_BAR_HEIGHT,
width,
x: 0, x: 0,
y: 0, y: 0,
}); });
}); });
mainWindow?.on('unmaximize', () => { const resizeWindow = async () => {
if (!mainView || !viewExists(mainView)) { const width = await mainWindow?.webContents.executeJavaScript(
return; 'window.innerWidth',
} );
const [width, height] = mainWindow.getSize(); const height = await mainWindow?.webContents.executeJavaScript(
'window.innerHeight',
);
const titleBarDisplayed = mainWindow.getBrowserViews().length > 1;
mainView.setBounds({ mainView.setBounds({
height: titleBarDisplayed ? height - TITLE_BAR_HEIGHT : height,
width, width,
height: height - TITLE_BAR_HEIGHT,
x: 0, x: 0,
y: TITLE_BAR_HEIGHT, y: titleBarDisplayed ? TITLE_BAR_HEIGHT : 0,
}); });
titleBarView.setBounds({
width, titleBarView?.setBounds({
height: TITLE_BAR_HEIGHT, height: TITLE_BAR_HEIGHT,
width,
x: 0, x: 0,
y: 0, y: 0,
}); });
@ -1403,7 +1411,12 @@ export const loadBrowserViews = async (
mainView.webContents.toggleDevTools(); mainView.webContents.toggleDevTools();
mainView.webContents.toggleDevTools(); mainView.webContents.toggleDevTools();
} }
}); };
const onResize = debounce(async () => {
resizeWindow();
}, 100);
mainWindow?.on('resize', onResize);
mainWindow?.on('unmaximize', resizeWindow);
if (mainWindow?.isMaximized()) { if (mainWindow?.isMaximized()) {
mainEvents.publish('maximize'); mainEvents.publish('maximize');
@ -1418,9 +1431,7 @@ export const loadBrowserViews = async (
...{ x: 0, y: 0, height: TITLE_BAR_HEIGHT }, ...{ x: 0, y: 0, height: TITLE_BAR_HEIGHT },
}); });
titleBarView.setAutoResize({ titleBarView.setAutoResize({
vertical: false, width: false,
horizontal: true,
width: true,
height: false, height: false,
}); });
@ -1431,8 +1442,8 @@ export const loadBrowserViews = async (
y: TITLE_BAR_HEIGHT, y: TITLE_BAR_HEIGHT,
}); });
mainView.setAutoResize({ mainView.setAutoResize({
width: true, width: false,
height: true, height: false,
}); });
windowHandler.setMainView(mainView); windowHandler.setMainView(mainView);