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

Fix resolveSystemProxyFromElectron causing a crash on quit (#7379)

* 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>
Signed-off-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
Jari Kolehmainen 2023-03-20 15:25:04 +02:00 committed by Gabriel
parent d322b9511a
commit 6b99b46302
4 changed files with 16 additions and 22 deletions

View File

@ -3,22 +3,19 @@
* 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 } from "@ogre-tools/injectable";
import electronBrowserWindowInjectable from "./electron-browser-window.injectable";
import withErrorLoggingInjectable from "../../../common/utils/with-error-logging/with-error-logging.injectable"; import withErrorLoggingInjectable from "../../../common/utils/with-error-logging/with-error-logging.injectable";
import resolveSystemProxyWindowInjectable from "./resolve-system-proxy-window.injectable";
const resolveSystemProxyFromElectronInjectable = getInjectable({ const resolveSystemProxyFromElectronInjectable = getInjectable({
id: "resolve-system-proxy-from-electron", id: "resolve-system-proxy-from-electron",
instantiate: (di) => { instantiate: (di) => {
const browserWindow = di.inject(electronBrowserWindowInjectable); const helperWindow = di.inject(resolveSystemProxyWindowInjectable);
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable); const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
const withErrorLogging = withErrorLoggingFor(() => "Error resolving proxy"); const withErrorLogging = withErrorLoggingFor(() => "Error resolving proxy");
const hiddenWindow = browserWindow({
show: false,
});
return withErrorLogging(async (url: string) => { return withErrorLogging(async (url: string) => {
return await hiddenWindow.webContents.session.resolveProxy(url); return await helperWindow.webContents.session.resolveProxy(url);
}); });
}, },
}); });

View File

@ -5,7 +5,7 @@
import { getDiForUnitTesting } from "../../getDiForUnitTesting"; import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import resolveSystemProxyFromElectronInjectable from "./resolve-system-proxy-from-electron.injectable"; 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 type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest"; import asyncFn from "@async-fn/jest";
import { getPromiseStatus } from "@k8slens/test-utils"; import { getPromiseStatus } from "@k8slens/test-utils";
@ -31,8 +31,8 @@ describe("technical: resolve-system-proxy-from-electron", () => {
resolveSystemProxyMock = asyncFn(); resolveSystemProxyMock = asyncFn();
di.override( di.override(
electronBrowserWindowInjectable, resolveSystemProxyWindowInjectable,
() => () => ({ () => ({
webContents: { webContents: {
session: { session: {
resolveProxy: resolveSystemProxyMock, resolveProxy: resolveSystemProxyMock,
@ -72,8 +72,8 @@ describe("technical: resolve-system-proxy-from-electron", () => {
resolveSystemProxyMock = asyncFn(); resolveSystemProxyMock = asyncFn();
di.override( di.override(
electronBrowserWindowInjectable, resolveSystemProxyWindowInjectable,
() => () => ({ () => ({
webContents: { webContents: {
session: { session: {
resolveProxy: () => { resolveProxy: () => {

View File

@ -5,11 +5,11 @@
import { getGlobalOverride } from "@k8slens/test-utils"; import { getGlobalOverride } from "@k8slens/test-utils";
import type { BrowserWindow, Session, WebContents } from "electron"; 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( export default getGlobalOverride(
electronBrowserWindowInjectable, resolveSystemProxyWindowInjectable,
() => () => ({ () => ({
webContents: { webContents: {
session: { session: {
resolveProxy: () => "DIRECT", resolveProxy: () => "DIRECT",

View File

@ -3,17 +3,14 @@
* 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 } from "@ogre-tools/injectable";
import type { BrowserWindowConstructorOptions } from "electron";
import { BrowserWindow } from "electron"; import { BrowserWindow } from "electron";
const electronBrowserWindowInjectable = getInjectable({ const resolveSystemProxyWindowInjectable = getInjectable({
id: "electron-browser-window", id: "resolve-system-proxy-window",
instantiate: () => { instantiate: () => {
return (opts: BrowserWindowConstructorOptions) => { return new BrowserWindow({ show: false, paintWhenInitiallyHidden: false });
return new BrowserWindow(opts);
};
}, },
causesSideEffects: true, causesSideEffects: true,
}); });
export default electronBrowserWindowInjectable; export default resolveSystemProxyWindowInjectable;