summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-11-05 13:47:47 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-11-16 12:27:31 +0100
commit710b42942543058ab8b68f97ddbe5a186fce69f7 (patch)
treefb7dbbc512216becc4e5bc70ef20e30696dc0a94
parent8f1b299c722294280f7ee0f9946a917dfee55d25 (diff)
downloadmullvadvpn-710b42942543058ab8b68f97ddbe5a186fce69f7.tar.xz
mullvadvpn-710b42942543058ab8b68f97ddbe5a186fce69f7.zip
Use setContentSize instead of setSize
-rw-r--r--gui/src/main/index.ts34
-rw-r--r--gui/src/main/window-controller.ts47
2 files changed, 40 insertions, 41 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 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;
+ }
+ }
}