Merge branch 'refactor-ipc' into split-cluster-to-managed-cluster

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen committed 2020-11-19 11:15:30 +02:00
commit 1d910739e2
8 files changed
+62 -48

No files matched your search

+4 -4
View File
@@ -37,12 +37,12 @@ export class BaseStore<T = any> extends Singleton {
return path.basename(this.storeConfig.path);
}
get syncRendererChannel() {
return `store-sync-renderer:${this.name}`
protected get syncRendererChannel() {
return `store-sync-renderer:${this.path}`
}
get syncMainChannel() {
return `store-sync-main:${this.name}`
protected get syncMainChannel() {
return `store-sync-main:${this.path}`
}
get path() {
+3
View File
@@ -0,0 +1,3 @@
import { observable } from "mobx"
export const clusterFrameMap = observable.map<string, number>();
+7 -2
View File
@@ -4,6 +4,7 @@ import { appEventBus } from "./event-bus"
import { ResourceApplier } from "../main/resource-applier";
import { ipcMain } from "electron";
import { ClusterManager } from "../main/cluster-manager";
import { clusterFrameMap } from "./cluster-frames"
export const clusterActivateHandler = "cluster:activate"
export const clusterSetFrameIdHandler = "cluster:set-frame-id"
@@ -23,7 +24,7 @@ if (ipcMain) {
handleRequest(clusterSetFrameIdHandler, (event, clusterId: ClusterId, frameId?: number) => {
const managedCluster = getById(clusterId);
if (managedCluster) {
if (frameId) managedCluster.cluster.frameId = frameId; // save cluster's webFrame.routingId to be able to send push-updates
clusterFrameMap.set(managedCluster.cluster.id, frameId)
return managedCluster.cluster.pushState();
}
})
@@ -34,7 +35,11 @@ if (ipcMain) {
handleRequest(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
appEventBus.emit({name: "cluster", action: "stop"});
return getById(clusterId)?.disconnect();
const managedCluster = getById(clusterId);
if (managedCluster) {
managedCluster.disconnect();
clusterFrameMap.delete(managedCluster.id)
}
})
handleRequest(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
+4 -6
View File
@@ -2,8 +2,9 @@
// https://www.electronjs.org/docs/api/ipc-main
// https://www.electronjs.org/docs/api/ipc-renderer
import { ipcMain, ipcRenderer, webContents, remote } from "electron"
import { ipcMain, ipcRenderer, webContents, remote } from "electron";
import logger from "../main/logger";
import { clusterFrameMap } from "./cluster-frames";
export function handleRequest(channel: string, listener: (...args: any[]) => any) {
ipcMain.handle(channel, listener)
@@ -15,11 +16,8 @@ export async function requestMain(channel: string, ...args: any[]) {
async function getSubFrames(): Promise<number[]> {
const subFrames: number[] = [];
const { clusterStore } = await import("./cluster-store");
clusterStore.clustersList.forEach(cluster => {
if (cluster.frameId) {
subFrames.push(cluster.frameId)
}
clusterFrameMap.forEach((frameId, _) => {
subFrames.push(frameId)
});
return subFrames;
}