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 6e43978fde..9878befc18 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 @@ -136,6 +136,27 @@ describe("opening application window using tray", () => { expect(callForApplicationWindowHtmlMock).toHaveBeenCalledWith("http://localhost:42"); }); + describe("given static HTML of application window has not resolved yet, when opening from tray again", () => { + beforeEach(() => { + callForApplicationWindowHtmlMock.mockClear(); + callForSplashWindowHtmlMock.mockClear(); + + applicationBuilder.tray.click("open-app"); + }); + + it("does not load contents of splash window again", () => { + expect(callForSplashWindowHtmlMock).not.toHaveBeenCalled(); + }); + + it("does not load contents of application window again", () => { + expect(callForApplicationWindowHtmlMock).not.toHaveBeenCalled(); + }); + + it("shows just the blank application window to permit developer tool access", () => { + expectWindowsToBeOpen(["only-application-window"]); + }); + }); + describe("when static HTML of application window resolves", () => { beforeEach(async () => { await callForApplicationWindowHtmlMock.resolve(); 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 dcd42f2333..1f50e2312f 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 @@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import type { LensWindow, SendToViewArgs } from "./lens-window-injection-token"; import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable"; import createElectronWindowForInjectable from "./create-electron-window.injectable"; +import assert from "assert"; export interface ElectronWindow { show: () => void; @@ -40,52 +41,62 @@ const createLensWindowInjectable = getInjectable({ return (configuration: LensWindowConfiguration): LensWindow => { let browserWindow: ElectronWindow | undefined; + let windowIsShown = false; let windowIsOpening = false; - let contentIsLoading = false; + + const showWindow = () => { + assert(browserWindow); + + browserWindow.show(); + windowIsShown = true; + }; return { id: configuration.id, get visible() { - return !!browserWindow && !contentIsLoading; + return windowIsShown; }, get opening() { return windowIsOpening; }, - show: async () => { + open: async () => { if (!browserWindow) { windowIsOpening = true; browserWindow = createElectronWindow({ ...configuration, - onClose: () => browserWindow = undefined, + onClose: () => { + browserWindow = undefined; + windowIsShown = false; + }, }); - const windowFilePath = configuration.getContentSource().file; - const windowUrl = configuration.getContentSource().url; + const { file: filePathForContent, url: urlForContent } = + configuration.getContentSource(); - contentIsLoading = true; - - if (windowFilePath) { - await browserWindow.loadFile(windowFilePath); - } else if (windowUrl) { - await browserWindow.loadUrl(windowUrl); + if (filePathForContent) { + await browserWindow.loadFile(filePathForContent); + } else if (urlForContent) { + await browserWindow.loadUrl(urlForContent); } await configuration.beforeOpen?.(); - - contentIsLoading = false; } - browserWindow.show(); + showWindow(); + windowIsOpening = false; }, + show: showWindow, + close: () => { browserWindow?.close(); browserWindow = undefined; + windowIsShown = false; }, send: (args: SendToViewArgs) => { 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 e424e33c78..4f8c3bb73a 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 @@ -13,8 +13,9 @@ export interface SendToViewArgs { export interface LensWindow { id: string; - show: () => Promise; + open: () => Promise; close: () => void; + show: () => void; send: (args: SendToViewArgs) => void; visible: boolean; opening: boolean; 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 18f5e20e1e..e1f9438ecf 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 @@ -13,14 +13,18 @@ const showApplicationWindowInjectable = getInjectable({ instantiate: (di) => { const applicationWindow = di.inject(applicationWindowInjectable); - const splashWindow = di.inject(splashWindowInjectable); return async () => { + if (applicationWindow.opening) { + applicationWindow.show(); + splashWindow.close(); + + return; + } + const windowIsAlreadyBeingShown = someIsTruthy([ applicationWindow.visible, - applicationWindow.opening, - splashWindow.visible, splashWindow.opening, ]); @@ -28,9 +32,9 @@ const showApplicationWindowInjectable = getInjectable({ return; } - await splashWindow.show(); + await splashWindow.open(); - await applicationWindow.show(); + await applicationWindow.open(); splashWindow.close(); }; diff --git a/src/main/start-main-application/start-main-application.injectable.ts b/src/main/start-main-application/start-main-application.injectable.ts index 8d48977089..30e1da33f9 100644 --- a/src/main/start-main-application/start-main-application.injectable.ts +++ b/src/main/start-main-application/start-main-application.injectable.ts @@ -49,7 +49,7 @@ const startMainApplicationInjectable = getInjectable({ await beforeApplicationIsLoading(); if (!shouldStartHidden) { - await splashWindow.show(); + await splashWindow.open(); } await onLoadOfApplication(); @@ -60,7 +60,7 @@ const startMainApplicationInjectable = getInjectable({ if (deepLinkUrl) { await openDeepLink(deepLinkUrl); } else { - await applicationWindow.show(); + await applicationWindow.open(); } splashWindow.close(); diff --git a/src/renderer/components/test-utils/get-application-builder.tsx b/src/renderer/components/test-utils/get-application-builder.tsx index f6cd766ce6..56927b4c3a 100644 --- a/src/renderer/components/test-utils/get-application-builder.tsx +++ b/src/renderer/components/test-utils/get-application-builder.tsx @@ -408,7 +408,7 @@ export const getApplicationBuilder = () => { const applicationWindow = mainDi.inject(applicationWindowInjectable); - await applicationWindow.show(); + await applicationWindow.open(); const startFrame = rendererDi.inject(startFrameInjectable);