Skip to content

Commit

Permalink
Kludge fix for application crash when quitting (#7463)
Browse files Browse the repository at this point in the history
Signed-off-by: Janne Savolainen <[email protected]>
  • Loading branch information
jansav authored Apr 3, 2023
1 parent 04fbcd4 commit 1195c82
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ const resolveSystemProxyFromElectronInjectable = getInjectable({
instantiate: (di) => {
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
const withErrorLogging = withErrorLoggingFor(() => "Error resolving proxy");

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;
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
});

describe("when call for proxy resolves", () => {
beforeEach(async () => {

await resolveSystemProxyMock.resolve("some-proxy");

expect(await actualPromise).toBe("some-proxy");
});

it("closes the window", () => {
expect(closeMock).toHaveBeenCalled();
});

it("resolves with the proxy", async () => {
const actual = await actualPromise;

expect(actual).toBe("some-proxy");
});
});
});

Expand All @@ -81,6 +102,8 @@ describe("technical: resolve-system-proxy-from-electron", () => {
},
} as unknown as Session,
} as unknown as WebContents,

close: () => {},
} as unknown as BrowserWindow),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -22,6 +22,9 @@ const resolveSystemProxyWindowInjectable = getInjectable({

return window;
},

lifecycle: lifecycleEnum.transient,

causesSideEffects: true,
});

Expand Down

0 comments on commit 1195c82

Please sign in to comment.