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 { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { beforeApplicationIsLoadingInjectionToken } from "../../runnable-tokens/before-application-is-loading-injection-token";
|
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({
|
const setupLensProxyInjectable = getInjectable({
|
||||||
id: "setup-lens-proxy",
|
id: "setup-lens-proxy",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableStoppableInjectable);
|
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "setup-lens-proxy",
|
id: "setup-lens-proxy",
|
||||||
run: () => {
|
run: async () => {
|
||||||
setupLensProxyStartableStoppable.start();
|
await setupLensProxyStartableStoppable.start();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import loggerInjectable from "../../../../common/logger.injectable";
|
import loggerInjectable from "../../../../common/logger.injectable";
|
||||||
import { hasTypedProperty, isObject, isString } from "../../../../common/utils";
|
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 isWindowsInjectable from "../../../../common/vars/is-windows.injectable";
|
||||||
import exitAppInjectable from "../../../electron-app/features/exit-app.injectable";
|
import exitAppInjectable from "../../../electron-app/features/exit-app.injectable";
|
||||||
import showErrorPopupInjectable from "../../../electron-app/features/show-error-popup.injectable";
|
import showErrorPopupInjectable from "../../../electron-app/features/show-error-popup.injectable";
|
||||||
@ -21,8 +21,8 @@ const getErrorMessage = (error: unknown, fallback: string): string => {
|
|||||||
return fallback;
|
return fallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupLensProxyStartableStoppableInjectable = getInjectable({
|
const setupLensProxyStartableInjectable = getInjectable({
|
||||||
id: "setup-lens-proxy-startable-stoppable",
|
id: "setup-lens-proxy-startable",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const lensProxy = di.inject(lensProxyInjectable);
|
const lensProxy = di.inject(lensProxyInjectable);
|
||||||
const exitApp = di.inject(exitAppInjectable);
|
const exitApp = di.inject(exitAppInjectable);
|
||||||
@ -32,60 +32,54 @@ const setupLensProxyStartableStoppableInjectable = getInjectable({
|
|||||||
const showErrorPopup = di.inject(showErrorPopupInjectable);
|
const showErrorPopup = di.inject(showErrorPopupInjectable);
|
||||||
const buildVersion = di.inject(buildVersionInjectable);
|
const buildVersion = di.inject(buildVersionInjectable);
|
||||||
|
|
||||||
return getStartableStoppable("setup-lens-proxy", () => {
|
return getSingleStartable("setup-lens-proxy", async (signal) => {
|
||||||
const controller = new AbortController();
|
try {
|
||||||
|
logger.info("🔌 Starting LensProxy");
|
||||||
(async () => {
|
await lensProxy.listen({ signal }); // lensProxy.port available
|
||||||
try {
|
} catch (error) {
|
||||||
logger.info("🔌 Starting LensProxy");
|
if (!signal.aborted) {
|
||||||
await lensProxy.listen({ signal: controller.signal }); // lensProxy.port available
|
showErrorPopup("Lens Error", `Could not start proxy: ${getErrorMessage(error, "unknown error")}`);
|
||||||
} catch (error) {
|
exitApp();
|
||||||
if (!controller.signal.aborted) {
|
|
||||||
showErrorPopup("Lens Error", `Could not start proxy: ${getErrorMessage(error, "unknown error")}`);
|
|
||||||
exitApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test proxy connection
|
return;
|
||||||
try {
|
}
|
||||||
logger.info("🔎 Testing LensProxy connection ...");
|
|
||||||
const versionFromProxy = await requestAppVersionViaProxy({ signal: controller.signal });
|
|
||||||
|
|
||||||
if (buildVersion.get() !== versionFromProxy) {
|
// test proxy connection
|
||||||
logger.error("Proxy server responded with invalid response");
|
try {
|
||||||
|
logger.info("🔎 Testing LensProxy connection ...");
|
||||||
|
const versionFromProxy = await requestAppVersionViaProxy({ signal });
|
||||||
|
|
||||||
return exitApp();
|
if (buildVersion.get() !== versionFromProxy) {
|
||||||
}
|
logger.error("Proxy server responded with invalid response");
|
||||||
|
|
||||||
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"));
|
|
||||||
|
|
||||||
return exitApp();
|
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 { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { beforeQuitOfBackEndInjectionToken } from "../../runnable-tokens/before-quit-of-back-end-injection-token";
|
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({
|
const stopSettingUpLensProxyInjectable = getInjectable({
|
||||||
id: "stop-setting-up-lens-proxy",
|
id: "stop-setting-up-lens-proxy",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableStoppableInjectable);
|
const setupLensProxyStartableStoppable = di.inject(setupLensProxyStartableInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "stop-setting-up-lens-proxy",
|
id: "stop-setting-up-lens-proxy",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user