From a6ce24d18464b22bf73a74f272f0a3d72899390e Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:20:16 -0400 Subject: [PATCH] [MM-58001] Fix an issue where the window position has a decimal number (#3017) * [MM-58001] Fix an issue where the window position has a decimal number * I accidentally a log --- src/main/app/utils.test.js | 16 ++++++++++++++++ src/main/app/utils.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/app/utils.test.js b/src/main/app/utils.test.js index 5ae19925..f4caf0e8 100644 --- a/src/main/app/utils.test.js +++ b/src/main/app/utils.test.js @@ -166,6 +166,22 @@ describe('main/app/utils', () => { resizeScreen(browserWindow); expect(browserWindow.setPosition).toHaveBeenCalledWith(690, 410); }); + + it('should never return non-integer value', () => { + MainWindow.get.mockReturnValue({ + getPosition: () => [450, 350], + getSize: () => [1280, 720], + }); + const browserWindow = { + getPosition: () => [450, 350], + getSize: () => [1281, 721], + setPosition: jest.fn(), + center: jest.fn(), + once: jest.fn(), + }; + resizeScreen(browserWindow); + expect(browserWindow.setPosition).toHaveBeenCalledWith(449, 349); + }); }); describe('migrateMacAppStore', () => { diff --git a/src/main/app/utils.ts b/src/main/app/utils.ts index 6a54d32d..c5f7ac41 100644 --- a/src/main/app/utils.ts +++ b/src/main/app/utils.ts @@ -155,8 +155,8 @@ function getNewWindowPosition(browserWindow: BrowserWindow) { const mainWindowPosition = mainWindow.getPosition(); return [ - mainWindowPosition[0] + ((mainWindowSize[0] - newWindowSize[0]) / 2), - mainWindowPosition[1] + ((mainWindowSize[1] - newWindowSize[1]) / 2), + Math.floor(mainWindowPosition[0] + ((mainWindowSize[0] - newWindowSize[0]) / 2)), + Math.floor(mainWindowPosition[1] + ((mainWindowSize[1] - newWindowSize[1]) / 2)), ]; }