Skip to content

Commit

Permalink
Fix resolveSystemProxyFromElectron causing a crash on quit (#7379)
Browse files Browse the repository at this point in the history
* destroy resolve system proxy window on before quit

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* resolve system proxy window: load blank page

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* disable paintWhenInitiallyHidden

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

---------

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
  • Loading branch information
jakolehm authored Mar 20, 2023
1 parent 52ede67 commit 7ed9925
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import electronBrowserWindowInjectable from "./electron-browser-window.injectable";
import withErrorLoggingInjectable from "../../../common/utils/with-error-logging/with-error-logging.injectable";
import resolveSystemProxyWindowInjectable from "./resolve-system-proxy-window.injectable";

const resolveSystemProxyFromElectronInjectable = getInjectable({
id: "resolve-system-proxy-from-electron",

instantiate: (di) => {
const browserWindow = di.inject(electronBrowserWindowInjectable);
const helperWindow = di.inject(resolveSystemProxyWindowInjectable);
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
const withErrorLogging = withErrorLoggingFor(() => "Error resolving proxy");
const hiddenWindow = browserWindow({
show: false,
});


return withErrorLogging(async (url: string) => {
return await hiddenWindow.webContents.session.resolveProxy(url);
return await helperWindow.webContents.session.resolveProxy(url);
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import resolveSystemProxyFromElectronInjectable from "./resolve-system-proxy-from-electron.injectable";
import electronBrowserWindowInjectable from "./electron-browser-window.injectable";
import resolveSystemProxyWindowInjectable from "./resolve-system-proxy-window.injectable";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import { getPromiseStatus } from "@k8slens/test-utils";
Expand All @@ -31,8 +31,8 @@ describe("technical: resolve-system-proxy-from-electron", () => {
resolveSystemProxyMock = asyncFn();

di.override(
electronBrowserWindowInjectable,
() => () => ({
resolveSystemProxyWindowInjectable,
() => ({
webContents: {
session: {
resolveProxy: resolveSystemProxyMock,
Expand Down Expand Up @@ -72,8 +72,8 @@ describe("technical: resolve-system-proxy-from-electron", () => {
resolveSystemProxyMock = asyncFn();

di.override(
electronBrowserWindowInjectable,
() => () => ({
resolveSystemProxyWindowInjectable,
() => ({
webContents: {
session: {
resolveProxy: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { getGlobalOverride } from "@k8slens/test-utils";
import type { BrowserWindow, Session, WebContents } from "electron";
import electronBrowserWindowInjectable from "./electron-browser-window.injectable";
import resolveSystemProxyWindowInjectable from "./resolve-system-proxy-window.injectable";

export default getGlobalOverride(
electronBrowserWindowInjectable,
() => () => ({
resolveSystemProxyWindowInjectable,
() => ({
webContents: {
session: {
resolveProxy: () => "DIRECT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { BrowserWindowConstructorOptions } from "electron";
import { BrowserWindow } from "electron";

const electronBrowserWindowInjectable = getInjectable({
id: "electron-browser-window",
const resolveSystemProxyWindowInjectable = getInjectable({
id: "resolve-system-proxy-window",
instantiate: () => {
return (opts: BrowserWindowConstructorOptions) => {
return new BrowserWindow(opts);
};
return new BrowserWindow({ show: false, paintWhenInitiallyHidden: false });
},
causesSideEffects: true,
});

export default electronBrowserWindowInjectable;
export default resolveSystemProxyWindowInjectable;

0 comments on commit 7ed9925

Please sign in to comment.