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([]); 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", () => { describe("when opening of splash window resolves", () => {
beforeEach(async () => { beforeEach(async () => {
await resolveOpeningOfWindow("splash"); await resolveOpeningOfWindow("splash");
@ -101,7 +113,7 @@ describe("opening application window using tray", () => {
expectWindowsToBeOpen(["only-application-window"]); 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(() => { beforeEach(() => {
createElectronWindowMock.mockClear(); createElectronWindowMock.mockClear();

View File

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

View File

@ -5,6 +5,8 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import splashWindowInjectable from "./splash-window/splash-window.injectable"; import splashWindowInjectable from "./splash-window/splash-window.injectable";
import applicationWindowInjectable from "./application-window/application-window.injectable"; import applicationWindowInjectable from "./application-window/application-window.injectable";
import { identity, some } from "lodash/fp";
const someIsTruthy = some(identity);
const showApplicationWindowInjectable = getInjectable({ const showApplicationWindowInjectable = getInjectable({
id: "show-application-window", id: "show-application-window",
@ -12,12 +14,17 @@ const showApplicationWindowInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const applicationWindow = di.inject(applicationWindowInjectable); const applicationWindow = di.inject(applicationWindowInjectable);
const splashWindow = di.inject( const splashWindow = di.inject(splashWindowInjectable);
splashWindowInjectable,
);
return async () => { return async () => {
if (applicationWindow.visible || splashWindow.visible) { const windowIsAlreadyBeingShown = someIsTruthy([
applicationWindow.visible,
applicationWindow.opening,
splashWindow.visible,
splashWindow.opening,
]);
if (windowIsAlreadyBeingShown) {
return; return;
} }