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");
});
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();

View File

@ -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) => {

View File

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

View File

@ -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();
};

View File

@ -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();

View File

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