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) => {
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", () => {
let closeMock: jest.Mock;
beforeEach(() => {
resolveSystemProxyMock = asyncFn();
closeMock = jest.fn();
di.override(
resolveSystemProxyWindowInjectable,
async () => ({
close: closeMock,
webContents: {
session: {
resolveProxy: resolveSystemProxyMock,
@ -58,10 +63,26 @@ describe("technical: resolve-system-proxy-from-electron", () => {
expect(promiseStatus.fulfilled).toBe(false);
});
it("when call for proxy, resolves with the proxy", async () => {
resolveSystemProxyMock.resolve("some-proxy");
it("does not close the window yet", () => {
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 WebContents,
close: () => {},
} as unknown as BrowserWindow),
);

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* 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 electronAppInjectable from "../../electron-app/electron-app.injectable";
@ -22,6 +22,9 @@ const resolveSystemProxyWindowInjectable = getInjectable({
return window;
},
lifecycle: lifecycleEnum.transient,
causesSideEffects: true,
});