From 836adc76d6d05b84fd8a3068004730a8d804de14 Mon Sep 17 00:00:00 2001 From: F-OBrien Date: Wed, 29 Mar 2023 19:02:31 +0100 Subject: [PATCH] resize popup window upon createView --- packages/extension-ui/src/createView.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/extension-ui/src/createView.tsx b/packages/extension-ui/src/createView.tsx index 1851529003..98250c7b2b 100644 --- a/packages/extension-ui/src/createView.tsx +++ b/packages/extension-ui/src/createView.tsx @@ -10,6 +10,24 @@ import { HashRouter } from 'react-router-dom'; import { View } from './components/index.js'; export default function createView (Entry: React.ComponentType, rootId = 'root'): void { + const targetInnerWidth = 560; + const targetInnerHeight = 600; + + // Popup window size is initially set via chrome.windows.create, however + // it will result in different inner dimensions on Windows and Mac OS. + // This is a hacky way to have a consistent popup size + if ( + window.innerWidth !== targetInnerWidth || + window.innerHeight !== targetInnerHeight + ) { + const newOuterWidth = + targetInnerWidth + (window.outerWidth - window.innerWidth); + const newOuterHeight = + targetInnerHeight + (window.outerHeight - window.innerHeight); + + window.resizeTo(newOuterWidth, newOuterHeight); + } + const rootElement = document.getElementById(rootId); if (!rootElement) {