From 0f94b7d510237d48f597e74758c3e82279aff1ae Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 21 Apr 2023 18:09:20 -0400 Subject: [PATCH] Fixed Snap issue with resizing on Windows 11 (#2686) * Fixed Snap issue with resizing on Windows 11 * Run on focus/blur as well * Whoops, left my logging changes * Fix tests --- src/main/preload/desktopAPI.js | 5 +++++ src/main/windows/mainWindow.test.js | 1 + src/main/windows/mainWindow.ts | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/main/preload/desktopAPI.js b/src/main/preload/desktopAPI.js index a789e3ac..cf4ba656 100644 --- a/src/main/preload/desktopAPI.js +++ b/src/main/preload/desktopAPI.js @@ -88,6 +88,7 @@ import { GET_ORDERED_SERVERS, GET_ORDERED_TABS_FOR_SERVER, SERVERS_UPDATE, + VIEW_FINISHED_RESIZING, } from 'common/communication'; console.log('Preload initialized'); @@ -251,3 +252,7 @@ const createKeyDownListener = () => { }); }; createKeyDownListener(); + +window.addEventListener('resize', () => { + ipcRenderer.send(VIEW_FINISHED_RESIZING); +}); diff --git a/src/main/windows/mainWindow.test.js b/src/main/windows/mainWindow.test.js index ca7e3e40..b46f30d4 100644 --- a/src/main/windows/mainWindow.test.js +++ b/src/main/windows/mainWindow.test.js @@ -462,6 +462,7 @@ describe('main/windows/mainWindow', () => { }; BrowserWindow.mockImplementation(() => window); const mainWindow = new MainWindow(); + mainWindow.getBounds = jest.fn(); mainWindow.init(); Object.defineProperty(process, 'platform', { value: originalPlatform, diff --git a/src/main/windows/mainWindow.ts b/src/main/windows/mainWindow.ts index ac7a94d9..a854ecef 100644 --- a/src/main/windows/mainWindow.ts +++ b/src/main/windows/mainWindow.ts @@ -133,6 +133,7 @@ export class MainWindow extends EventEmitter { this.win.on('leave-full-screen', () => this.win?.webContents.send('leave-full-screen')); this.win.on('will-resize', this.onWillResize); this.win.on('resized', this.onResized); + this.win.on('moved', this.onResized); if (process.platform !== 'darwin') { mainWindow.on('resize', this.onResize); } @@ -286,6 +287,8 @@ export class MainWindow extends EventEmitter { // do nothing because we want to supress the menu popping up }); } + + this.emit(MAIN_WINDOW_RESIZED, this.getBounds()); } private onBlur = () => { @@ -295,6 +298,8 @@ export class MainWindow extends EventEmitter { globalShortcut.unregisterAll(); + this.emit(MAIN_WINDOW_RESIZED, this.getBounds()); + // App should save bounds when a window is closed. // However, 'close' is not fired in some situations(shutdown, ctrl+c) // because main process is killed in such situations.