diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index cf3a5c329..e7a26ff13 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -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'; @@ -87,7 +86,7 @@ const DOWNLOAD_MANAGER_NAMESPACE = 'DownloadManager'; const TITLE_BAR_EVENTS = [ 'maximize', 'unmaximize', - 'moved', + 'move', 'enter-full-screen', 'leave-full-screen', ]; @@ -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 ( @@ -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, }); @@ -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'); @@ -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, }); @@ -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);