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 ba26ce8e4b..2971a82614 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 @@ -43,23 +43,34 @@ const createLensWindowInjectable = getInjectable({ onClose: () => browserWindow = undefined, }); + let windowIsOpening = false; + return { id: configuration.id, get visible() { return !!browserWindow; }, + + get opening() { + return windowIsOpening; + }, + show: async () => { if (!browserWindow) { + windowIsOpening = true; browserWindow = await createElectronWindow(); } browserWindow.show(); + windowIsOpening = false; }, + close: () => { browserWindow?.close(); browserWindow = undefined; }, + send: (args: SendToViewArgs) => { if (!browserWindow) { throw new Error(`Tried to send message to window "${configuration.id}" but the window was closed`); 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; }