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

Make sure bug about opening involuntary duplicate app windows is solved in all scenarios

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Iku-turso 2022-06-01 15:41:38 +03:00 committed by Janne Savolainen
parent 3770183088
commit 7b043afe42
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
4 changed files with 36 additions and 5 deletions

View File

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

View File

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

View File

@ -17,6 +17,7 @@ export interface LensWindow {
close: () => void;
send: (args: SendToViewArgs) => void;
visible: boolean;
opening: boolean;
}
export const lensWindowInjectionToken = getInjectionToken<LensWindow>({

View File

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