diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-16 12:31:02 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-11-16 12:31:02 +0100 |
| commit | a013d38cf4d0dbb1984fbd1022c08de9b5ae410c (patch) | |
| tree | 189b5ecf00772a3472c3e291c54de42a8232a387 /gui/src | |
| parent | 21e92cde7d2695b9d72c96de16dae2e494166ecf (diff) | |
| parent | 279d35d1ec16d2ac69d739e91e60ef5fc56c9593 (diff) | |
| download | mullvadvpn-a013d38cf4d0dbb1984fbd1022c08de9b5ae410c.tar.xz mullvadvpn-a013d38cf4d0dbb1984fbd1022c08de9b5ae410c.zip | |
Merge branch 'fix-windows-resize'
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 34 | ||||
| -rw-r--r-- | gui/src/main/window-controller.ts | 49 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 12 |
3 files changed, 50 insertions, 45 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index f337824af1..cd19ae594f 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -1693,45 +1693,13 @@ class ApplicationMain { } } - // On both Linux and Windows the app height is applied incorrectly: - // https://github.com/electron/electron/issues/28777 - private getContentHeight(): number { - // The height we want achieve. - const contentHeight = 568; - - switch (process.platform) { - case 'darwin': { - // The size of transparent area around arrow on macOS. - const headerBarArrowHeight = 12; - - return this.guiSettings.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 this.guiSettings.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; - } - } - private async createWindow(): Promise<BrowserWindow> { - const height = this.getContentHeight(); - const width = 320; + const { width, height } = WindowController.getContentSize(this.guiSettings.unpinnedWindow); const options: Electron.BrowserWindowConstructorOptions = { useContentSize: true, width, - minWidth: width, - maxWidth: width, height, - minHeight: height, - maxHeight: height, resizable: false, maximizable: false, fullscreenable: false, diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index 1904383475..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()); @@ -263,10 +265,13 @@ export default class WindowController { } } - // On linux, the window won't be properly rescaled back to it's original + // 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; + } + } } diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 7880352d7b..0acbd25ab2 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -224,7 +224,10 @@ export default class AppRenderer { void this.onDaemonConnected(); } - this.checkContentHeight(); + this.checkContentHeight(false); + window.addEventListener('resize', () => { + this.checkContentHeight(true); + }); if (initialState.windowsSplitTunnelingApplications) { this.reduxActions.settings.setSplitTunnelingApplications( @@ -577,7 +580,7 @@ export default class AppRenderer { // purposes since there's a bug in Electron that causes the app height to be another value than // the one we have set. // https://github.com/electron/electron/issues/28777 - private checkContentHeight(): void { + private checkContentHeight(resize: boolean): void { let expectedContentHeight = 568; // The app content is 12px taller on macOS to fit the top arrow. @@ -587,7 +590,10 @@ export default class AppRenderer { const contentHeight = window.innerHeight; if (contentHeight !== expectedContentHeight) { - log.error(`Wrong content height ${contentHeight}, expected ${expectedContentHeight}`); + log.debug( + resize ? 'Resize:' : 'Initial:', + `Wrong content height: ${contentHeight}, expected ${expectedContentHeight}`, + ); } } |
