diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-05 13:47:47 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-11-16 12:27:31 +0100 |
| commit | 710b42942543058ab8b68f97ddbe5a186fce69f7 (patch) | |
| tree | fb7dbbc512216becc4e5bc70ef20e30696dc0a94 /gui/src/main/window-controller.ts | |
| parent | 8f1b299c722294280f7ee0f9946a917dfee55d25 (diff) | |
| download | mullvadvpn-710b42942543058ab8b68f97ddbe5a186fce69f7.tar.xz mullvadvpn-710b42942543058ab8b68f97ddbe5a186fce69f7.zip | |
Use setContentSize instead of setSize
Diffstat (limited to 'gui/src/main/window-controller.ts')
| -rw-r--r-- | gui/src/main/window-controller.ts | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index c42d0398e3..dff90de639 100644 --- a/gui/src/main/window-controller.ts +++ b/gui/src/main/window-controller.ts @@ -135,8 +135,6 @@ class AttachedToTrayWindowPositioning implements IWindowPositioning { } export default class WindowController { - private width: number; - private height: number; private windowValue: BrowserWindow; private webContentsValue: WebContents; private windowPositioning: IWindowPositioning; @@ -151,10 +149,7 @@ export default class WindowController { return this.webContentsValue.isDestroyed() ? undefined : this.webContentsValue; } - constructor(windowValue: BrowserWindow, tray: Tray, unpinnedWindow: boolean) { - const [width, height] = windowValue.getSize(); - this.width = width; - this.height = height; + constructor(windowValue: BrowserWindow, tray: Tray, private unpinnedWindow: boolean) { this.windowValue = windowValue; this.webContentsValue = windowValue.webContents; this.windowPositioning = unpinnedWindow @@ -204,6 +199,13 @@ export default class WindowController { } } + public static getContentSize(unpinnedWindow: boolean): { width: number; height: number } { + return { + width: 320, + height: WindowController.getContentHeight(unpinnedWindow), + }; + } + private installHideHandler() { this.window?.addListener('hide', () => this.windowPositioningScheduler.cancel()); this.window?.addListener('closed', () => this.windowPositioningScheduler.cancel()); @@ -266,7 +268,10 @@ export default class WindowController { // On Linux and Windows, the window won't be properly rescaled back to it's original // size if the DPI scaling factor is changed. // https://github.com/electron/electron/issues/11050 - if (process.platform === 'linux' && changedMetrics.includes('scaleFactor')) { + if ( + changedMetrics.includes('scaleFactor') && + (process.platform === 'win32' || process.platform === 'linux') + ) { this.forceResizeWindow(); } }; @@ -276,7 +281,8 @@ export default class WindowController { } private forceResizeWindow() { - this.window?.setSize(this.width, this.height); + const { width, height } = WindowController.getContentSize(this.unpinnedWindow); + this.window?.setContentSize(width, height); } private executeWhenWindowIsReady(closure: () => void) { @@ -288,4 +294,29 @@ export default class WindowController { }); } } + + // On both Linux and Windows the app height is applied incorrectly: + // https://github.com/electron/electron/issues/28777 + private static getContentHeight(unpinnedWindow: boolean): number { + // The height we want to achieve. + const contentHeight = 568; + + switch (process.platform) { + case 'darwin': { + // The size of transparent area around arrow on macOS. + const headerBarArrowHeight = 12; + + return unpinnedWindow ? contentHeight : contentHeight + headerBarArrowHeight; + } + case 'win32': + // On Windows the app height ends up slightly lower than we set it to if running in unpinned + // mode and the app becomes a tiny bit taller when pinned to task bar. + return unpinnedWindow ? contentHeight + 19 : contentHeight - 1; + case 'linux': + // On Linux the app ends up slightly lower than we set it to. + return contentHeight - 25; + default: + return contentHeight; + } + } } |
