mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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:
1 parent
ad9bafe2a5
commit
2789bcebcb
754 files changed
+2715
-2752
No files matched your search
+1
-1
@@ -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 directoryForIntegrationTestingInjectable from "./directory-for-integration-testing.injectable";
|
||||
|
||||
export default getGlobalOverride(directoryForIntegrationTestingInjectable, () => undefined);
|
||||
@@ -18,38 +18,35 @@ import { beforeAnythingInjectionToken } from "@k8slens/application-for-electron-
|
||||
const setupAppPathsInjectable = getInjectable({
|
||||
id: "setup-app-paths",
|
||||
|
||||
instantiate: (di) => {
|
||||
const setElectronAppPath = di.inject(setElectronAppPathInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
const getElectronAppPath = di.inject(getElectronAppPathInjectable);
|
||||
const appPathsState = di.inject(appPathsStateInjectable);
|
||||
const directoryForIntegrationTesting = di.inject(directoryForIntegrationTestingInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const setElectronAppPath = di.inject(setElectronAppPathInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
const getElectronAppPath = di.inject(getElectronAppPathInjectable);
|
||||
const appPathsState = di.inject(appPathsStateInjectable);
|
||||
const directoryForIntegrationTesting = di.inject(directoryForIntegrationTestingInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-app-paths",
|
||||
run: () => {
|
||||
if (directoryForIntegrationTesting) {
|
||||
setElectronAppPath("appData", directoryForIntegrationTesting);
|
||||
}
|
||||
if (directoryForIntegrationTesting) {
|
||||
setElectronAppPath("appData", directoryForIntegrationTesting);
|
||||
}
|
||||
|
||||
const appDataPath = getElectronAppPath("appData");
|
||||
const appDataPath = getElectronAppPath("appData");
|
||||
|
||||
setElectronAppPath("userData", joinPaths(appDataPath, appName));
|
||||
setElectronAppPath("userData", joinPaths(appDataPath, appName));
|
||||
|
||||
const appPaths = pipeline(
|
||||
pathNames,
|
||||
map(name => [name, getElectronAppPath(name)]),
|
||||
fromPairs,
|
||||
) as AppPaths;
|
||||
const appPaths = pipeline(
|
||||
pathNames,
|
||||
map(name => [name, getElectronAppPath(name)]),
|
||||
fromPairs,
|
||||
) as AppPaths;
|
||||
|
||||
appPathsState.set(appPaths);
|
||||
appPathsState.set(appPaths);
|
||||
|
||||
// NOTE: this is the worse of two evils. This makes sure that `RunnableSync` always is sync
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
// NOTE: this is the worse of two evils. This makes sure that `RunnableSync` always is sync
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeAnythingInjectionToken,
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import directoryForTempInjectable from "../../../common/app-paths/directory-for-temp/directory-for-temp.injectable";
|
||||
import { iter, strictGet } from "../../../common/utils";
|
||||
import { iter, strictGet } from "@k8slens/utilities";
|
||||
import type { ComputeKubeconfigDiff } from "../kubeconfig-sync/compute-diff.injectable";
|
||||
import computeKubeconfigDiffInjectable from "../kubeconfig-sync/compute-diff.injectable";
|
||||
import type { ConfigToModels } from "../kubeconfig-sync/config-to-models.injectable";
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ import type { Readable } from "stream";
|
||||
import type { CatalogEntity } from "../../../common/catalog";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import createReadFileStreamInjectable from "../../../common/fs/create-read-file-stream.injectable";
|
||||
import type { Disposer } from "../../../common/utils";
|
||||
import { bytesToUnits, noop } from "../../../common/utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { bytesToUnits, noop } from "@k8slens/utilities";
|
||||
import computeKubeconfigDiffInjectable from "./compute-diff.injectable";
|
||||
import kubeconfigSyncLoggerInjectable from "./logger.injectable";
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
import type { IComputedValue, ObservableMap } from "mobx";
|
||||
import { action, observable, computed, makeObservable, observe } from "mobx";
|
||||
import type { CatalogEntity } from "../../../common/catalog";
|
||||
import type { Disposer } from "../../../common/utils";
|
||||
import { iter } from "../../../common/utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
import type { KubeconfigSyncValue } from "../../../common/user-store";
|
||||
import type { Logger } from "../../../common/logger";
|
||||
import type { WatchKubeconfigFileChanges } from "./watch-file-changes.injectable";
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import statInjectable from "../../../common/fs/stat.injectable";
|
||||
import type { Watcher } from "../../../common/fs/watch/watch.injectable";
|
||||
import watchInjectable from "../../../common/fs/watch/watch.injectable";
|
||||
import type { Disposer } from "../../../common/utils";
|
||||
import { getOrInsertWith, iter } from "../../../common/utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { getOrInsertWith, iter } from "@k8slens/utilities";
|
||||
import diffChangedKubeconfigInjectable from "./diff-changed-kubeconfig.injectable";
|
||||
import kubeconfigSyncLoggerInjectable from "./logger.injectable";
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { WeblinkStore } from "../../common/weblinks-store/weblink-store";
|
||||
import { WebLink } from "../../common/catalog-entities";
|
||||
import type { CatalogEntityRegistry } from "../catalog";
|
||||
import got from "got";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { random } from "lodash";
|
||||
|
||||
async function validateLink(link: WebLink) {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { debounce } from "lodash";
|
||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
|
||||
|
||||
export default getGlobalOverride(catalogSyncBroadcasterInjectable, () => debounce(() => {}));
|
||||
+2
-1
@@ -6,10 +6,11 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { reaction } from "mobx";
|
||||
import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token";
|
||||
import { catalogInitChannel } from "../../common/ipc/catalog";
|
||||
import { disposer, toJS } from "../../common/utils";
|
||||
import { disposer } from "@k8slens/utilities";
|
||||
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable";
|
||||
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
|
||||
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
|
||||
import { toJS } from "../../common/utils";
|
||||
|
||||
const catalogSyncToRendererInjectable = getInjectable({
|
||||
id: "catalog-sync-to-renderer",
|
||||
|
||||
@@ -3,24 +3,21 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { afterRootFrameIsReadyInjectionToken } from "../start-main-application/runnable-tokens/after-root-frame-is-ready-injection-token";
|
||||
import { afterRootFrameIsReadyInjectionToken } from "../start-main-application/runnable-tokens/phases";
|
||||
import catalogSyncToRendererInjectable from "./catalog-sync-to-renderer.injectable";
|
||||
|
||||
const startCatalogSyncInjectable = getInjectable({
|
||||
id: "start-catalog-sync",
|
||||
|
||||
instantiate: (di) => {
|
||||
const catalogSyncToRenderer = di.inject(catalogSyncToRendererInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const catalogSyncToRenderer = di.inject(catalogSyncToRendererInjectable);
|
||||
|
||||
return {
|
||||
id: "start-catalog-sync",
|
||||
run: () => {
|
||||
if (!catalogSyncToRenderer.started) {
|
||||
catalogSyncToRenderer.start();
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
if (!catalogSyncToRenderer.started) {
|
||||
catalogSyncToRenderer.start();
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: afterRootFrameIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@@ -4,25 +4,22 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import catalogSyncToRendererInjectable from "./catalog-sync-to-renderer.injectable";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../start-main-application/runnable-tokens/phases";
|
||||
|
||||
const stopCatalogSyncInjectable = getInjectable({
|
||||
id: "stop-catalog-sync",
|
||||
|
||||
instantiate: (di) => {
|
||||
const catalogSyncToRenderer = di.inject(catalogSyncToRendererInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const catalogSyncToRenderer = di.inject(catalogSyncToRendererInjectable);
|
||||
|
||||
return {
|
||||
id: "stop-catalog-sync",
|
||||
run: () => {
|
||||
if (catalogSyncToRenderer.started) {
|
||||
catalogSyncToRenderer.stop();
|
||||
}
|
||||
if (catalogSyncToRenderer.started) {
|
||||
catalogSyncToRenderer.stop();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeQuitOfFrontEndInjectionToken,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { action, computed, type IComputedValue, type IObservableArray, makeObservable, observable } from "mobx";
|
||||
import type { CatalogEntity } from "../../common/catalog";
|
||||
import type { HasCategoryForEntity } from "../../common/catalog/has-category-for-entity.injectable";
|
||||
import { iter } from "../../common/utils";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
|
||||
interface Dependencies {
|
||||
readonly hasCategoryForEntity: HasCategoryForEntity;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { groupBy, reduce } from "lodash";
|
||||
import { filter, map } from "lodash/fp";
|
||||
import type { ClusterMetadata } from "../../common/cluster-types";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import { hasDefinedTupleValue, isDefined, object } from "../../common/utils";
|
||||
import { hasDefinedTupleValue, isDefined, object } from "@k8slens/utilities";
|
||||
import type { ClusterDetectionResult, ClusterMetadataDetector } from "./token";
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ import { clusterListNamespaceForbiddenChannel } from "../../common/ipc/cluster";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { KubeApiResource } from "../../common/rbac";
|
||||
import { formatKubeApiResource } from "../../common/rbac";
|
||||
import { disposer, isDefined, isRequestError } from "../../common/utils";
|
||||
import { withConcurrencyLimit } from "../../common/utils/with-concurrency-limit";
|
||||
import { disposer, isDefined, isRequestError, withConcurrencyLimit } from "@k8slens/utilities";
|
||||
import type { ClusterPrometheusHandler } from "./prometheus-handler/prometheus-handler";
|
||||
import type { BroadcastConnectionUpdate } from "./broadcast-connection-update.injectable";
|
||||
import type { KubeAuthProxyServer } from "./kube-auth-proxy-server.injectable";
|
||||
|
||||
@@ -8,16 +8,13 @@ import clusterManagerInjectable from "./manager.injectable";
|
||||
|
||||
const initializeClusterManagerInjectable = getInjectable({
|
||||
id: "initialize-cluster-manager",
|
||||
instantiate: (di) => {
|
||||
const clusterManager = di.inject(clusterManagerInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const clusterManager = di.inject(clusterManagerInjectable);
|
||||
|
||||
return {
|
||||
id: "initialize-cluster-manager",
|
||||
run: () => {
|
||||
clusterManager.init();
|
||||
},
|
||||
};
|
||||
},
|
||||
clusterManager.init();
|
||||
},
|
||||
}),
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import "../../common/ipc/cluster";
|
||||
import type { IObservableValue, ObservableSet } from "mobx";
|
||||
import { action, makeObservable, observe, reaction, toJS } from "mobx";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import { isErrnoException } from "../../common/utils";
|
||||
import { isErrnoException } from "@k8slens/utilities";
|
||||
import { isKubernetesCluster, KubernetesCluster, LensKubernetesClusterStatus } from "../../common/catalog-entities/kubernetes-cluster";
|
||||
import { ipcMainOn } from "../../common/ipc";
|
||||
import { once } from "lodash";
|
||||
|
||||
@@ -8,13 +8,12 @@ import loggerInjectable from "../../common/logger.injectable";
|
||||
import type { KubeApiResource } from "../../common/rbac";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import { requestApiVersionsInjectionToken } from "./request-api-versions";
|
||||
import { withConcurrencyLimit } from "../../common/utils/with-concurrency-limit";
|
||||
import { backoffCaller, withConcurrencyLimit } from "@k8slens/utilities";
|
||||
import requestKubeApiResourcesForInjectable from "./request-kube-api-resources-for.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import { backoffCaller } from "../../common/utils/backoff-caller";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import broadcastConnectionUpdateInjectable from "./broadcast-connection-update.injectable";
|
||||
|
||||
export type RequestApiResources = (cluster: Cluster) => Promise<AsyncResult<KubeApiResource[], Error>>;
|
||||
export type RequestApiResources = (cluster: Cluster) => AsyncResult<KubeApiResource[], Error>;
|
||||
|
||||
export interface KubeResourceListGroup {
|
||||
group: string;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export interface KubeResourceListGroup {
|
||||
group: string;
|
||||
@@ -15,7 +15,7 @@ export interface ClusterData {
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
export type RequestApiVersions = (cluster: ClusterData) => Promise<AsyncResult<KubeResourceListGroup[], Error>>;
|
||||
export type RequestApiVersions = (cluster: ClusterData) => AsyncResult<KubeResourceListGroup[], Error>;
|
||||
|
||||
export const requestApiVersionsInjectionToken = getInjectionToken<RequestApiVersions>({
|
||||
id: "request-api-versions-token",
|
||||
|
||||
@@ -6,11 +6,11 @@ import type { V1APIResourceList } from "@kubernetes/client-node";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import type { KubeApiResource } from "../../common/rbac";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import k8sRequestInjectable from "../k8s-request.injectable";
|
||||
import type { KubeResourceListGroup } from "./request-api-versions";
|
||||
|
||||
export type RequestKubeApiResources = (grouping: KubeResourceListGroup) => Promise<AsyncResult<KubeApiResource[], Error>>;
|
||||
export type RequestKubeApiResources = (grouping: KubeResourceListGroup) => AsyncResult<KubeApiResource[], Error>;
|
||||
|
||||
export type RequestKubeApiResourcesFor = (cluster: Cluster) => RequestKubeApiResources;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import type { V1APIGroupList } from "@kubernetes/client-node";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { chain } from "../../common/utils/iter";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
import k8sRequestInjectable from "../k8s-request.injectable";
|
||||
import { requestApiVersionsInjectionToken } from "./request-api-versions";
|
||||
|
||||
@@ -19,7 +19,7 @@ const requestNonCoreApiVersionsInjectable = getInjectable({
|
||||
|
||||
return {
|
||||
callWasSuccessful: true,
|
||||
response: chain(groups.values())
|
||||
response: iter.chain(groups.values())
|
||||
.flatMap(group => group.versions.map(version => ({
|
||||
group: group.name,
|
||||
path: `/apis/${version.groupVersion}`,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-sto
|
||||
import type { ClusterModel } from "../../../common/cluster-types";
|
||||
import readJsonSyncInjectable from "../../../common/fs/read-json-sync.injectable";
|
||||
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
||||
import { isErrnoException } from "../../../common/utils";
|
||||
import { isErrnoException } from "@k8slens/utilities";
|
||||
|
||||
interface Pre500WorkspaceStoreModel {
|
||||
workspaces: {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import type { ClusterModel, ClusterPreferences, ClusterPrometheusPreferences } from "../../../common/cluster-types";
|
||||
import { moveSync, removeSync } from "fs-extra";
|
||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import { isDefined } from "../../../common/utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
|
||||
@@ -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 randomUUIDInjectable from "./random-uuid.injectable";
|
||||
|
||||
export default getGlobalOverride(randomUUIDInjectable, () => () => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { kebabCase } from "lodash";
|
||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import electronAppInjectable from "./electron-app.injectable";
|
||||
|
||||
export default getGlobalOverride(electronAppInjectable, () => {
|
||||
|
||||
+1
-1
@@ -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 electronDialogInjectable from "./electron-dialog.injectable";
|
||||
|
||||
export default getGlobalOverride(electronDialogInjectable, () => ({
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import EventEmitter from "events";
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import nativeThemeInjectable from "./native-theme.injectable";
|
||||
|
||||
export default getGlobalOverride(nativeThemeInjectable, () => Object.assign(new EventEmitter(), {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../../../common/test-utils/get-global-override-for-function";
|
||||
import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
|
||||
import showOpenDialogInjectable from "./show-open-dialog.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(showOpenDialogInjectable);
|
||||
@@ -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 "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||
import lensProtocolRouterMainInjectable from "../../protocol-handler/lens-protocol-router-main/lens-protocol-router-main.injectable";
|
||||
|
||||
const cleanUpDeepLinkingInjectable = getInjectable({
|
||||
id: "clean-up-deep-linking",
|
||||
|
||||
instantiate: (di) => {
|
||||
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
|
||||
|
||||
return {
|
||||
id: "clean-up-deep-linking",
|
||||
run: () => void lensProtocolRouterMain.cleanup(),
|
||||
};
|
||||
},
|
||||
lensProtocolRouterMain.cleanup();
|
||||
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeQuitOfBackEndInjectionToken,
|
||||
});
|
||||
|
||||
+12
-16
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/phases";
|
||||
import electronAppInjectable from "../../electron-app.injectable";
|
||||
import { isEmpty } from "lodash/fp";
|
||||
import getVisibleWindowsInjectable from "../../../start-main-application/lens-window/get-visible-windows.injectable";
|
||||
@@ -11,23 +11,19 @@ import getVisibleWindowsInjectable from "../../../start-main-application/lens-wi
|
||||
const hideDockForLastClosedWindowInjectable = getInjectable({
|
||||
id: "hide-dock-when-there-are-no-windows",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||
const visibleWindows = getVisibleWindows();
|
||||
|
||||
return {
|
||||
id: "hide-dock-when-there-are-no-windows",
|
||||
run: () => {
|
||||
const visibleWindows = getVisibleWindows();
|
||||
if (isEmpty(visibleWindows)) {
|
||||
app.dock?.hide();
|
||||
}
|
||||
|
||||
if (isEmpty(visibleWindows)) {
|
||||
app.dock?.hide();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeQuitOfFrontEndInjectionToken,
|
||||
});
|
||||
|
||||
+7
-10
@@ -4,21 +4,18 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import electronAppInjectable from "../../electron-app.injectable";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../../start-main-application/runnable-tokens/after-window-is-opened-injection-token";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../../start-main-application/runnable-tokens/phases";
|
||||
|
||||
const showDockForFirstOpenedWindowInjectable = getInjectable({
|
||||
id: "show-dock-for-first-opened-window",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
|
||||
return {
|
||||
id: "show-dock-for-first-opened-window",
|
||||
run: () => {
|
||||
app.dock?.show();
|
||||
},
|
||||
};
|
||||
},
|
||||
app.dock?.show();
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: afterWindowIsOpenedInjectionToken,
|
||||
});
|
||||
|
||||
+10
-13
@@ -10,21 +10,18 @@ import exitAppInjectable from "../features/exit-app.injectable";
|
||||
const enforceSingleApplicationInstanceInjectable = getInjectable({
|
||||
id: "enforce-single-application-instance",
|
||||
|
||||
instantiate: (di) => {
|
||||
const requestSingleInstanceLock = di.inject(requestSingleInstanceLockInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const requestSingleInstanceLock = di.inject(requestSingleInstanceLockInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
|
||||
return {
|
||||
id: "enforce-single-application-instance",
|
||||
run: () => {
|
||||
if (!requestSingleInstanceLock()) {
|
||||
exitApp();
|
||||
}
|
||||
if (!requestSingleInstanceLock()) {
|
||||
exitApp();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@@ -10,19 +10,16 @@ import electronAppInjectable from "../electron-app.injectable";
|
||||
const setupApplicationNameInjectable = getInjectable({
|
||||
id: "setup-application-name",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-application-name",
|
||||
run: () => {
|
||||
app.setName(appName);
|
||||
app.setName(appName);
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@@ -7,68 +7,63 @@ import electronAppInjectable from "../electron-app.injectable";
|
||||
import openDeepLinkInjectable from "../../protocol-handler/lens-protocol-router-main/open-deep-link-for-url/open-deep-link.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import commandLineArgumentsInjectable from "../../utils/command-line-arguments.injectable";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { find, startsWith, toLower, map } from "lodash/fp";
|
||||
import { startsWith, toLower } from "lodash/fp";
|
||||
import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
import showApplicationWindowInjectable from "../../start-main-application/lens-window/show-application-window.injectable";
|
||||
|
||||
const setupDeepLinkingInjectable = getInjectable({
|
||||
id: "setup-deep-linking",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const openDeepLinkForUrl = di.inject(openDeepLinkInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: async () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const openDeepLinkForUrl = di.inject(openDeepLinkInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
const firstInstanceCommandLineArguments = di.inject(commandLineArgumentsInjectable);
|
||||
|
||||
const firstInstanceCommandLineArguments = di.inject(
|
||||
commandLineArgumentsInjectable,
|
||||
);
|
||||
logger.info(`📟 Setting protocol client for lens://`);
|
||||
|
||||
return {
|
||||
id: "setup-deep-linking",
|
||||
run: async () => {
|
||||
logger.info(`📟 Setting protocol client for lens://`);
|
||||
if (app.setAsDefaultProtocolClient("lens")) {
|
||||
logger.info("📟 Protocol client register succeeded ✅");
|
||||
} else {
|
||||
logger.info("📟 Protocol client register failed ❗");
|
||||
}
|
||||
|
||||
if (app.setAsDefaultProtocolClient("lens")) {
|
||||
logger.info("📟 Protocol client register succeeded ✅");
|
||||
} else {
|
||||
logger.info("📟 Protocol client register failed ❗");
|
||||
}
|
||||
const url = getDeepLinkUrl(firstInstanceCommandLineArguments);
|
||||
|
||||
const url = getDeepLinkUrl(firstInstanceCommandLineArguments);
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
app.on("open-url", async (event, url) => {
|
||||
event.preventDefault();
|
||||
|
||||
app.on("open-url", async (event, url) => {
|
||||
event.preventDefault();
|
||||
await openDeepLinkForUrl(url);
|
||||
});
|
||||
|
||||
await openDeepLinkForUrl(url);
|
||||
});
|
||||
app.on(
|
||||
"second-instance",
|
||||
async (_, secondInstanceCommandLineArguments) => {
|
||||
const url = getDeepLinkUrl(secondInstanceCommandLineArguments);
|
||||
|
||||
app.on(
|
||||
"second-instance",
|
||||
await showApplicationWindow();
|
||||
|
||||
async (_, secondInstanceCommandLineArguments) => {
|
||||
const url = getDeepLinkUrl(secondInstanceCommandLineArguments);
|
||||
|
||||
await showApplicationWindow();
|
||||
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
},
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
export default setupDeepLinkingInjectable;
|
||||
|
||||
const getDeepLinkUrl = (commandLineArguments: string[]) =>
|
||||
pipeline(commandLineArguments, map(toLower), find(startsWith("lens://")));
|
||||
const getDeepLinkUrl = (commandLineArguments: string[]) => (
|
||||
commandLineArguments
|
||||
.map(toLower)
|
||||
.find(startsWith("lens://"))
|
||||
);
|
||||
+25
-24
@@ -10,32 +10,33 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
const setupDeveloperToolsInDevelopmentEnvironmentInjectable = getInjectable({
|
||||
id: "setup-developer-tools-in-development-environment",
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const nodeEnv = di.inject(nodeEnvInjectionToken);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const nodeEnv = di.inject(nodeEnvInjectionToken);
|
||||
|
||||
return {
|
||||
id: "setup-developer-tools-in-development-environment",
|
||||
run: () => {
|
||||
if (nodeEnv !== "development") {
|
||||
return;
|
||||
if (nodeEnv !== "development") {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("🤓 Installing developer tools");
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
const {
|
||||
default: devToolsInstaller,
|
||||
REACT_DEVELOPER_TOOLS,
|
||||
} = await import("electron-devtools-installer");
|
||||
|
||||
const name = await devToolsInstaller([REACT_DEVELOPER_TOOLS]);
|
||||
|
||||
logger.info(`[DEVTOOLS-INSTALLER]: installed ${name}`);
|
||||
} catch (error) {
|
||||
logger.error(`[DEVTOOLS-INSTALLER]: failed`, { error });
|
||||
}
|
||||
|
||||
logger.info("🤓 Installing developer tools");
|
||||
|
||||
import("electron-devtools-installer")
|
||||
.then(({ default: devToolsInstaller, REACT_DEVELOPER_TOOLS }) =>
|
||||
devToolsInstaller([REACT_DEVELOPER_TOOLS]),
|
||||
)
|
||||
.then((name) =>
|
||||
logger.info(`[DEVTOOLS-INSTALLER]: installed ${name}`),
|
||||
)
|
||||
.catch((error) =>
|
||||
logger.error(`[DEVTOOLS-INSTALLER]: failed`, { error }),
|
||||
);
|
||||
},
|
||||
};
|
||||
},
|
||||
})();
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
@@ -10,19 +10,14 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
const setupDeviceShutdownInjectable = getInjectable({
|
||||
id: "setup-device-shutdown",
|
||||
|
||||
instantiate: (di) => {
|
||||
const powerMonitor = di.inject(powerMonitorInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const powerMonitor = di.inject(powerMonitorInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-device-shutdown",
|
||||
run: () => {
|
||||
powerMonitor.on("shutdown", async () => {
|
||||
exitApp();
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
powerMonitor.on("shutdown", exitApp);
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
+19
-22
@@ -16,30 +16,27 @@ import clusterConnectionInjectable from "../../../cluster/cluster-connection.inj
|
||||
const setupIpcMainHandlersInjectable = getInjectable({
|
||||
id: "setup-ipc-main-handlers",
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
|
||||
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
|
||||
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-ipc-main-handlers",
|
||||
run: () => {
|
||||
logger.debug("[APP-MAIN] initializing ipc main handlers");
|
||||
logger.debug("[APP-MAIN] initializing ipc main handlers");
|
||||
|
||||
setupIpcMainHandlers({
|
||||
applicationMenuItemComposite,
|
||||
pushCatalogToRenderer,
|
||||
clusterStore,
|
||||
emitAppEvent,
|
||||
getClusterById,
|
||||
getClusterConnection: (cluster) => di.inject(clusterConnectionInjectable, cluster),
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
setupIpcMainHandlers({
|
||||
applicationMenuItemComposite,
|
||||
pushCatalogToRenderer,
|
||||
clusterStore,
|
||||
emitAppEvent,
|
||||
getClusterById,
|
||||
getClusterConnection: (cluster) => di.inject(clusterConnectionInjectable, cluster),
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
causesSideEffects: true,
|
||||
|
||||
+13
-16
@@ -11,24 +11,21 @@ import showApplicationWindowInjectable from "../../start-main-application/lens-w
|
||||
const setupMainWindowVisibilityAfterActivationInjectable = getInjectable({
|
||||
id: "setup-main-window-visibility-after-activation",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-main-window-visibility-after-activation",
|
||||
run: () => {
|
||||
app.on("activate", async (_, windowIsVisible) => {
|
||||
logger.info("APP:ACTIVATE", { hasVisibleWindows: windowIsVisible });
|
||||
app.on("activate", (_, windowIsVisible) => {
|
||||
logger.info("APP:ACTIVATE", { hasVisibleWindows: windowIsVisible });
|
||||
|
||||
if (!windowIsVisible) {
|
||||
await showApplicationWindow();
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
if (!windowIsVisible) {
|
||||
void showApplicationWindow();
|
||||
}
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
+12
-15
@@ -4,28 +4,25 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||
import electronAppInjectable from "../electron-app.injectable";
|
||||
import { runManyFor } from "../../../common/runnable/run-many-for";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../start-main-application/runnable-tokens/after-window-is-opened-injection-token";
|
||||
import { runManyFor } from "@k8slens/run-many";
|
||||
|
||||
const setupRunnablesAfterWindowIsOpenedInjectable = getInjectable({
|
||||
id: "setup-runnables-after-window-is-opened",
|
||||
|
||||
instantiate: (di) => {
|
||||
const afterWindowIsOpened = runManyFor(di)(afterWindowIsOpenedInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const afterWindowIsOpened = runManyFor(di)(afterWindowIsOpenedInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-runnables-after-window-is-opened",
|
||||
run: () => {
|
||||
app.on("browser-window-created", () => {
|
||||
afterWindowIsOpened();
|
||||
});
|
||||
app.on("browser-window-created", () => {
|
||||
afterWindowIsOpened();
|
||||
});
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
+27
-32
@@ -4,50 +4,45 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
|
||||
import { beforeQuitOfFrontEndInjectionToken, beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||
import electronAppInjectable from "../electron-app.injectable";
|
||||
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
|
||||
import autoUpdaterInjectable from "../features/auto-updater.injectable";
|
||||
import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
|
||||
import { runManySyncFor } from "@k8slens/run-many";
|
||||
|
||||
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
||||
id: "setup-closing-of-application",
|
||||
|
||||
instantiate: (di) => {
|
||||
const runManySync = runManySyncFor(di);
|
||||
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
|
||||
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
|
||||
const autoUpdater = di.inject(autoUpdaterInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const runManySync = runManySyncFor(di);
|
||||
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
|
||||
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
|
||||
const autoUpdater = di.inject(autoUpdaterInjectable);
|
||||
let isAutoUpdating = false;
|
||||
|
||||
return {
|
||||
id: "setup-closing-of-application",
|
||||
run: () => {
|
||||
let isAutoUpdating = false;
|
||||
autoUpdater.on("before-quit-for-update", () => {
|
||||
isAutoUpdating = true;
|
||||
});
|
||||
|
||||
autoUpdater.on("before-quit-for-update", () => {
|
||||
isAutoUpdating = true;
|
||||
});
|
||||
app.on("will-quit", (event) => {
|
||||
runRunnablesBeforeQuitOfFrontEnd();
|
||||
|
||||
app.on("will-quit", (event) => {
|
||||
runRunnablesBeforeQuitOfFrontEnd();
|
||||
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
|
||||
|
||||
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
|
||||
if (shouldQuitBackEnd) {
|
||||
runRunnablesBeforeQuitOfBackEnd();
|
||||
} else {
|
||||
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
if (shouldQuitBackEnd) {
|
||||
runRunnablesBeforeQuitOfBackEnd();
|
||||
} else {
|
||||
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../common/cluster/cluster";
|
||||
import { FormData } from "@k8slens/node-fetch";
|
||||
import type { RequestMetricsParams } from "../common/k8s-api/endpoints/metrics.api/request-metrics.injectable";
|
||||
import { object } from "../common/utils";
|
||||
import { object } from "@k8slens/utilities";
|
||||
import k8sRequestInjectable from "./k8s-request.injectable";
|
||||
|
||||
export type GetMetrics = (cluster: Cluster, prometheusPath: string, queryParams: RequestMetricsParams & { query: string }) => Promise<unknown>;
|
||||
|
||||
@@ -26,7 +26,7 @@ import setUpdateOnQuitInjectable from "./electron-app/features/set-update-on-qui
|
||||
import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable";
|
||||
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
|
||||
import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable";
|
||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||
import type { GlobalOverride } from "@k8slens/test-utils";
|
||||
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||
import {
|
||||
setLegacyGlobalDiForExtensionApi,
|
||||
@@ -53,7 +53,7 @@ export function getDiForUnitTesting() {
|
||||
});
|
||||
|
||||
for (const globalOverridePath of global.injectablePaths.main.globalOverridePaths) {
|
||||
const globalOverride = require(globalOverridePath).default as GlobalOverride;
|
||||
const globalOverride = require(globalOverridePath).default as GlobalOverride<unknown, unknown>;
|
||||
|
||||
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import listHelmChartsInjectable from "../helm-service/list-helm-charts.injectable";
|
||||
import getActiveHelmRepositoriesInjectable from "../repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { HelmRepo } from "../../../common/helm/helm-repo";
|
||||
import { sortBySemverVersion } from "../../../common/utils";
|
||||
import { sortBySemverVersion } from "@k8slens/utilities";
|
||||
import helmChartManagerInjectable from "../helm-chart-manager.injectable";
|
||||
|
||||
describe("Helm Service tests", () => {
|
||||
let listHelmCharts: () => Promise<any>;
|
||||
let getActiveHelmRepositoriesMock: jest.Mock<Promise<AsyncResult<HelmRepo[]>>>;
|
||||
let getActiveHelmRepositoriesMock: jest.Mock<AsyncResult<HelmRepo[]>>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { computed } from "mobx";
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import execHelmEnvInjectable from "./exec-env.injectable";
|
||||
|
||||
export default getGlobalOverride(execHelmEnvInjectable, () => computed(() => ({})));
|
||||
@@ -5,11 +5,11 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ExecFileException } from "child_process";
|
||||
import execFileInjectable from "../../../common/fs/exec-file.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
|
||||
import execHelmEnvInjectable from "./exec-env.injectable";
|
||||
|
||||
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, ExecFileException & { stderr: string }>>;
|
||||
export type ExecHelm = (args: string[]) => AsyncResult<string, ExecFileException & { stderr: string }>;
|
||||
|
||||
const execHelmInjectable = getInjectable({
|
||||
id: "exec-helm",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "../exec-helm/exec-helm.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export type HelmEnv = Record<string, string> & {
|
||||
HELM_REPOSITORY_CACHE?: string;
|
||||
@@ -17,7 +17,7 @@ const getHelmEnvInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const execHelm = di.inject(execHelmInjectable);
|
||||
|
||||
return async (): Promise<AsyncResult<HelmEnv>> => {
|
||||
return async (): AsyncResult<HelmEnv> => {
|
||||
const result = await execHelm(["env"]);
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import * as yaml from "js-yaml";
|
||||
import { iter, put, sortBySemverVersion } from "../../common/utils";
|
||||
import { iter, put, sortBySemverVersion } from "@k8slens/utilities";
|
||||
import type { HelmRepo } from "../../common/helm/helm-repo";
|
||||
import type { HelmChartManagerCache } from "./helm-chart-manager-cache.injectable";
|
||||
import type { Logger } from "../../common/logger";
|
||||
|
||||
+1
-1
@@ -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 getHelmChartReadmeInjectable from "./get-helm-chart-readme.injectable";
|
||||
|
||||
export default getGlobalOverride(getHelmChartReadmeInjectable, () => () => {
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import execHelmInjectable from "../../../exec-helm/exec-helm.injectable";
|
||||
import yaml from "js-yaml";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../../common/k8s-api/kube-json-api";
|
||||
@@ -18,7 +18,7 @@ const callForHelmManifestInjectable = getInjectable({
|
||||
name: string,
|
||||
namespace: string,
|
||||
kubeconfigPath: string,
|
||||
): Promise<AsyncResult<(KubeJsonApiData | KubeJsonApiDataList)[]>> => {
|
||||
): AsyncResult<(KubeJsonApiData | KubeJsonApiDataList)[]> => {
|
||||
const result = await execHelm([
|
||||
"get",
|
||||
"manifest",
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { JsonObject } from "type-fest";
|
||||
import { json } from "../../../../../common/utils";
|
||||
import yaml from "js-yaml";
|
||||
import execFileWithInputInjectable from "./exec-file-with-input/exec-file-with-input.injectable";
|
||||
import { getErrorMessage } from "../../../../../common/utils/get-error-message";
|
||||
@@ -60,7 +59,7 @@ const callForKubeResourcesByManifestInjectable = getInjectable({
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
const output = json.parse(result.response) as { items: JsonObject[] };
|
||||
const output = JSON.parse(result.response) as { items: JsonObject[] };
|
||||
|
||||
return output.items;
|
||||
};
|
||||
|
||||
+1
-1
@@ -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 execFileWithInputInjectable from "./exec-file-with-input.injectable";
|
||||
|
||||
export default getGlobalOverride(execFileWithInputInjectable, () => () => {
|
||||
|
||||
+3
-3
@@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
|
||||
import { isNumber } from "../../../../../../common/utils";
|
||||
import { isNumber } from "@k8slens/utilities";
|
||||
import assert from "assert";
|
||||
import type { ChildProcess } from "child_process";
|
||||
|
||||
@@ -13,7 +13,7 @@ export type ExecFileWithInput = (options: {
|
||||
filePath: string;
|
||||
commandArguments: string[];
|
||||
input: string;
|
||||
}) => Promise<AsyncResult<string, unknown>>;
|
||||
}) => AsyncResult<string, unknown>;
|
||||
|
||||
const execFileWithInputInjectable = getInjectable({
|
||||
id: "exec-file-with-input",
|
||||
|
||||
+3
-3
@@ -5,9 +5,9 @@
|
||||
import { getDiForUnitTesting } from "../../../../../getDiForUnitTesting";
|
||||
import type { ExecFileWithInput } from "./exec-file-with-input.injectable";
|
||||
import execFileWithInputInjectable from "./exec-file-with-input.injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
|
||||
import { getPromiseStatus } from "../../../../../../common/test-utils/get-promise-status";
|
||||
import { getPromiseStatus } from "@k8slens/test-utils";
|
||||
import EventEmitter from "events";
|
||||
|
||||
describe("exec-file-with-input", () => {
|
||||
@@ -56,7 +56,7 @@ describe("exec-file-with-input", () => {
|
||||
});
|
||||
|
||||
describe("when called", () => {
|
||||
let actualPromise: Promise<AsyncResult<string, unknown>>;
|
||||
let actualPromise: AsyncResult<string, unknown>;
|
||||
|
||||
beforeEach(() => {
|
||||
actualPromise = execFileWithInput({
|
||||
|
||||
+2
-2
@@ -5,13 +5,13 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import callForHelmManifestInjectable from "./call-for-helm-manifest/call-for-helm-manifest.injectable";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../common/k8s-api/kube-json-api";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export type GetHelmReleaseResources = (
|
||||
name: string,
|
||||
namespace: string,
|
||||
kubeconfigPath: string,
|
||||
) => Promise<AsyncResult<KubeJsonApiData[], string>>;
|
||||
) => AsyncResult<KubeJsonApiData[], string>;
|
||||
|
||||
const getHelmReleaseResourcesInjectable = getInjectable({
|
||||
id: "get-helm-release-resources",
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { ExecFileWithInput } from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
|
||||
import execFileWithInputInjectable from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiData } from "../../../../common/k8s-api/kube-json-api";
|
||||
|
||||
describe("get helm release resources", () => {
|
||||
@@ -37,7 +37,7 @@ describe("get helm release resources", () => {
|
||||
});
|
||||
|
||||
describe("when called", () => {
|
||||
let actualPromise: Promise<AsyncResult<KubeJsonApiData[], string>>;
|
||||
let actualPromise: AsyncResult<KubeJsonApiData[], string>;
|
||||
|
||||
beforeEach(() => {
|
||||
actualPromise = getHelmReleaseResources(
|
||||
|
||||
+1
-1
@@ -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 getHelmReleaseInjectable from "./get-helm-release.injectable";
|
||||
|
||||
export default getGlobalOverride(getHelmReleaseInjectable, () => () => {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import { isObject, json } from "../../../common/utils";
|
||||
import kubeconfigManagerInjectable from "../../kubeconfig-manager/kubeconfig-manager.injectable";
|
||||
import { isObject, json } from "@k8slens/utilities";
|
||||
import execHelmInjectable from "../exec-helm/exec-helm.injectable";
|
||||
import getHelmReleaseResourcesInjectable from "./get-helm-release-resources/get-helm-release-resources.injectable";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { object } from "../../../common/utils";
|
||||
import { object } from "@k8slens/utilities";
|
||||
import getActiveHelmRepositoriesInjectable from "../repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
import type { HelmRepo } from "../../../common/helm/helm-repo";
|
||||
import helmChartManagerInjectable from "../helm-chart-manager.injectable";
|
||||
|
||||
+1
-1
@@ -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 updateHelmReleaseInjectable from "./update-helm-release.injectable";
|
||||
|
||||
export default getGlobalOverride(updateHelmReleaseInjectable, () => () => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
||||
import { isObject, json, toCamelCase } from "../../common/utils";
|
||||
import { toCamelCase, isObject } from "@k8slens/utilities";
|
||||
|
||||
export type ListHelmReleases = (pathToKubeconfig: string, namespace?: string) => Promise<Record<string, any>[]>;
|
||||
|
||||
@@ -34,7 +34,7 @@ const listHelmReleasesInjectable = getInjectable({
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
const output = json.parse(result.response);
|
||||
const output = JSON.parse(result.response);
|
||||
|
||||
if (!Array.isArray(output) || output.length == 0) {
|
||||
return [];
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ import readYamlFileInjectable from "../../../../common/fs/read-yaml-file.injecta
|
||||
import getHelmEnvInjectable from "../../get-helm-env/get-helm-env.injectable";
|
||||
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
interface HelmRepositoryFromYaml {
|
||||
name: string;
|
||||
@@ -38,7 +38,7 @@ const getActiveHelmRepositoriesInjectable = getInjectable({
|
||||
|
||||
const getRepositories = getRepositoriesFor(readYamlFile);
|
||||
|
||||
return async (): Promise<AsyncResult<HelmRepo[]>> => {
|
||||
return async (): AsyncResult<HelmRepo[]> => {
|
||||
const envResult = await getHelmEnv();
|
||||
|
||||
if (!envResult.callWasSuccessful) {
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
|
||||
import type { HelmRepo } from "../../../../common/helm/helm-repo";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
const removeHelmRepositoryInjectable = getInjectable({
|
||||
id: "remove-helm-repository",
|
||||
@@ -15,7 +15,7 @@ const removeHelmRepositoryInjectable = getInjectable({
|
||||
const execHelm = di.inject(execHelmInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return async (repo: HelmRepo): Promise<AsyncResult<void, string>> => {
|
||||
return async (repo: HelmRepo): AsyncResult<void, string> => {
|
||||
logger.info(`[HELM]: removing repo ${repo.name} (${repo.url})`);
|
||||
|
||||
const result = await execHelm([
|
||||
|
||||
@@ -9,7 +9,7 @@ import { defaultHotbarCells, getEmptyHotbar } from "../../../common/hotbars/type
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import catalogCatalogEntityInjectable from "../../../common/catalog-entities/general-catalog-entities/implementations/catalog-catalog-entity.injectable";
|
||||
import { isDefined, isErrnoException } from "../../../common/utils";
|
||||
import { isDefined, isErrnoException } from "@k8slens/utilities";
|
||||
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { hotbarStoreMigrationInjectionToken } from "../../../common/hotbars/migrations-token";
|
||||
|
||||
+1
-1
@@ -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 waitUntilPortIsUsedInjectable from "./wait-until-port-is-used.injectable";
|
||||
|
||||
export default getGlobalOverride(
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { dumpConfigYaml } from "../../common/kube-helpers";
|
||||
import { isErrnoException } from "../../common/utils";
|
||||
import { isErrnoException } from "@k8slens/utilities";
|
||||
import type { PartialDeep } from "type-fest";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||
|
||||
@@ -18,6 +18,8 @@ import getDirnameOfPathInjectable from "../../common/path/get-dirname.injectable
|
||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||
import getBasenameOfPathInjectable from "../../common/path/get-basename.injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import execFileInjectable from "../../common/fs/exec-file.injectable";
|
||||
import unlinkInjectable from "../../common/fs/unlink.injectable";
|
||||
|
||||
export type CreateKubectl = (version: string) => Kubectl;
|
||||
|
||||
@@ -39,6 +41,8 @@ const createKubectlInjectable = getInjectable({
|
||||
getDirnameOfPath: di.inject(getDirnameOfPathInjectable),
|
||||
joinPaths: di.inject(joinPathsInjectable),
|
||||
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||
execFile: di.inject(execFileInjectable),
|
||||
unlink: di.inject(unlinkInjectable),
|
||||
};
|
||||
|
||||
return (version) => new Kubectl(dependencies, version);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import { promiseExecFile } from "../../common/utils/promise-exec";
|
||||
import { ensureDir, pathExists } from "fs-extra";
|
||||
import * as lockFile from "proper-lockfile";
|
||||
import { SemVer, coerce } from "semver";
|
||||
@@ -18,6 +17,9 @@ import type { GetDirnameOfPath } from "../../common/path/get-dirname.injectable"
|
||||
import type { GetBasenameOfPath } from "../../common/path/get-basename.injectable";
|
||||
import type { NormalizedPlatform } from "../../common/vars/normalized-platform.injectable";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import { hasTypedProperty, isObject, isString, json } from "@k8slens/utilities";
|
||||
import type { Unlink } from "../../common/fs/unlink.injectable";
|
||||
|
||||
const initScriptVersionString = "# lens-initscript v3";
|
||||
|
||||
@@ -40,6 +42,8 @@ export interface KubectlDependencies {
|
||||
joinPaths: JoinPaths;
|
||||
getDirnameOfPath: GetDirnameOfPath;
|
||||
getBasenameOfPath: GetBasenameOfPath;
|
||||
execFile: ExecFile;
|
||||
unlink: Unlink;
|
||||
}
|
||||
|
||||
export class Kubectl {
|
||||
@@ -145,38 +149,64 @@ export class Kubectl {
|
||||
public async checkBinary(path: string, checkVersion = true) {
|
||||
const exists = await pathExists(path);
|
||||
|
||||
if (exists) {
|
||||
try {
|
||||
const args = [
|
||||
"version",
|
||||
"--client",
|
||||
"--output", "json",
|
||||
];
|
||||
const { stdout } = await promiseExecFile(path, args);
|
||||
const output = JSON.parse(stdout);
|
||||
|
||||
if (!checkVersion) {
|
||||
return true;
|
||||
}
|
||||
let version: string = output.clientVersion.gitVersion;
|
||||
|
||||
if (version[0] === "v") {
|
||||
version = version.slice(1);
|
||||
}
|
||||
|
||||
if (version === this.kubectlVersion) {
|
||||
this.dependencies.logger.debug(`Local kubectl is version ${this.kubectlVersion}`);
|
||||
|
||||
return true;
|
||||
}
|
||||
this.dependencies.logger.error(`Local kubectl is version ${version}, expected ${this.kubectlVersion}, unlinking`);
|
||||
} catch (error) {
|
||||
this.dependencies.logger.error(`Local kubectl failed to run properly (${error}), unlinking`);
|
||||
}
|
||||
await fs.promises.unlink(this.path);
|
||||
if (!exists) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
const args = [
|
||||
"version",
|
||||
"--client",
|
||||
"--output", "json",
|
||||
];
|
||||
const execResult = await this.dependencies.execFile(path, args);
|
||||
|
||||
if (!execResult.callWasSuccessful) {
|
||||
this.dependencies.logger.error(`Local kubectl failed to run properly (${execResult.error}), unlinking`);
|
||||
await this.dependencies.unlink(this.path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const parseResult = json.parse(execResult.response);
|
||||
|
||||
if (!parseResult.callWasSuccessful) {
|
||||
this.dependencies.logger.error(`Local kubectl failed to run properly (${parseResult.error}), unlinking`);
|
||||
await this.dependencies.unlink(this.path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!checkVersion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { response: output } = parseResult;
|
||||
|
||||
if (
|
||||
!isObject(output)
|
||||
|| !hasTypedProperty(output, "clientVersion", isObject)
|
||||
|| !hasTypedProperty(output.clientVersion, "gitVersion", isString)
|
||||
) {
|
||||
this.dependencies.logger.error(`Local kubectl failed to return correct shaped response, unlinking`);
|
||||
await this.dependencies.unlink(this.path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const version = output.clientVersion.gitVersion;
|
||||
|
||||
switch (output.clientVersion.gitVersion) {
|
||||
case this.kubectlVersion:
|
||||
case `v${this.kubectlVersion}`:
|
||||
this.dependencies.logger.debug(`Local kubectl is version ${this.kubectlVersion}`);
|
||||
|
||||
return true;
|
||||
default:
|
||||
this.dependencies.logger.error(`Local kubectl is version ${version}, expected ${this.kubectlVersion}, unlinking`);
|
||||
await this.dependencies.unlink(this.path);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected async checkBundled(): Promise<boolean> {
|
||||
@@ -266,7 +296,7 @@ export class Kubectl {
|
||||
await fs.promises.chmod(this.path, 0o755);
|
||||
this.dependencies.logger.debug("kubectl binary download finished");
|
||||
} catch (error) {
|
||||
await fs.promises.unlink(this.path).catch(noop);
|
||||
await this.dependencies.unlink(this.path).catch(noop);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getOrInsertMap } from "../../../../common/utils";
|
||||
import { getOrInsertMap } from "@k8slens/utilities";
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import { ipcMainHandle } from "../../../../common/ipc";
|
||||
import crypto from "crypto";
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
*/
|
||||
|
||||
// @experimental
|
||||
export type {
|
||||
Environments,
|
||||
} from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
|
||||
export type { Environments } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
export { registerLensCore } from "./register-lens-core";
|
||||
export { nodeEnvInjectionToken } from "../common/vars/node-env-injection-token";
|
||||
|
||||
export * as Mobx from "mobx";
|
||||
export * as mainExtensionApi from "../extensions/main-api";
|
||||
export * as commonExtensionApi from "../extensions/common-api";
|
||||
|
||||
@@ -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 logLevelInjectable from "./level.injectable";
|
||||
|
||||
export default getGlobalOverride(logLevelInjectable, () => "error");
|
||||
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token";
|
||||
import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import { buildURL } from "../../common/utils/buildUrl";
|
||||
import { buildURL } from "@k8slens/utilities";
|
||||
|
||||
const navigateToRouteInjectable = getInjectable({
|
||||
id: "navigate-to-route",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { CoreV1Api } from "@kubernetes/client-node";
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { isRequestError } from "../../common/utils";
|
||||
import { isRequestError } from "@k8slens/utilities";
|
||||
|
||||
export interface PrometheusService extends PrometheusServiceInfo {
|
||||
kind: string;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as uuid from "uuid";
|
||||
|
||||
import { ProtocolHandlerExtension, ProtocolHandlerInternal, ProtocolHandlerInvalid } from "../../../common/protocol-handler";
|
||||
import { delay, noop } from "../../../common/utils";
|
||||
import { delay, noop } from "@k8slens/utilities";
|
||||
import type { ExtensionsStore, IsEnabledExtensionDescriptor } from "../../../extensions/extensions-store/extensions-store";
|
||||
import type { LensProtocolRouterMain } from "../lens-protocol-router-main/lens-protocol-router-main";
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import type { LensExtension } from "../../../extensions/lens-extension";
|
||||
import { observable, when, makeObservable } from "mobx";
|
||||
import type { LensProtocolRouterDependencies, RouteAttempt } from "../../../common/protocol-handler";
|
||||
import { ProtocolHandlerInvalid } from "../../../common/protocol-handler";
|
||||
import { disposer, noop } from "../../../common/utils";
|
||||
import { disposer, noop } from "@k8slens/utilities";
|
||||
import type { BroadcastMessage } from "../../../common/ipc/broadcast-message.injectable";
|
||||
|
||||
export interface FallbackHandler {
|
||||
|
||||
@@ -14,9 +14,9 @@ import type { WriteFile } from "../../common/fs/write-file.injectable";
|
||||
import type { RemovePath } from "../../common/fs/remove.injectable";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { CreateKubectl } from "../kubectl/create-kubectl.injectable";
|
||||
import type { KubeconfigManager } from "../kubeconfig-manager/kubeconfig-manager";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export interface ResourceApplierDependencies {
|
||||
emitAppEvent: EmitAppEvent;
|
||||
@@ -81,13 +81,13 @@ export class ResourceApplier {
|
||||
throw result.error.stderr || result.error.message;
|
||||
}
|
||||
|
||||
async create(resource: string): Promise<AsyncResult<string, string>> {
|
||||
async create(resource: string): AsyncResult<string, string> {
|
||||
this.dependencies.emitAppEvent({ name: "resource", action: "apply" });
|
||||
|
||||
return this.kubectlApply(this.sanitizeObject(resource));
|
||||
}
|
||||
|
||||
protected async kubectlApply(content: string): Promise<AsyncResult<string, string>> {
|
||||
protected async kubectlApply(content: string): AsyncResult<string, string> {
|
||||
const kubectlPath = await this.getKubectlPath();
|
||||
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
|
||||
const fileName = tempy.file({ name: "resource.yaml" });
|
||||
@@ -125,15 +125,15 @@ export class ResourceApplier {
|
||||
}
|
||||
}
|
||||
|
||||
public async kubectlApplyAll(resources: string[], extraArgs = ["-o", "json"]): Promise<AsyncResult<string, string>> {
|
||||
public async kubectlApplyAll(resources: string[], extraArgs = ["-o", "json"]): AsyncResult<string, string> {
|
||||
return this.kubectlCmdAll("apply", resources, extraArgs);
|
||||
}
|
||||
|
||||
public async kubectlDeleteAll(resources: string[], extraArgs?: string[]): Promise<AsyncResult<string, string>> {
|
||||
public async kubectlDeleteAll(resources: string[], extraArgs?: string[]): AsyncResult<string, string> {
|
||||
return this.kubectlCmdAll("delete", resources, extraArgs);
|
||||
}
|
||||
|
||||
protected async kubectlCmdAll(subCmd: string, resources: string[], parentArgs: string[] = []): Promise<AsyncResult<string, string>> {
|
||||
protected async kubectlCmdAll(subCmd: string, resources: string[], parentArgs: string[] = []): AsyncResult<string, string> {
|
||||
const kubectlPath = await this.getKubectlPath();
|
||||
const proxyKubeconfigPath = await this.dependencies.proxyKubeconfigManager.ensurePath();
|
||||
const tmpDir = tempy.directory();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ServerResponse } from "http";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import { object } from "../../common/utils";
|
||||
import { object } from "@k8slens/utilities";
|
||||
import type { LensApiRequest, Route } from "./route";
|
||||
import { contentTypes } from "./router-content-types";
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ClusterMetadataKey } from "../../../common/cluster-types";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import { clusterRoute } from "../../router/route";
|
||||
import { isObject } from "lodash";
|
||||
import { isRequestError, object } from "../../../common/utils";
|
||||
import { isRequestError, object } from "@k8slens/utilities";
|
||||
import type { GetMetrics } from "../../get-metrics.injectable";
|
||||
import getMetricsInjectable from "../../get-metrics.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
import { isDefined } from "../../../common/utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
import mainExtensionsInjectable from "../../../extensions/main-extensions.injectable";
|
||||
import catalogEntityRegistryInjectable from "../../catalog/entity-registry.injectable";
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import type * as pty from "node-pty";
|
||||
import { getOrInsertWith } from "../../common/utils";
|
||||
import { getOrInsertWith } from "@k8slens/utilities";
|
||||
import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { ComputeShellEnvironment } from "../../features/shell-sync/main/compute-shell-environment.injectable";
|
||||
|
||||
@@ -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 spawnPtyInjectable from "./spawn-pty.injectable";
|
||||
|
||||
export default getGlobalOverride(spawnPtyInjectable, () => () => {
|
||||
|
||||
+1
-1
@@ -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, () => () => ({
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
+4
-11
@@ -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;
|
||||
+1
-1
@@ -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";
|
||||
|
||||
-10
@@ -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",
|
||||
});
|
||||
-10
@@ -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",
|
||||
});
|
||||
-10
@@ -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",
|
||||
});
|
||||
-10
@@ -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",
|
||||
});
|
||||
-10
@@ -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",
|
||||
});
|
||||
-10
@@ -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",
|
||||
});
|
||||
-10
@@ -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",
|
||||
});
|
||||
+1
-2
@@ -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(),
|
||||
}),
|
||||
|
||||
|
||||
+8
-11
@@ -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,
|
||||
});
|
||||
|
||||
+6
-9
@@ -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,
|
||||
});
|
||||
|
||||
+10
-13
@@ -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,
|
||||
});
|
||||
|
||||
+11
-14
@@ -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,
|
||||
});
|
||||
|
||||
+32
-37
@@ -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,
|
||||
|
||||
|
||||
+7
-10
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
+10
-13
@@ -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,
|
||||
});
|
||||
|
||||
Loaded 100 of 754 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user