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

Kludge fix for application crash when quitting (#7463)

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-04-03 16:53:21 +03:00 committed by GitHub
parent 04fbcd4eee
commit 1195c82a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 6 deletions

View File

@ -16,7 +16,11 @@ const resolveSystemProxyFromElectronInjectable = getInjectable({
return withErrorLogging(async (url: string) => { return withErrorLogging(async (url: string) => {
const helperWindow = await di.inject(resolveSystemProxyWindowInjectable); const helperWindow = await di.inject(resolveSystemProxyWindowInjectable);
return await helperWindow.webContents.session.resolveProxy(url); const proxy = await helperWindow.webContents.session.resolveProxy(url);
helperWindow.close();
return proxy;
}); });
}, },
}); });

View File

@ -27,12 +27,17 @@ describe("technical: resolve-system-proxy-from-electron", () => {
}); });
describe("given there are no unexpected issues, when called with URL", () => { describe("given there are no unexpected issues, when called with URL", () => {
let closeMock: jest.Mock;
beforeEach(() => { beforeEach(() => {
resolveSystemProxyMock = asyncFn(); resolveSystemProxyMock = asyncFn();
closeMock = jest.fn();
di.override( di.override(
resolveSystemProxyWindowInjectable, resolveSystemProxyWindowInjectable,
async () => ({ async () => ({
close: closeMock,
webContents: { webContents: {
session: { session: {
resolveProxy: resolveSystemProxyMock, resolveProxy: resolveSystemProxyMock,
@ -58,10 +63,26 @@ describe("technical: resolve-system-proxy-from-electron", () => {
expect(promiseStatus.fulfilled).toBe(false); expect(promiseStatus.fulfilled).toBe(false);
}); });
it("when call for proxy, resolves with the proxy", async () => { it("does not close the window yet", () => {
resolveSystemProxyMock.resolve("some-proxy"); expect(closeMock).not.toHaveBeenCalled();
});
expect(await actualPromise).toBe("some-proxy"); describe("when call for proxy resolves", () => {
beforeEach(async () => {
await resolveSystemProxyMock.resolve("some-proxy");
});
it("closes the window", () => {
expect(closeMock).toHaveBeenCalled();
});
it("resolves with the proxy", async () => {
const actual = await actualPromise;
expect(actual).toBe("some-proxy");
});
}); });
}); });
@ -81,6 +102,8 @@ describe("technical: resolve-system-proxy-from-electron", () => {
}, },
} as unknown as Session, } as unknown as Session,
} as unknown as WebContents, } as unknown as WebContents,
close: () => {},
} as unknown as BrowserWindow), } as unknown as BrowserWindow),
); );

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { BrowserWindow } from "electron"; import { BrowserWindow } from "electron";
import electronAppInjectable from "../../electron-app/electron-app.injectable"; import electronAppInjectable from "../../electron-app/electron-app.injectable";
@ -22,6 +22,9 @@ const resolveSystemProxyWindowInjectable = getInjectable({
return window; return window;
}, },
lifecycle: lifecycleEnum.transient,
causesSideEffects: true, causesSideEffects: true,
}); });