mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Add distinction between `getInstance` and `getInstanceOrCreate` since it is not always possible to create an instance (since you might not know the correct arguments) - Remove all the `export const *Store = *Store.getInstance<*Store>();` calls as it defeats the purpose of `Singleton`. Plus with the typing changes the appropriate `*Store.getInstance()` is "short enough". - Special case the two extension export facades to not need to use `getInstanceOrCreate`. Plus since they are just facades it is always possible to create them. - Move some other types to be also `Singleton`'s: ExtensionLoader, ExtensionDiscovery, ThemeStore, LocalizationStore, ... - Fixed dev-run always using the same port with electron inspect - Update Store documentation with new recommendations about creating instances of singletons - Fix all unit tests to create their dependent singletons Signed-off-by: Sebastian Malton <sebastian@malton.name>
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { handleRequest } from "./ipc";
|
|
import { ClusterId, ClusterStore } from "./cluster-store";
|
|
import { appEventBus } from "./event-bus";
|
|
import { ResourceApplier } from "../main/resource-applier";
|
|
import { ipcMain, IpcMainInvokeEvent } from "electron";
|
|
import { clusterFrameMap } from "./cluster-frames";
|
|
|
|
export const clusterActivateHandler = "cluster:activate";
|
|
export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
|
export const clusterRefreshHandler = "cluster:refresh";
|
|
export const clusterDisconnectHandler = "cluster:disconnect";
|
|
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
|
|
|
if (ipcMain) {
|
|
handleRequest(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
|
|
|
if (cluster) {
|
|
return cluster.activate(force);
|
|
}
|
|
});
|
|
|
|
handleRequest(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
|
|
|
if (cluster) {
|
|
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
|
|
|
|
return cluster.pushState();
|
|
}
|
|
});
|
|
|
|
handleRequest(clusterRefreshHandler, (event, clusterId: ClusterId) => {
|
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
|
|
|
if (cluster) return cluster.refresh({ refreshMetadata: true });
|
|
});
|
|
|
|
handleRequest(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
|
appEventBus.emit({name: "cluster", action: "stop"});
|
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
|
|
|
if (cluster) {
|
|
cluster.disconnect();
|
|
clusterFrameMap.delete(cluster.id);
|
|
}
|
|
});
|
|
|
|
handleRequest(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
|
|
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"});
|
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
|
|
|
if (cluster) {
|
|
const applier = new ResourceApplier(cluster);
|
|
|
|
applier.kubectlApplyAll(resources);
|
|
} else {
|
|
throw `${clusterId} is not a valid cluster id`;
|
|
}
|
|
});
|
|
}
|