Convert runMany and runManySync to use injectManyWithMeta + move to seperate package (#7244)

* Convert runMany and runManySync to use injectManyWithMeta

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup type errors due to new Runnable requirements

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add documentation for verifyRunnablesAreDAG

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Simplify convertToWithIdWith

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move all utility functions to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move testing utilities to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move run-many and run-many-sync to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Replace all internal uses of utilities with new packages

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Use new @k8slens/run-many package in core

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add dep to open-lens

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup uses of @k8slens/test-utils

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup getGlobalOverride

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move tests to new package too

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup uses of AsyncResult and autoBind

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup remaining import issues

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Finial fixups to fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Revert moving "testUsingFakeTime" to separate package

- This fixes tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix integration tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix unit test failing due to spelling fix

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-10 10:07:28 +02:00
1 parent ad9bafe2a5
commit 2789bcebcb
754 files changed
+2715 -2752

No files matched your search

@@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import { getGlobalOverride } from "@k8slens/test-utils";
import createElectronWindowInjectable from "./create-electron-window.injectable";
export default getGlobalOverride(createElectronWindowInjectable, () => () => ({
@@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token";
import { bundledExtensionsLoaded } from "../../../../common/ipc/extension-handling";
import { delay } from "../../../../common/utils";
import { delay } from "@k8slens/utilities";
const waitUntilBundledExtensionsAreLoadedInjectable = getInjectable({
id: "wait-until-bundled-extensions-are-loaded",
@@ -2,23 +2,16 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { pipeline } from "@ogre-tools/fp";
import { getInjectable } from "@ogre-tools/injectable";
import { filter } from "lodash/fp";
import { applicationWindowInjectionToken } from "./application-window/application-window-injection-token";
const getVisibleWindowsInjectable = getInjectable({
id: "get-visible-windows",
instantiate: (di) => {
const getAllLensWindows = () => di.injectMany(applicationWindowInjectionToken);
return () =>
pipeline(
getAllLensWindows(),
filter((lensWindow) => !!lensWindow.isVisible),
);
},
instantiate: (di) => () => (
di.injectMany(applicationWindowInjectionToken)
.filter(window => window.isVisible)
),
});
export default getVisibleWindowsInjectable;
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { iter } from "../../../common/utils";
import { iter } from "@k8slens/utilities";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
import showApplicationWindowInjectable from "./show-application-window.injectable";
import getCurrentApplicationWindowInjectable from "./application-window/get-current-application-window.injectable";
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { iter } from "../../../common/utils";
import { iter } from "@k8slens/utilities";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
import { IpcRendererNavigationEvents } from "../../../common/ipc/navigation-events";
import showApplicationWindowInjectable from "./show-application-window.injectable";
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Runnable } from "../../../common/runnable/run-many-for";
export const afterApplicationIsLoadedInjectionToken = getInjectionToken<Runnable>({
id: "after-application-is-loaded",
});
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Runnable } from "../../../common/runnable/run-many-for";
export const afterRootFrameIsReadyInjectionToken = getInjectionToken<Runnable>({
id: "after-root-frame-is-ready",
});
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Runnable } from "../../../common/runnable/run-many-for";
export const afterWindowIsOpenedInjectionToken = getInjectionToken<Runnable>({
id: "after-window-is-opened",
});
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Runnable } from "../../../common/runnable/run-many-for";
export const beforeApplicationIsLoadingInjectionToken = getInjectionToken<Runnable>({
id: "before-application-is-loading",
});
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { RunnableSync } from "../../../common/runnable/run-many-sync-for";
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<RunnableSync>({
id: "before-quit-of-back-end",
});
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { RunnableSync } from "../../../common/runnable/run-many-sync-for";
export const beforeQuitOfFrontEndInjectionToken = getInjectionToken<RunnableSync>({
id: "before-quit-of-front-end",
});
@@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Runnable } from "../../../common/runnable/run-many-for";
export const onLoadOfApplicationInjectionToken = getInjectionToken<Runnable>({
id: "on-load-of-application",
});
@@ -0,0 +1,27 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Runnable, RunnableSync } from "@k8slens/run-many";
export const beforeQuitOfFrontEndInjectionToken = getInjectionToken<RunnableSync>({
id: "before-quit-of-front-end",
});
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<RunnableSync>({
id: "before-quit-of-back-end",
});
export const afterWindowIsOpenedInjectionToken = getInjectionToken<Runnable>({
id: "after-window-is-opened",
});
export const afterRootFrameIsReadyInjectionToken = getInjectionToken<Runnable>({
id: "after-root-frame-is-ready",
});
export const afterApplicationIsLoadedInjectionToken = getInjectionToken<Runnable>({
id: "after-application-is-loaded",
});
@@ -3,14 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeQuitOfBackEndInjectionToken } from "../runnable-tokens/before-quit-of-back-end-injection-token";
import { beforeQuitOfBackEndInjectionToken } from "../runnable-tokens/phases";
import { ShellSession } from "../../shell-session/shell-session";
const cleanUpShellSessionsInjectable = getInjectable({
id: "clean-up-shell-sessions",
instantiate: () => ({
id: "clean-up-shell-sessions",
run: () => void ShellSession.cleanup(),
}),
@@ -4,23 +4,20 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
import { beforeQuitOfFrontEndInjectionToken } from "../runnable-tokens/before-quit-of-front-end-injection-token";
import { beforeQuitOfFrontEndInjectionToken } from "../runnable-tokens/phases";
const emitCloseToEventBusInjectable = getInjectable({
id: "emit-close-to-event-bus",
instantiate: (di) => {
const emitAppEvent = di.inject(emitAppEventInjectable);
instantiate: (di) => ({
run: () => {
const emitAppEvent = di.inject(emitAppEventInjectable);
return {
id: "emit-close-to-event-bus",
run: () => {
emitAppEvent({ name: "app", action: "close" });
emitAppEvent({ name: "app", action: "close" });
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeQuitOfFrontEndInjectionToken,
});
@@ -9,16 +9,13 @@ import { afterApplicationIsLoadedInjectionToken } from "@k8slens/application";
const emitServiceStartToEventBusInjectable = getInjectable({
id: "emit-service-start-to-event-bus",
instantiate: (di) => {
const emitAppEvent = di.inject(emitAppEventInjectable);
instantiate: (di) => ({
run: () => {
const emitAppEvent = di.inject(emitAppEventInjectable);
return {
id: "emit-service-start-to-event-bus",
run: () => {
emitAppEvent({ name: "service", action: "start" });
},
};
},
emitAppEvent({ name: "service", action: "start" });
},
}),
injectionToken: afterApplicationIsLoadedInjectionToken,
});
@@ -3,26 +3,23 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/after-root-frame-is-ready-injection-token";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phases";
import lensProtocolRouterMainInjectable from "../../../protocol-handler/lens-protocol-router-main/lens-protocol-router-main.injectable";
import { runInAction } from "mobx";
const flagRendererAsLoadedInjectable = getInjectable({
id: "flag-renderer-as-loaded",
instantiate: (di) => {
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
instantiate: (di) => ({
run: () => {
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
return {
id: "flag-renderer-as-loaded",
run: () => {
runInAction(() => {
// Todo: remove this kludge which enables out-of-place temporal dependency.
lensProtocolRouterMain.rendererLoaded = true;
});
},
};
},
runInAction(() => {
// Todo: remove this kludge which enables out-of-place temporal dependency.
lensProtocolRouterMain.rendererLoaded = true;
});
},
}),
injectionToken: afterRootFrameIsReadyInjectionToken,
});
@@ -5,26 +5,23 @@
import { getInjectable } from "@ogre-tools/injectable";
import { runInAction } from "mobx";
import lensProtocolRouterMainInjectable from "../../../protocol-handler/lens-protocol-router-main/lens-protocol-router-main.injectable";
import { beforeQuitOfFrontEndInjectionToken } from "../../runnable-tokens/before-quit-of-front-end-injection-token";
import { beforeQuitOfFrontEndInjectionToken } from "../../runnable-tokens/phases";
const flagRendererAsNotLoadedInjectable = getInjectable({
id: "stop-deep-linking",
instantiate: (di) => {
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
instantiate: (di) => ({
run: () => {
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
return {
id: "stop-deep-linking",
run: () => {
runInAction(() => {
// Todo: remove this kludge which enables out-of-place temporal dependency.
lensProtocolRouterMain.rendererLoaded = false;
});
runInAction(() => {
// Todo: remove this kludge which enables out-of-place temporal dependency.
lensProtocolRouterMain.rendererLoaded = false;
});
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeQuitOfFrontEndInjectionToken,
});
@@ -14,51 +14,46 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
const initializeExtensionsInjectable = getInjectable({
id: "initialize-extensions",
instantiate: (di) => {
const logger = di.inject(loggerInjectable);
const extensionDiscovery = di.inject(extensionDiscoveryInjectable);
const extensionLoader = di.inject(extensionLoaderInjectable);
const showErrorPopup = di.inject(showErrorPopupInjectable);
instantiate: (di) => ({
run: async () => {
const logger = di.inject(loggerInjectable);
const extensionDiscovery = di.inject(extensionDiscoveryInjectable);
const extensionLoader = di.inject(extensionLoaderInjectable);
const showErrorPopup = di.inject(showErrorPopupInjectable);
return {
id: "initialize-extensions",
run: async () => {
logger.info("🧩 Initializing extensions");
logger.info("🧩 Initializing extensions");
await extensionDiscovery.init();
await extensionDiscovery.init();
await extensionLoader.init();
await extensionLoader.init();
try {
const extensions = await extensionDiscovery.load();
try {
const extensions = await extensionDiscovery.load();
// Start watching after bundled extensions are loaded
extensionDiscovery.watchExtensions();
// Start watching after bundled extensions are loaded
extensionDiscovery.watchExtensions();
// Subscribe to extensions that are copied or deleted to/from the extensions folder
extensionDiscovery.events
.on("add", (extension: InstalledExtension) => {
extensionLoader.addExtension(extension);
})
.on("remove", (lensExtensionId: LensExtensionId) => {
extensionLoader.removeExtension(lensExtensionId);
});
// Subscribe to extensions that are copied or deleted to/from the extensions folder
extensionDiscovery.events
.on("add", (extension: InstalledExtension) => {
extensionLoader.addExtension(extension);
})
.on("remove", (lensExtensionId: LensExtensionId) => {
extensionLoader.removeExtension(lensExtensionId);
});
extensionLoader.initExtensions(extensions);
} catch (error: any) {
showErrorPopup(
"Lens Error",
`Could not load extensions${
error?.message ? `: ${error.message}` : ""
}`,
);
extensionLoader.initExtensions(extensions);
} catch (error: any) {
showErrorPopup(
"Lens Error",
`Could not load extensions${error?.message ? `: ${error.message}` : ""}`,
);
console.error(error);
console.trace();
}
},
};
},
console.error(error);
console.trace();
}
},
}),
causesSideEffects: true,
@@ -9,17 +9,14 @@ import { afterApplicationIsLoadedInjectionToken } from "@k8slens/application";
const addKubeconfigSyncAsEntitySourceInjectable = getInjectable({
id: "add-kubeconfig-sync-as-entity-source",
instantiate: (di) => {
const kubeConfigSyncManager = di.inject(kubeconfigSyncManagerInjectable);
const entityRegistry = di.inject(catalogEntityRegistryInjectable);
instantiate: (di) => ({
run: () => {
const kubeConfigSyncManager = di.inject(kubeconfigSyncManagerInjectable);
const entityRegistry = di.inject(catalogEntityRegistryInjectable);
return {
id: "add-kubeconfig-sync-as-entity-source",
run: () => {
entityRegistry.addComputedSource("kubeconfig-sync", kubeConfigSyncManager.source);
},
};
},
entityRegistry.addComputedSource("kubeconfig-sync", kubeConfigSyncManager.source);
},
}),
injectionToken: afterApplicationIsLoadedInjectionToken,
});
@@ -12,21 +12,18 @@ import addKubeconfigSyncAsEntitySourceInjectable from "./add-source.injectable";
const startKubeConfigSyncInjectable = getInjectable({
id: "start-kubeconfig-sync",
instantiate: (di) => {
const directoryForKubeConfigs = di.inject(directoryForKubeConfigsInjectable);
const kubeConfigSyncManager = di.inject(kubeconfigSyncManagerInjectable);
const ensureDir = di.inject(ensureDirInjectable);
instantiate: (di) => ({
run: async () => {
const directoryForKubeConfigs = di.inject(directoryForKubeConfigsInjectable);
const kubeConfigSyncManager = di.inject(kubeconfigSyncManagerInjectable);
const ensureDir = di.inject(ensureDirInjectable);
return {
id: "start-kubeconfig-sync",
run: async () => {
await ensureDir(directoryForKubeConfigs);
await ensureDir(directoryForKubeConfigs);
kubeConfigSyncManager.startSync();
},
runAfter: di.inject(addKubeconfigSyncAsEntitySourceInjectable),
};
},
kubeConfigSyncManager.startSync();
},
runAfter: addKubeconfigSyncAsEntitySourceInjectable,
}),
injectionToken: afterApplicationIsLoadedInjectionToken,
});
@@ -3,20 +3,21 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeQuitOfBackEndInjectionToken } from "../../runnable-tokens/before-quit-of-back-end-injection-token";
import { beforeQuitOfBackEndInjectionToken } from "../../runnable-tokens/phases";
import kubeconfigSyncManagerInjectable from "../../../catalog-sources/kubeconfig-sync/manager.injectable";
const stopKubeConfigSyncInjectable = getInjectable({
id: "stop-kube-config-sync",
instantiate: (di) => {
const kubeConfigSyncManager = di.inject(kubeconfigSyncManagerInjectable);
instantiate: (di) => ({
run: () => {
const kubeConfigSyncManager = di.inject(kubeconfigSyncManagerInjectable);
return {
id: "stop-kube-config-sync",
run: () => void kubeConfigSyncManager.stopSync(),
};
},
kubeConfigSyncManager.stopSync();
return undefined;
},
}),
injectionToken: beforeQuitOfBackEndInjectionToken,
});
@@ -4,8 +4,8 @@
*/
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
import { rootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel";
import { runManyFor } from "../../../../common/runnable/run-many-for";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/after-root-frame-is-ready-injection-token";
import { runManyFor } from "@k8slens/run-many";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phases";
const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "action",
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import { getGlobalOverride } from "@k8slens/test-utils";
import initializeSentryOnMainInjectable from "./initialize-on-main.injectable";
export default getGlobalOverride(initializeSentryOnMainInjectable, () => () => {});
@@ -9,15 +9,16 @@ import initializeSentryOnMainInjectable from "./initialize-on-main.injectable";
const setupSentryInjectable = getInjectable({
id: "setup-sentry",
instantiate: (di) => {
const initializeSentryReportingWith = di.inject(initializeSentryReportingWithInjectable);
const initializeSentryOnMain = di.inject(initializeSentryOnMainInjectable);
instantiate: (di) => ({
run: () => {
const initializeSentryReportingWith = di.inject(initializeSentryReportingWithInjectable);
const initializeSentryOnMain = di.inject(initializeSentryOnMainInjectable);
return {
id: "setup-sentry",
run: () => void initializeSentryReportingWith(initializeSentryOnMain),
};
},
initializeSentryReportingWith(initializeSentryOnMain);
return undefined;
},
}),
injectionToken: beforeElectronIsReadyInjectionToken,
});
@@ -10,21 +10,18 @@ import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-el
const setupHardwareAccelerationInjectable = getInjectable({
id: "setup-hardware-acceleration",
instantiate: (di) => {
const hardwareAccelerationShouldBeDisabled = di.inject(hardwareAccelerationShouldBeDisabledInjectable);
const disableHardwareAcceleration = di.inject(disableHardwareAccelerationInjectable);
instantiate: (di) => ({
run: () => {
const hardwareAccelerationShouldBeDisabled = di.inject(hardwareAccelerationShouldBeDisabledInjectable);
const disableHardwareAcceleration = di.inject(disableHardwareAccelerationInjectable);
return {
id: "setup-hardware-acceleration",
run: () => {
if (hardwareAccelerationShouldBeDisabled) {
disableHardwareAcceleration();
}
if (hardwareAccelerationShouldBeDisabled) {
disableHardwareAcceleration();
}
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeElectronIsReadyInjectionToken,
});
@@ -9,22 +9,19 @@ import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-el
const setupHostnamesInjectable = getInjectable({
id: "setup-hostnames",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
instantiate: (di) => ({
run: () => {
const app = di.inject(electronAppInjectable);
return {
id: "setup-hostnames",
run: () => {
app.commandLine.appendSwitch("host-rules", [
"MAP localhost 127.0.0.1",
"MAP lens.app 127.0.0.1",
"MAP *.lens.app 127.0.0.1",
].join());
app.commandLine.appendSwitch("host-rules", [
"MAP localhost 127.0.0.1",
"MAP lens.app 127.0.0.1",
"MAP *.lens.app 127.0.0.1",
].join());
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeElectronIsReadyInjectionToken,
});
@@ -3,19 +3,18 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import * as Immer from "immer";
import { setAutoFreeze, enableMapSet } from "immer";
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
const setupImmerInjectable = getInjectable({
id: "setup-immer",
instantiate: () => ({
id: "setup-immer",
run: () => {
// Docs: https://immerjs.github.io/immer/
// Required in `utils/storage-helper.ts`
Immer.setAutoFreeze(false); // allow to merge mobx observables
Immer.enableMapSet(); // allow to merge maps and sets
setAutoFreeze(false); // allow to merge mobx observables
enableMapSet(); // allow to merge maps and sets
return undefined;
},
@@ -10,42 +10,39 @@ import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-el
const setupLensProxyCertificateInjectable = getInjectable({
id: "setup-lens-proxy-certificate",
instantiate: (di) => {
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
instantiate: (di) => ({
run: () => {
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
return {
id: "setup-lens-proxy-certificate",
run: () => {
const cert = generate([
{ name: "commonName", value: "Lens Certificate Authority" },
{ name: "organizationName", value: "Lens" },
], {
keySize: 2048,
algorithm: "sha256",
days: 365,
extensions: [
{
name: "basicConstraints",
cA: true,
},
{
name: "subjectAltName",
altNames: [
{ type: 2, value: "*.lens.app" },
{ type: 2, value: "lens.app" },
{ type: 2, value: "localhost" },
{ type: 7, ip: "127.0.0.1" },
],
},
],
});
const cert = generate([
{ name: "commonName", value: "Lens Certificate Authority" },
{ name: "organizationName", value: "Lens" },
], {
keySize: 2048,
algorithm: "sha256",
days: 365,
extensions: [
{
name: "basicConstraints",
cA: true,
},
{
name: "subjectAltName",
altNames: [
{ type: 2, value: "*.lens.app" },
{ type: 2, value: "lens.app" },
{ type: 2, value: "localhost" },
{ type: 7, ip: "127.0.0.1" },
],
},
],
});
lensProxyCertificate.set(cert);
lensProxyCertificate.set(cert);
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeElectronIsReadyInjectionToken,
});
@@ -19,68 +19,65 @@ import { Agent } from "https";
const setupLensProxyInjectable = getInjectable({
id: "setup-lens-proxy",
instantiate: (di) => {
const lensProxy = di.inject(lensProxyInjectable);
const exitApp = di.inject(exitAppInjectable);
const logger = di.inject(loggerInjectable);
const lensProxyPort = di.inject(lensProxyPortInjectable);
const isWindows = di.inject(isWindowsInjectable);
const showErrorPopup = di.inject(showErrorPopupInjectable);
const buildVersion = di.inject(buildVersionInjectable);
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
const fetch = di.inject(fetchInjectable);
instantiate: (di) => ({
run: async () => {
const lensProxy = di.inject(lensProxyInjectable);
const exitApp = di.inject(exitAppInjectable);
const logger = di.inject(loggerInjectable);
const lensProxyPort = di.inject(lensProxyPortInjectable);
const isWindows = di.inject(isWindowsInjectable);
const showErrorPopup = di.inject(showErrorPopupInjectable);
const buildVersion = di.inject(buildVersionInjectable);
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
const fetch = di.inject(fetchInjectable);
return {
id: "setup-lens-proxy",
run: async () => {
try {
logger.info("🔌 Starting LensProxy");
await lensProxy.listen(); // lensProxy.port available
} catch (error: any) {
showErrorPopup("Lens Error", `Could not start proxy: ${error?.message || "unknown error"}`);
try {
logger.info("🔌 Starting LensProxy");
await lensProxy.listen(); // lensProxy.port available
} catch (error: any) {
showErrorPopup("Lens Error", `Could not start proxy: ${error?.message || "unknown error"}`);
return exitApp();
}
// test proxy connection
try {
logger.info("🔎 Testing LensProxy connection ...");
const versionResponse = await fetch(`https://127.0.0.1:${lensProxyPort.get()}/version`, {
agent: new Agent({
ca: lensProxyCertificate.get()?.cert,
}),
});
const { version: versionFromProxy } = await versionResponse.json() as { version: string };
if (buildVersion.get() !== versionFromProxy) {
logger.error("Proxy server responded with invalid response");
return exitApp();
}
// test proxy connection
try {
logger.info("🔎 Testing LensProxy connection ...");
const versionResponse = await fetch(`https://127.0.0.1:${lensProxyPort.get()}/version`, {
agent: new Agent({
ca: lensProxyCertificate.get()?.cert,
}),
});
logger.info("⚡ LensProxy connection OK");
} catch (error) {
logger.error(`🛑 LensProxy: failed connection test: ${error}`);
const { version: versionFromProxy } = await versionResponse.json() as { version: string };
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.",
];
if (buildVersion.get() !== versionFromProxy) {
logger.error("Proxy server responded with invalid response");
showErrorPopup("Lens Proxy Error", message.join("\n\n"));
return exitApp();
}
logger.info("⚡ LensProxy connection OK");
} catch (error) {
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();
}
},
runAfter: di.inject(initializeBuildVersionInjectable),
};
},
return exitApp();
}
},
runAfter: initializeBuildVersionInjectable,
}),
causesSideEffects: true,
@@ -10,7 +10,6 @@ const setupMobxInjectable = getInjectable({
id: "setup-mobx",
instantiate: () => ({
id: "setup-mobx",
run: () => {
// Docs: https://mobx.js.org/configuration.html
Mobx.configure({
@@ -9,36 +9,31 @@ import getCommandLineSwitchInjectable from "../../electron-app/features/get-comm
const setupProxyEnvInjectable = getInjectable({
id: "setup-proxy-env",
instantiate: (di) => {
const getCommandLineSwitch = di.inject(getCommandLineSwitchInjectable);
instantiate: (di) => ({
run: () => {
const getCommandLineSwitch = di.inject(getCommandLineSwitchInjectable);
const switchValue = getCommandLineSwitch("proxy-server");
return {
id: "setup-proxy-env",
run: () => {
const switchValue = getCommandLineSwitch("proxy-server");
let httpsProxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || "";
let httpsProxy =
process.env.HTTPS_PROXY || process.env.HTTP_PROXY || "";
delete process.env.HTTPS_PROXY;
delete process.env.HTTP_PROXY;
delete process.env.HTTPS_PROXY;
delete process.env.HTTP_PROXY;
if (switchValue !== "") {
httpsProxy = switchValue;
}
if (switchValue !== "") {
httpsProxy = switchValue;
}
if (httpsProxy !== "") {
process.env.APP_HTTPS_PROXY = httpsProxy;
}
if (httpsProxy !== "") {
process.env.APP_HTTPS_PROXY = httpsProxy;
}
if (getCommandLineSwitch("proxy-server") !== "") {
process.env.HTTPS_PROXY = getCommandLineSwitch("proxy-server");
}
if (getCommandLineSwitch("proxy-server") !== "") {
process.env.HTTPS_PROXY = getCommandLineSwitch("proxy-server");
}
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeElectronIsReadyInjectionToken,
});
@@ -9,18 +9,13 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
const setupSyncingOfGeneralCatalogEntitiesInjectable = getInjectable({
id: "setup-syncing-of-general-catalog-entities",
instantiate: (di) => {
const syncGeneralCatalogEntities = di.inject(
syncGeneralCatalogEntitiesInjectable,
);
instantiate: (di) => ({
run: () => {
const syncGeneralCatalogEntities = di.inject(syncGeneralCatalogEntitiesInjectable);
return {
id: "setup-syncing-of-general-catalog-entities",
run: () => {
syncGeneralCatalogEntities();
},
};
},
syncGeneralCatalogEntities();
},
}),
injectionToken: onLoadOfApplicationInjectionToken,
});
@@ -9,16 +9,13 @@ import syncWeblinksInjectable from "../../catalog-sources/sync-weblinks.injectab
const setupSyncingOfWeblinksInjectable = getInjectable({
id: "setup-syncing-of-weblinks",
instantiate: (di) => {
const syncWeblinks = di.inject(syncWeblinksInjectable);
instantiate: (di) => ({
run: () => {
const syncWeblinks = di.inject(syncWeblinksInjectable);
return {
id: "setup-syncing-of-weblinks",
run: () => {
syncWeblinks();
},
};
},
syncWeblinks();
},
}),
injectionToken: onLoadOfApplicationInjectionToken,
});
@@ -9,8 +9,11 @@ import injectSystemCAsInjectable from "../../../features/certificate-authorities
const setupSystemCaInjectable = getInjectable({
id: "setup-system-ca",
instantiate: (di) => ({
id: "setup-system-ca",
run: di.inject(injectSystemCAsInjectable),
run: async () => {
const injectSystemCAs = di.inject(injectSystemCAsInjectable);
await injectSystemCAs();
},
}),
injectionToken: beforeApplicationIsLoadingInjectionToken,
});
@@ -18,33 +18,30 @@ const getDeepLinkUrl = (commandLineArguments: string[]) => (
const showInitialWindowInjectable = getInjectable({
id: "show-initial-window",
instantiate: (di) => {
const shouldStartHidden = di.inject(shouldStartHiddenInjectable);
const shouldStartWindow = !shouldStartHidden;
const createFirstApplicationWindow = di.inject(createFirstApplicationWindowInjectable);
const splashWindow = di.inject(splashWindowInjectable);
const openDeepLink = di.inject(openDeepLinkInjectable);
const commandLineArguments = di.inject(commandLineArgumentsInjectable);
instantiate: (di) => ({
run: async () => {
const shouldStartHidden = di.inject(shouldStartHiddenInjectable);
const shouldStartWindow = !shouldStartHidden;
const createFirstApplicationWindow = di.inject(createFirstApplicationWindowInjectable);
const splashWindow = di.inject(splashWindowInjectable);
const openDeepLink = di.inject(openDeepLinkInjectable);
const commandLineArguments = di.inject(commandLineArgumentsInjectable);
return {
id: "show-initial-window",
run: async () => {
if (shouldStartWindow) {
const deepLinkUrl = getDeepLinkUrl(commandLineArguments);
if (shouldStartWindow) {
const deepLinkUrl = getDeepLinkUrl(commandLineArguments);
if (deepLinkUrl) {
await openDeepLink(deepLinkUrl);
} else {
const applicationWindow = createFirstApplicationWindow();
if (deepLinkUrl) {
await openDeepLink(deepLinkUrl);
} else {
const applicationWindow = createFirstApplicationWindow();
await applicationWindow.start();
}
splashWindow.close();
await applicationWindow.start();
}
},
};
},
splashWindow.close();
}
},
}),
injectionToken: afterApplicationIsLoadedInjectionToken,
});
@@ -9,20 +9,18 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
const showLoadingInjectable = getInjectable({
id: "show-loading",
instantiate: (di) => {
const shouldStartHidden = di.inject(shouldStartHiddenInjectable);
const shouldShowLoadingWindow = !shouldStartHidden;
const splashWindow = di.inject(splashWindowInjectable);
return {
id: "show-loading",
run: async () => {
if (shouldShowLoadingWindow) {
await splashWindow.start();
}
},
};
},
instantiate: (di) => ({
run: async () => {
const shouldStartHidden = di.inject(shouldStartHiddenInjectable);
const shouldShowLoadingWindow = !shouldStartHidden;
const splashWindow = di.inject(splashWindowInjectable);
if (shouldShowLoadingWindow) {
await splashWindow.start();
}
},
}),
injectionToken: onLoadOfApplicationInjectionToken,
});
@@ -4,23 +4,20 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import clusterManagerInjectable from "../../cluster/manager.injectable";
import { beforeQuitOfFrontEndInjectionToken } from "../runnable-tokens/before-quit-of-front-end-injection-token";
import { beforeQuitOfFrontEndInjectionToken } from "../runnable-tokens/phases";
const stopClusterManagerInjectable = getInjectable({
id: "stop-cluster-manager",
instantiate: (di) => {
const clusterManager = di.inject(clusterManagerInjectable);
instantiate: (di) => ({
run: () => {
const clusterManager = di.inject(clusterManagerInjectable);
return {
id: "stop-cluster-manager",
run: () => {
clusterManager.stop();
clusterManager.stop();
return undefined;
},
};
},
return undefined;
},
}),
injectionToken: beforeQuitOfFrontEndInjectionToken,
});