diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-11-19 11:45:59 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-11-19 11:45:59 +0100 |
| commit | a51e006ddfcc9a49ad4a4bf448a58bf2d4f5bf6a (patch) | |
| tree | d0f03acb035e87e1bc4f415878b9bb8d482c9157 /gui/src/main/window-controller.ts | |
| parent | b72f29cd885c2e9c02b27f72cd93683aba253e8d (diff) | |
| parent | 9f9eb140f0f7eab42bae361be6202418c59475f5 (diff) | |
| download | mullvadvpn-a51e006ddfcc9a49ad4a4bf448a58bf2d4f5bf6a.tar.xz mullvadvpn-a51e006ddfcc9a49ad4a4bf448a58bf2d4f5bf6a.zip | |
Merge branch 'add-app-window-setting'
Diffstat (limited to 'gui/src/main/window-controller.ts')
| -rw-r--r-- | gui/src/main/window-controller.ts | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index 69457a63fa..09b8d7651f 100644 --- a/gui/src/main/window-controller.ts +++ b/gui/src/main/window-controller.ts @@ -133,6 +133,7 @@ class AttachedToTrayWindowPositioning implements IWindowPositioning { export default class WindowController { private width: number; private height: number; + private windowValue: BrowserWindow; private webContentsValue: WebContents; private windowPositioning: IWindowPositioning; private isWindowReady = false; @@ -145,20 +146,35 @@ export default class WindowController { return this.webContentsValue; } - constructor(private windowValue: BrowserWindow, tray: Tray) { + constructor(windowValue: BrowserWindow, private tray: Tray, unpinnedWindow: boolean) { const [width, height] = windowValue.getSize(); this.width = width; this.height = height; + this.windowValue = windowValue; this.webContentsValue = windowValue.webContents; - this.windowPositioning = - process.platform === 'linux' - ? new StandaloneWindowPositioning() - : new AttachedToTrayWindowPositioning(tray); + this.windowPositioning = unpinnedWindow + ? new StandaloneWindowPositioning() + : new AttachedToTrayWindowPositioning(tray); this.installDisplayMetricsHandler(); this.installWindowReadyHandlers(); } + public replaceWindow(window: BrowserWindow, unpinnedWindow: boolean) { + this.window.removeAllListeners(); + this.window.destroy(); + + this.windowValue = window; + this.webContentsValue = window.webContents; + + this.windowPositioning = unpinnedWindow + ? new StandaloneWindowPositioning() + : new AttachedToTrayWindowPositioning(this.tray); + + this.updatePosition(); + this.notifyUpdateWindowShape(); + } + public show(whenReady = true) { if (whenReady) { this.executeWhenWindowIsReady(() => this.showImmediately()); @@ -192,11 +208,26 @@ export default class WindowController { private showImmediately() { const window = this.windowValue; - this.updatePosition(); - this.notifyUpdateWindowShape(); + // When running with unpinned window on Windows there's a bug that causes the app to become + // wider if opened from minimized if the updated position is set before the window is opened. + // Unfortunately the order can't always be changed since this would cause the Window to "jump" + // in other scenarios. + if ( + process.platform === 'win32' && + this.windowPositioning instanceof StandaloneWindowPositioning + ) { + window.show(); + window.focus(); + + this.updatePosition(); + this.notifyUpdateWindowShape(); + } else { + this.updatePosition(); + this.notifyUpdateWindowShape(); - window.show(); - window.focus(); + window.show(); + window.focus(); + } } private updatePosition() { |
