mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move deactivating a cluster into injectable IPC (#7356)
* Move activating cluster into injectable IPC Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move deactivating a cluster into injectable IPC Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
497f63fde6
commit
ae9a8c3c41
16 files changed
+111
-96
No files matched your search
@@ -16,3 +16,5 @@ export interface ActivateCluster {
|
||||
}
|
||||
|
||||
export const activateClusterChannel = getRequestChannel<ActivateCluster, void>("activate-cluster");
|
||||
|
||||
export const deactivateClusterChannel = getRequestChannel<ClusterId, void>("deactivate-cluster");
|
||||
@@ -5,10 +5,16 @@
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { ChannelRequester } from "../../../../common/utils/channel/request-from-channel-injection-token";
|
||||
import type { activateClusterChannel } from "./channels";
|
||||
import type { activateClusterChannel, deactivateClusterChannel } from "./channels";
|
||||
|
||||
export type RequestClusterActivation = ChannelRequester<typeof activateClusterChannel>;
|
||||
|
||||
export const requestClusterActivationInjectionToken = getInjectionToken<RequestClusterActivation>({
|
||||
id: "request-cluster-activation-token",
|
||||
});
|
||||
|
||||
export type RequestClusterDeactivation = ChannelRequester<typeof deactivateClusterChannel>;
|
||||
|
||||
export const requestClusterDeactivationInjectionToken = getInjectionToken<RequestClusterDeactivation>({
|
||||
id: "request-cluster-deactivation-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 { deactivateClusterChannel } from "../common/channels";
|
||||
import requestClusterDeactivationInjectable from "./request-deactivation.injectable";
|
||||
|
||||
const clusterDeactivationRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: deactivateClusterChannel,
|
||||
handler: (di) => di.inject(requestClusterDeactivationInjectable),
|
||||
});
|
||||
|
||||
export default clusterDeactivationRequestChannelListenerInjectable;
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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 emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable";
|
||||
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
|
||||
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||
import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable";
|
||||
import { requestClusterDeactivationInjectionToken } from "../common/request-token";
|
||||
|
||||
const requestClusterDeactivationInjectable = getInjectable({
|
||||
id: "request-cluster-deactivation",
|
||||
instantiate: (di) => {
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||
|
||||
return async (clusterId) => {
|
||||
emitAppEvent({ name: "cluster", action: "stop" });
|
||||
|
||||
const cluster = getClusterById(clusterId);
|
||||
|
||||
if (!cluster) {
|
||||
return;
|
||||
}
|
||||
|
||||
const connection = di.inject(clusterConnectionInjectable, cluster);
|
||||
|
||||
connection.disconnect();
|
||||
clusterFrames.delete(clusterId);
|
||||
};
|
||||
},
|
||||
injectionToken: requestClusterDeactivationInjectionToken,
|
||||
});
|
||||
|
||||
export default requestClusterDeactivationInjectable;
|
||||
+20
@@ -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 { deactivateClusterChannel } from "../common/channels";
|
||||
import { requestClusterDeactivationInjectionToken } from "../common/request-token";
|
||||
|
||||
const requestClusterDeactivationInjectable = getInjectable({
|
||||
id: "request-cluster-deactivation",
|
||||
instantiate: (di) => {
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectable);
|
||||
|
||||
return (clusterId) => requestFromChannel(deactivateClusterChannel, clusterId);
|
||||
},
|
||||
injectionToken: requestClusterDeactivationInjectionToken,
|
||||
});
|
||||
|
||||
export default requestClusterDeactivationInjectable;
|
||||
Reference in new issue
Block a user