From f91e88788be9ebcc306fb2a0727de6fa8d318e5c Mon Sep 17 00:00:00 2001 From: Iku-turso Date: Wed, 1 Jun 2022 15:41:38 +0300 Subject: [PATCH] Make sure bug about opening involuntary duplicate app windows is solved in all scenarios Co-authored-by: Janne Savolainen Signed-off-by: Iku-turso --- .../opening-application-window-using-tray.test.ts | 14 +++++++++++++- .../create-lens-window.injectable.ts | 8 ++++++++ .../lens-window-injection-token.ts | 1 + .../show-application-window.injectable.ts | 15 +++++++++++---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts b/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts index c345dc2299..4a598c8d68 100644 --- a/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts +++ b/src/behaviours/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts @@ -86,6 +86,18 @@ describe("opening application window using tray", () => { expectWindowsToBeOpen([]); }); + describe("given opening of splash window has not finished yet, but another attempt to open the application is made", () => { + beforeEach(() => { + createElectronWindowMock.mockClear(); + + applicationBuilder.tray.click("open-app"); + }); + + it("does not open any new windows", () => { + expect(createElectronWindowMock).not.toHaveBeenCalled(); + }); + }); + describe("when opening of splash window resolves", () => { beforeEach(async () => { await resolveOpeningOfWindow("splash"); @@ -101,7 +113,7 @@ describe("opening application window using tray", () => { expectWindowsToBeOpen(["only-application-window"]); }); - describe("given opening has not finished yet, but another attempt to open the application is made", () => { + describe("given opening of application window has not finished yet, but another attempt to open the application is made", () => { beforeEach(() => { createElectronWindowMock.mockClear(); diff --git a/src/main/start-main-application/lens-window/application-window/create-lens-window.injectable.ts b/src/main/start-main-application/lens-window/application-window/create-lens-window.injectable.ts index 62487ca090..4042a1a56d 100644 --- a/src/main/start-main-application/lens-window/application-window/create-lens-window.injectable.ts +++ b/src/main/start-main-application/lens-window/application-window/create-lens-window.injectable.ts @@ -46,6 +46,8 @@ const createLensWindowInjectable = getInjectable({ configuration, )); + let windowIsOpening = false; + return { id: configuration.id, @@ -53,12 +55,18 @@ const createLensWindowInjectable = getInjectable({ return !!browserWindow; }, + get opening() { + return windowIsOpening; + }, + show: async () => { if (!browserWindow) { + windowIsOpening = true; browserWindow = await createElectronWindow(); } browserWindow.show(); + windowIsOpening = false; }, close: () => { diff --git a/src/main/start-main-application/lens-window/application-window/lens-window-injection-token.ts b/src/main/start-main-application/lens-window/application-window/lens-window-injection-token.ts index 1a31c18780..e424e33c78 100644 --- a/src/main/start-main-application/lens-window/application-window/lens-window-injection-token.ts +++ b/src/main/start-main-application/lens-window/application-window/lens-window-injection-token.ts @@ -17,6 +17,7 @@ export interface LensWindow { close: () => void; send: (args: SendToViewArgs) => void; visible: boolean; + opening: boolean; } export const lensWindowInjectionToken = getInjectionToken({ diff --git a/src/main/start-main-application/lens-window/show-application-window.injectable.ts b/src/main/start-main-application/lens-window/show-application-window.injectable.ts index a862455567..18f5e20e1e 100644 --- a/src/main/start-main-application/lens-window/show-application-window.injectable.ts +++ b/src/main/start-main-application/lens-window/show-application-window.injectable.ts @@ -5,6 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import splashWindowInjectable from "./splash-window/splash-window.injectable"; import applicationWindowInjectable from "./application-window/application-window.injectable"; +import { identity, some } from "lodash/fp"; +const someIsTruthy = some(identity); const showApplicationWindowInjectable = getInjectable({ id: "show-application-window", @@ -12,12 +14,17 @@ const showApplicationWindowInjectable = getInjectable({ instantiate: (di) => { const applicationWindow = di.inject(applicationWindowInjectable); - const splashWindow = di.inject( - splashWindowInjectable, - ); + const splashWindow = di.inject(splashWindowInjectable); return async () => { - if (applicationWindow.visible || splashWindow.visible) { + const windowIsAlreadyBeingShown = someIsTruthy([ + applicationWindow.visible, + applicationWindow.opening, + splashWindow.visible, + splashWindow.opening, + ]); + + if (windowIsAlreadyBeingShown) { return; }