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,15 +32,12 @@ 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();
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
try {
|
||||||
logger.info("🔌 Starting LensProxy");
|
logger.info("🔌 Starting LensProxy");
|
||||||
await lensProxy.listen({ signal: controller.signal }); // lensProxy.port available
|
await lensProxy.listen({ signal }); // lensProxy.port available
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!controller.signal.aborted) {
|
if (!signal.aborted) {
|
||||||
showErrorPopup("Lens Error", `Could not start proxy: ${getErrorMessage(error, "unknown error")}`);
|
showErrorPopup("Lens Error", `Could not start proxy: ${getErrorMessage(error, "unknown error")}`);
|
||||||
exitApp();
|
exitApp();
|
||||||
}
|
}
|
||||||
@ -51,7 +48,7 @@ const setupLensProxyStartableStoppableInjectable = getInjectable({
|
|||||||
// test proxy connection
|
// test proxy connection
|
||||||
try {
|
try {
|
||||||
logger.info("🔎 Testing LensProxy connection ...");
|
logger.info("🔎 Testing LensProxy connection ...");
|
||||||
const versionFromProxy = await requestAppVersionViaProxy({ signal: controller.signal });
|
const versionFromProxy = await requestAppVersionViaProxy({ signal });
|
||||||
|
|
||||||
if (buildVersion.get() !== versionFromProxy) {
|
if (buildVersion.get() !== versionFromProxy) {
|
||||||
logger.error("Proxy server responded with invalid response");
|
logger.error("Proxy server responded with invalid response");
|
||||||
@ -61,7 +58,7 @@ const setupLensProxyStartableStoppableInjectable = getInjectable({
|
|||||||
|
|
||||||
logger.info("⚡ LensProxy connection OK");
|
logger.info("⚡ LensProxy connection OK");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (controller.signal.aborted) {
|
if (signal.aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +78,8 @@ const setupLensProxyStartableStoppableInjectable = getInjectable({
|
|||||||
|
|
||||||
return exitApp();
|
return exitApp();
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
return () => controller.abort();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
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