Move activating cluster into injectable IPC (#7355)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-15 08:26:28 -04:00
1 parent 121a50ecf3
commit 497f63fde6
12 files changed
+122 -38

No files matched your search

@@ -0,0 +1,18 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ClusterId } from "../../../../common/cluster-types";
import { getRequestChannel } from "../../../../common/utils/channel/get-request-channel";
export interface ActivateCluster {
clusterId: ClusterId;
/**
* @default false
*/
force?: boolean;
}
export const activateClusterChannel = getRequestChannel<ActivateCluster, void>("activate-cluster");
@@ -0,0 +1,14 @@
/**
* 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 { ChannelRequester } from "../../../../common/utils/channel/request-from-channel-injection-token";
import type { activateClusterChannel } from "./channels";
export type RequestClusterActivation = ChannelRequester<typeof activateClusterChannel>;
export const requestClusterActivationInjectionToken = getInjectionToken<RequestClusterActivation>({
id: "request-cluster-activation-token",
});
@@ -0,0 +1,14 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
import { activateClusterChannel } from "../common/channels";
import requestClusterActivationInjectable from "./request-activation.injectable";
const activateClusterRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
channel: activateClusterChannel,
handler: (di) => di.inject(requestClusterActivationInjectable),
});
export default activateClusterRequestChannelListenerInjectable;
@@ -0,0 +1,30 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable";
import { requestClusterActivationInjectionToken } from "../common/request-token";
const requestClusterActivationInjectable = getInjectable({
id: "request-cluster-activation",
instantiate: (di) => {
const getClusterById = di.inject(getClusterByIdInjectable);
return async ({ clusterId, force = false }) => {
const cluster = getClusterById(clusterId);
if (!cluster) {
return;
}
const connection = di.inject(clusterConnectionInjectable, cluster);
await connection.activate(force);
};
},
injectionToken: requestClusterActivationInjectionToken,
});
export default requestClusterActivationInjectable;
@@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
import { activateClusterChannel } from "../common/channels";
import { requestClusterActivationInjectionToken } from "../common/request-token";
const requestClusterActivationInjectable = getInjectable({
id: "request-cluster-activation",
instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectable);
return (req) => requestFromChannel(activateClusterChannel, req);
},
injectionToken: requestClusterActivationInjectionToken,
});
export default requestClusterActivationInjectable;