mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix starting of lens proxy
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
e49b0f61ce
commit
d173e45177
24
src/common/utils/get-startable.ts
Normal file
24
src/common/utils/get-startable.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export type Starter = (signal: AbortSignal) => Promise<void>;
|
||||
|
||||
export interface SingleStartable {
|
||||
start: () => Promise<void>;
|
||||
stop: () => void;
|
||||
}
|
||||
|
||||
export function getSingleStartable(id: string, start: Starter): SingleStartable {
|
||||
const controller = new AbortController();
|
||||
|
||||
return {
|
||||
start: async () => {
|
||||
await start(controller.signal);
|
||||
},
|
||||
stop: () => {
|
||||
controller.abort();
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -4,18 +4,18 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeApplicationIsLoadingInjectionToken } from "../../runnable-tokens/before-application-is-loading-injection-token";
|
||||
import setupLensProxyStartableStoppableInjectable from "./startable-stoppable.injectable";
|
||||
import setupLensProxyStartableInjectable from "./startable-stoppable.injectable";
|
||||
|
||||
const setupLensProxyInjectable = getInjectable({
|
||||
id: "setup-lens-proxy",
|
||||
|
||||
instantiate: (di) => {
|
||||
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableStoppableInjectable);
|
||||
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-lens-proxy",
|
||||
run: () => {
|
||||
setupLensProxyStartableStoppable.start();
|
||||
run: async () => {
|
||||
await setupLensProxyStartableStoppable.start();
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import { hasTypedProperty, isObject, isString } from "../../../../common/utils";
|
||||
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
|
||||
import { getSingleStartable } from "../../../../common/utils/get-startable";
|
||||
import isWindowsInjectable from "../../../../common/vars/is-windows.injectable";
|
||||
import exitAppInjectable from "../../../electron-app/features/exit-app.injectable";
|
||||
import showErrorPopupInjectable from "../../../electron-app/features/show-error-popup.injectable";
|
||||
@ -21,8 +21,8 @@ const getErrorMessage = (error: unknown, fallback: string): string => {
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const setupLensProxyStartableStoppableInjectable = getInjectable({
|
||||
id: "setup-lens-proxy-startable-stoppable",
|
||||
const setupLensProxyStartableInjectable = getInjectable({
|
||||
id: "setup-lens-proxy-startable",
|
||||
instantiate: (di) => {
|
||||
const lensProxy = di.inject(lensProxyInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
@ -32,60 +32,54 @@ const setupLensProxyStartableStoppableInjectable = getInjectable({
|
||||
const showErrorPopup = di.inject(showErrorPopupInjectable);
|
||||
const buildVersion = di.inject(buildVersionInjectable);
|
||||
|
||||
return getStartableStoppable("setup-lens-proxy", () => {
|
||||
const controller = new AbortController();
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
logger.info("🔌 Starting LensProxy");
|
||||
await lensProxy.listen({ signal: controller.signal }); // lensProxy.port available
|
||||
} catch (error) {
|
||||
if (!controller.signal.aborted) {
|
||||
showErrorPopup("Lens Error", `Could not start proxy: ${getErrorMessage(error, "unknown error")}`);
|
||||
exitApp();
|
||||
}
|
||||
|
||||
return;
|
||||
return getSingleStartable("setup-lens-proxy", async (signal) => {
|
||||
try {
|
||||
logger.info("🔌 Starting LensProxy");
|
||||
await lensProxy.listen({ signal }); // lensProxy.port available
|
||||
} catch (error) {
|
||||
if (!signal.aborted) {
|
||||
showErrorPopup("Lens Error", `Could not start proxy: ${getErrorMessage(error, "unknown error")}`);
|
||||
exitApp();
|
||||
}
|
||||
|
||||
// test proxy connection
|
||||
try {
|
||||
logger.info("🔎 Testing LensProxy connection ...");
|
||||
const versionFromProxy = await requestAppVersionViaProxy({ signal: controller.signal });
|
||||
return;
|
||||
}
|
||||
|
||||
if (buildVersion.get() !== versionFromProxy) {
|
||||
logger.error("Proxy server responded with invalid response");
|
||||
// test proxy connection
|
||||
try {
|
||||
logger.info("🔎 Testing LensProxy connection ...");
|
||||
const versionFromProxy = await requestAppVersionViaProxy({ signal });
|
||||
|
||||
return exitApp();
|
||||
}
|
||||
|
||||
logger.info("⚡ LensProxy connection OK");
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.error(`🛑 LensProxy: failed connection test: ${error}`);
|
||||
|
||||
const hostsPath = isWindows
|
||||
? "C:\\windows\\system32\\drivers\\etc\\hosts"
|
||||
: "/etc/hosts";
|
||||
const message = [
|
||||
`Failed connection test: ${error}`,
|
||||
"Check to make sure that no other versions of Lens are running",
|
||||
`Check ${hostsPath} to make sure that it is clean and that the localhost loopback is at the top and set to 127.0.0.1`,
|
||||
"If you have HTTP_PROXY or http_proxy set in your environment, make sure that the localhost and the ipv4 loopback address 127.0.0.1 are added to the NO_PROXY environment variable.",
|
||||
];
|
||||
|
||||
showErrorPopup("Lens Proxy Error", message.join("\n\n"));
|
||||
if (buildVersion.get() !== versionFromProxy) {
|
||||
logger.error("Proxy server responded with invalid response");
|
||||
|
||||
return exitApp();
|
||||
}
|
||||
})();
|
||||
|
||||
return () => controller.abort();
|
||||
logger.info("⚡ LensProxy connection OK");
|
||||
} catch (error) {
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.error(`🛑 LensProxy: failed connection test: ${error}`);
|
||||
|
||||
const hostsPath = isWindows
|
||||
? "C:\\windows\\system32\\drivers\\etc\\hosts"
|
||||
: "/etc/hosts";
|
||||
const message = [
|
||||
`Failed connection test: ${error}`,
|
||||
"Check to make sure that no other versions of Lens are running",
|
||||
`Check ${hostsPath} to make sure that it is clean and that the localhost loopback is at the top and set to 127.0.0.1`,
|
||||
"If you have HTTP_PROXY or http_proxy set in your environment, make sure that the localhost and the ipv4 loopback address 127.0.0.1 are added to the NO_PROXY environment variable.",
|
||||
];
|
||||
|
||||
showErrorPopup("Lens Proxy Error", message.join("\n\n"));
|
||||
|
||||
return exitApp();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default setupLensProxyStartableStoppableInjectable;
|
||||
export default setupLensProxyStartableInjectable;
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../runnable-tokens/before-quit-of-back-end-injection-token";
|
||||
import setupLensProxyStartableStoppableInjectable from "./startable-stoppable.injectable";
|
||||
import setupLensProxyStartableInjectable from "./startable-stoppable.injectable";
|
||||
|
||||
const stopSettingUpLensProxyInjectable = getInjectable({
|
||||
id: "stop-setting-up-lens-proxy",
|
||||
instantiate: (di) => {
|
||||
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableStoppableInjectable);
|
||||
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableInjectable);
|
||||
|
||||
return {
|
||||
id: "stop-setting-up-lens-proxy",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user