summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-11-15 16:26:56 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-11-15 16:26:56 +0100
commit8602854d62dfd774b9ce229be28a933131ea4e24 (patch)
treef89a7553a8fd1e17ec3306a07081c1095b2b12ee /gui/src/main
parent13cd3b45058da817ca045daf7cef7ab1e247bd34 (diff)
parenta92b194b9a3dbad0d09e9aa08ec3101f02afc101 (diff)
downloadmullvadvpn-8602854d62dfd774b9ce229be28a933131ea4e24.tar.xz
mullvadvpn-8602854d62dfd774b9ce229be28a933131ea4e24.zip
Merge branch 'refactor-unpin-window'
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/index.ts8
-rw-r--r--gui/src/main/window-controller.ts26
2 files changed, 14 insertions, 20 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 5e3b28b342..f337824af1 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -1585,7 +1585,13 @@ class ApplicationMain {
this.tray.removeAllListeners();
const window = await this.createWindow();
- this.windowController.replaceWindow(window, unpinnedWindow);
+
+ this.windowController.destroy();
+ this.windowController = new WindowController(
+ window,
+ this.tray,
+ this.guiSettings.unpinnedWindow,
+ );
await this.initializeWindow();
this.windowController.show();
diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts
index cdb7102afb..1904383475 100644
--- a/gui/src/main/window-controller.ts
+++ b/gui/src/main/window-controller.ts
@@ -151,7 +151,7 @@ export default class WindowController {
return this.webContentsValue.isDestroyed() ? undefined : this.webContentsValue;
}
- constructor(windowValue: BrowserWindow, private tray: Tray, unpinnedWindow: boolean) {
+ constructor(windowValue: BrowserWindow, tray: Tray, unpinnedWindow: boolean) {
const [width, height] = windowValue.getSize();
this.width = width;
this.height = height;
@@ -165,24 +165,6 @@ export default class WindowController {
this.installHideHandler();
}
- public replaceWindow(windowValue: BrowserWindow, unpinnedWindow: boolean) {
- this.window?.destroy();
-
- const [width, height] = windowValue.getSize();
- this.width = width;
- this.height = height;
- this.windowValue = windowValue;
- this.webContentsValue = windowValue.webContents;
-
- this.windowPositioning = unpinnedWindow
- ? new StandaloneWindowPositioning()
- : new AttachedToTrayWindowPositioning(this.tray);
-
- this.installDisplayMetricsHandler();
- this.installHideHandler();
- this.updatePosition();
- }
-
public show(whenReady = true) {
if (whenReady) {
this.executeWhenWindowIsReady(() => this.showImmediately());
@@ -216,6 +198,12 @@ export default class WindowController {
this.notifyUpdateWindowShape();
}
+ public destroy() {
+ if (this.window && !this.window.isDestroyed()) {
+ this.window.destroy();
+ }
+ }
+
private installHideHandler() {
this.window?.addListener('hide', () => this.windowPositioningScheduler.cancel());
this.window?.addListener('closed', () => this.windowPositioningScheduler.cancel());