1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Implement showing of blank application window when re-opening before contents have been load to permit developer tool access

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-06-10 16:22:01 +03:00
parent 700eb324a2
commit d2cff17e9b
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
6 changed files with 61 additions and 24 deletions

View File

@ -136,6 +136,27 @@ describe("opening application window using tray", () => {
expect(callForApplicationWindowHtmlMock).toHaveBeenCalledWith("http://localhost:42"); 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", () => { describe("when static HTML of application window resolves", () => {
beforeEach(async () => { beforeEach(async () => {
await callForApplicationWindowHtmlMock.resolve(); await callForApplicationWindowHtmlMock.resolve();

View File

@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { LensWindow, SendToViewArgs } from "./lens-window-injection-token"; import type { LensWindow, SendToViewArgs } from "./lens-window-injection-token";
import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable"; import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable";
import createElectronWindowForInjectable from "./create-electron-window.injectable"; import createElectronWindowForInjectable from "./create-electron-window.injectable";
import assert from "assert";
export interface ElectronWindow { export interface ElectronWindow {
show: () => void; show: () => void;
@ -40,52 +41,62 @@ const createLensWindowInjectable = getInjectable({
return (configuration: LensWindowConfiguration): LensWindow => { return (configuration: LensWindowConfiguration): LensWindow => {
let browserWindow: ElectronWindow | undefined; let browserWindow: ElectronWindow | undefined;
let windowIsShown = false;
let windowIsOpening = false; let windowIsOpening = false;
let contentIsLoading = false;
const showWindow = () => {
assert(browserWindow);
browserWindow.show();
windowIsShown = true;
};
return { return {
id: configuration.id, id: configuration.id,
get visible() { get visible() {
return !!browserWindow && !contentIsLoading; return windowIsShown;
}, },
get opening() { get opening() {
return windowIsOpening; return windowIsOpening;
}, },
show: async () => { open: async () => {
if (!browserWindow) { if (!browserWindow) {
windowIsOpening = true; windowIsOpening = true;
browserWindow = createElectronWindow({ browserWindow = createElectronWindow({
...configuration, ...configuration,
onClose: () => browserWindow = undefined, onClose: () => {
browserWindow = undefined;
windowIsShown = false;
},
}); });
const windowFilePath = configuration.getContentSource().file; const { file: filePathForContent, url: urlForContent } =
const windowUrl = configuration.getContentSource().url; configuration.getContentSource();
contentIsLoading = true; if (filePathForContent) {
await browserWindow.loadFile(filePathForContent);
if (windowFilePath) { } else if (urlForContent) {
await browserWindow.loadFile(windowFilePath); await browserWindow.loadUrl(urlForContent);
} else if (windowUrl) {
await browserWindow.loadUrl(windowUrl);
} }
await configuration.beforeOpen?.(); await configuration.beforeOpen?.();
contentIsLoading = false;
} }
browserWindow.show(); showWindow();
windowIsOpening = false; windowIsOpening = false;
}, },
show: showWindow,
close: () => { close: () => {
browserWindow?.close(); browserWindow?.close();
browserWindow = undefined; browserWindow = undefined;
windowIsShown = false;
}, },
send: (args: SendToViewArgs) => { send: (args: SendToViewArgs) => {

View File

@ -13,8 +13,9 @@ export interface SendToViewArgs {
export interface LensWindow { export interface LensWindow {
id: string; id: string;
show: () => Promise<void>; open: () => Promise<void>;
close: () => void; close: () => void;
show: () => void;
send: (args: SendToViewArgs) => void; send: (args: SendToViewArgs) => void;
visible: boolean; visible: boolean;
opening: boolean; opening: boolean;

View File

@ -13,14 +13,18 @@ const showApplicationWindowInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const applicationWindow = di.inject(applicationWindowInjectable); const applicationWindow = di.inject(applicationWindowInjectable);
const splashWindow = di.inject(splashWindowInjectable); const splashWindow = di.inject(splashWindowInjectable);
return async () => { return async () => {
if (applicationWindow.opening) {
applicationWindow.show();
splashWindow.close();
return;
}
const windowIsAlreadyBeingShown = someIsTruthy([ const windowIsAlreadyBeingShown = someIsTruthy([
applicationWindow.visible, applicationWindow.visible,
applicationWindow.opening,
splashWindow.visible,
splashWindow.opening, splashWindow.opening,
]); ]);
@ -28,9 +32,9 @@ const showApplicationWindowInjectable = getInjectable({
return; return;
} }
await splashWindow.show(); await splashWindow.open();
await applicationWindow.show(); await applicationWindow.open();
splashWindow.close(); splashWindow.close();
}; };

View File

@ -49,7 +49,7 @@ const startMainApplicationInjectable = getInjectable({
await beforeApplicationIsLoading(); await beforeApplicationIsLoading();
if (!shouldStartHidden) { if (!shouldStartHidden) {
await splashWindow.show(); await splashWindow.open();
} }
await onLoadOfApplication(); await onLoadOfApplication();
@ -60,7 +60,7 @@ const startMainApplicationInjectable = getInjectable({
if (deepLinkUrl) { if (deepLinkUrl) {
await openDeepLink(deepLinkUrl); await openDeepLink(deepLinkUrl);
} else { } else {
await applicationWindow.show(); await applicationWindow.open();
} }
splashWindow.close(); splashWindow.close();

View File

@ -408,7 +408,7 @@ export const getApplicationBuilder = () => {
const applicationWindow = mainDi.inject(applicationWindowInjectable); const applicationWindow = mainDi.inject(applicationWindowInjectable);
await applicationWindow.show(); await applicationWindow.open();
const startFrame = rendererDi.inject(startFrameInjectable); const startFrame = rendererDi.inject(startFrameInjectable);