mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add more specific IPC helpers
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
eb6021df0d
commit
492fa6f649
@ -22,12 +22,12 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import Config from "conf";
|
import Config from "conf";
|
||||||
import type { Options as ConfOptions } from "conf/dist/source/types";
|
import type { Options as ConfOptions } from "conf/dist/source/types";
|
||||||
import { app, ipcMain, IpcMainEvent, ipcRenderer, IpcRendererEvent, remote } from "electron";
|
import { app, ipcMain, ipcRenderer, remote } from "electron";
|
||||||
import { IReactionOptions, observable, reaction, runInAction, when } from "mobx";
|
import { IReactionOptions, observable, reaction, runInAction, when } from "mobx";
|
||||||
import Singleton from "./utils/singleton";
|
import Singleton from "./utils/singleton";
|
||||||
import { getAppVersion } from "./utils/app-version";
|
import { getAppVersion } from "./utils/app-version";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
import { broadcastMessage, ipcMainOn, ipcRendererOn } from "./ipc";
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
|
|
||||||
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||||
@ -118,23 +118,17 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (ipcMain) {
|
if (ipcMain) {
|
||||||
const callback = (event: IpcMainEvent, model: T) => {
|
this.syncDisposers.push(ipcMainOn(this.syncMainChannel, (event, model: T) => {
|
||||||
logger.silly(`[STORE]: SYNC ${this.name} from renderer`, { model });
|
logger.silly(`[STORE]: SYNC ${this.name} from renderer`, { model });
|
||||||
this.onSync(model);
|
this.onSync(model);
|
||||||
};
|
}));
|
||||||
|
|
||||||
subscribeToBroadcast(this.syncMainChannel, callback);
|
|
||||||
this.syncDisposers.push(() => unsubscribeFromBroadcast(this.syncMainChannel, callback));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
const callback = (event: IpcRendererEvent, model: T) => {
|
this.syncDisposers.push(ipcRendererOn(this.syncRendererChannel, (event, model: T) => {
|
||||||
logger.silly(`[STORE]: SYNC ${this.name} from main`, { model });
|
logger.silly(`[STORE]: SYNC ${this.name} from main`, { model });
|
||||||
this.onSyncFromMain(model);
|
this.onSyncFromMain(model);
|
||||||
};
|
}));
|
||||||
|
|
||||||
subscribeToBroadcast(this.syncRendererChannel, callback);
|
|
||||||
this.syncDisposers.push(() => unsubscribeFromBroadcast(this.syncRendererChannel, callback));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { handleRequest } from "./ipc";
|
|
||||||
import { ClusterId, ClusterStore } from "./cluster-store";
|
import { ClusterId, ClusterStore } from "./cluster-store";
|
||||||
import { appEventBus } from "./event-bus";
|
import { appEventBus } from "./event-bus";
|
||||||
import { ResourceApplier } from "../main/resource-applier";
|
import { ResourceApplier } from "../main/resource-applier";
|
||||||
@ -34,13 +33,13 @@ export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
|||||||
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
||||||
|
|
||||||
if (ipcMain) {
|
if (ipcMain) {
|
||||||
handleRequest(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
ipcMain.handle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
||||||
return ClusterStore.getInstance()
|
return ClusterStore.getInstance()
|
||||||
.getById(clusterId)
|
.getById(clusterId)
|
||||||
?.activate(force);
|
?.activate(force);
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
ipcMain.handle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
if (cluster) {
|
if (cluster) {
|
||||||
@ -49,13 +48,13 @@ if (ipcMain) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterRefreshHandler, (event, clusterId: ClusterId) => {
|
ipcMain.handle(clusterRefreshHandler, (event, clusterId: ClusterId) => {
|
||||||
return ClusterStore.getInstance()
|
return ClusterStore.getInstance()
|
||||||
.getById(clusterId)
|
.getById(clusterId)
|
||||||
?.refresh({ refreshMetadata: true });
|
?.refresh({ refreshMetadata: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
ipcMain.handle(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
||||||
appEventBus.emit({name: "cluster", action: "stop"});
|
appEventBus.emit({name: "cluster", action: "stop"});
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
@ -65,7 +64,7 @@ if (ipcMain) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterKubectlApplyAllHandler, async (event, clusterId: ClusterId, resources: string[], extraArgs: string[]) => {
|
ipcMain.handle(clusterKubectlApplyAllHandler, async (event, clusterId: ClusterId, resources: string[], extraArgs: string[]) => {
|
||||||
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"});
|
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"});
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ if (ipcMain) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterKubectlDeleteAllHandler, async (event, clusterId: ClusterId, resources: string[], extraArgs: string[]) => {
|
ipcMain.handle(clusterKubectlDeleteAllHandler, async (event, clusterId: ClusterId, resources: string[], extraArgs: string[]) => {
|
||||||
appEventBus.emit({name: "cluster", action: "kubectl-delete-all"});
|
appEventBus.emit({name: "cluster", action: "kubectl-delete-all"});
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import { appEventBus } from "./event-bus";
|
|||||||
import { dumpConfigYaml } from "./kube-helpers";
|
import { dumpConfigYaml } from "./kube-helpers";
|
||||||
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
||||||
import type { KubeConfig } from "@kubernetes/client-node";
|
import type { KubeConfig } from "@kubernetes/client-node";
|
||||||
import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
|
import { ipcMainOn, ipcRendererOn, requestMain } from "./ipc";
|
||||||
import type { ResourceType } from "../renderer/components/cluster-settings/components/cluster-metrics-setting";
|
import type { ResourceType } from "../renderer/components/cluster-settings/components/cluster-metrics-setting";
|
||||||
import { disposer, noop } from "./utils";
|
import { disposer, noop } from "./utils";
|
||||||
|
|
||||||
@ -114,6 +114,8 @@ export interface ClusterPrometheusPreferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||||
|
private static StateChannel = "cluster:state";
|
||||||
|
|
||||||
static get storedKubeConfigFolder(): string {
|
static get storedKubeConfigFolder(): string {
|
||||||
return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs");
|
return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs");
|
||||||
}
|
}
|
||||||
@ -170,7 +172,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (ipcMain) {
|
} else if (ipcMain) {
|
||||||
handleRequest(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
ipcMain.handle(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
||||||
const states: clusterStateSync[] = [];
|
const states: clusterStateSync[] = [];
|
||||||
|
|
||||||
this.clustersList.forEach((cluster) => {
|
this.clustersList.forEach((cluster) => {
|
||||||
@ -191,17 +193,25 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
reaction(() => this.connectedClustersList, () => {
|
reaction(() => this.connectedClustersList, () => {
|
||||||
this.pushState();
|
this.pushState();
|
||||||
}),
|
}),
|
||||||
() => unsubscribeAllFromBroadcast("cluster:state"),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleStateChange = (event: any, clusterId: string, state: ClusterState) => {
|
||||||
|
logger.silly(`[CLUSTER-STORE]: received push-state at ${location.host} (${webFrame.routingId})`, clusterId, state);
|
||||||
|
this.getById(clusterId)?.setState(state);
|
||||||
|
};
|
||||||
|
|
||||||
registerIpcListener() {
|
registerIpcListener() {
|
||||||
logger.info(`[CLUSTER-STORE] start to listen (${webFrame.routingId})`);
|
logger.info(`[CLUSTER-STORE] start to listen (${webFrame.routingId})`);
|
||||||
subscribeToBroadcast("cluster:state", (event, clusterId: string, state: ClusterState) => {
|
|
||||||
logger.silly(`[CLUSTER-STORE]: received push-state at ${location.host} (${webFrame.routingId})`, clusterId, state);
|
if (ipcMain) {
|
||||||
this.getById(clusterId)?.setState(state);
|
this.disposer.push(ipcMainOn(ClusterStore.StateChannel, this.handleStateChange));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (ipcRenderer) {
|
||||||
|
this.disposer.push(ipcRendererOn(ClusterStore.StateChannel, this.handleStateChange));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unregisterIpcListener() {
|
unregisterIpcListener() {
|
||||||
|
|||||||
@ -27,13 +27,10 @@ import { ipcMain, ipcRenderer, webContents, remote } from "electron";
|
|||||||
import { toJS } from "mobx";
|
import { toJS } from "mobx";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
import { ClusterFrameInfo, clusterFrameMap } from "../cluster-frames";
|
import { ClusterFrameInfo, clusterFrameMap } from "../cluster-frames";
|
||||||
|
import type { Disposer } from "../utils";
|
||||||
|
|
||||||
const subFramesChannel = "ipc:get-sub-frames";
|
const subFramesChannel = "ipc:get-sub-frames";
|
||||||
|
|
||||||
export function handleRequest(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) {
|
|
||||||
ipcMain.handle(channel, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function requestMain(channel: string, ...args: any[]) {
|
export async function requestMain(channel: string, ...args: any[]) {
|
||||||
return ipcRenderer.invoke(channel, ...args);
|
return ipcRenderer.invoke(channel, ...args);
|
||||||
}
|
}
|
||||||
@ -71,34 +68,18 @@ export function broadcastMessage(channel: string, ...args: any[]) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function subscribeToBroadcast(channel: string, listener: (...args: any[]) => any) {
|
export function ipcMainOn(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): Disposer {
|
||||||
if (ipcRenderer) {
|
ipcMain.on(channel, listener);
|
||||||
ipcRenderer.on(channel, listener);
|
|
||||||
} else if (ipcMain) {
|
|
||||||
ipcMain.on(channel, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
return listener;
|
return () => ipcMain.off(channel, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unsubscribeFromBroadcast(channel: string, listener: (...args: any[]) => any) {
|
export function ipcRendererOn(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => any): Disposer {
|
||||||
if (ipcRenderer) {
|
ipcRenderer.on(channel, listener);
|
||||||
ipcRenderer.off(channel, listener);
|
|
||||||
} else if (ipcMain) {
|
|
||||||
ipcMain.off(channel, listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function unsubscribeAllFromBroadcast(channel: string) {
|
return () => ipcRenderer.off(channel, listener);
|
||||||
if (ipcRenderer) {
|
|
||||||
ipcRenderer.removeAllListeners(channel);
|
|
||||||
} else if (ipcMain) {
|
|
||||||
ipcMain.removeAllListeners(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bindBroadcastHandlers() {
|
export function bindBroadcastHandlers() {
|
||||||
handleRequest(subFramesChannel, () => {
|
ipcMain.handle(subFramesChannel, getSubFrames);
|
||||||
return getSubFrames();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,13 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { watch } from "chokidar";
|
import { watch } from "chokidar";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcMain, ipcRenderer } from "electron";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { observable, reaction, toJS, when } from "mobx";
|
import { observable, reaction, toJS, when } from "mobx";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
|
import { broadcastMessage, ipcRendererOn, requestMain } from "../common/ipc";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { ExtensionInstallationStateStore } from "../renderer/components/+extensions/extension-install.store";
|
import { ExtensionInstallationStateStore } from "../renderer/components/+extensions/extension-install.store";
|
||||||
@ -130,13 +130,13 @@ export class ExtensionDiscovery extends Singleton {
|
|||||||
};
|
};
|
||||||
|
|
||||||
requestMain(ExtensionDiscovery.extensionDiscoveryChannel).then(onMessage);
|
requestMain(ExtensionDiscovery.extensionDiscoveryChannel).then(onMessage);
|
||||||
subscribeToBroadcast(ExtensionDiscovery.extensionDiscoveryChannel, (_event, message: ExtensionDiscoveryChannelMessage) => {
|
ipcRendererOn(ExtensionDiscovery.extensionDiscoveryChannel, (_event, message: ExtensionDiscoveryChannelMessage) => {
|
||||||
onMessage(message);
|
onMessage(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async initMain() {
|
async initMain() {
|
||||||
handleRequest(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
|
ipcMain.handle(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
|
||||||
|
|
||||||
reaction(() => this.toJSON(), () => {
|
reaction(() => this.toJSON(), () => {
|
||||||
this.broadcast();
|
this.broadcast();
|
||||||
|
|||||||
@ -19,13 +19,13 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { app, ipcRenderer, remote } from "electron";
|
import { app, ipcMain, ipcRenderer, remote } from "electron";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { action, computed, observable, reaction, toJS, when } from "mobx";
|
import { action, computed, observable, reaction, toJS, when } from "mobx";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { getHostedCluster } from "../common/cluster-store";
|
import { getHostedCluster } from "../common/cluster-store";
|
||||||
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
|
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain } from "../common/ipc";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import type { InstalledExtension } from "./extension-discovery";
|
import type { InstalledExtension } from "./extension-discovery";
|
||||||
@ -164,11 +164,11 @@ export class ExtensionLoader extends Singleton {
|
|||||||
this.broadcastExtensions();
|
this.broadcastExtensions();
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(ExtensionLoader.extensionsMainChannel, () => {
|
ipcMain.handle(ExtensionLoader.extensionsMainChannel, () => {
|
||||||
return Array.from(this.toJSON());
|
return Array.from(this.toJSON());
|
||||||
});
|
});
|
||||||
|
|
||||||
subscribeToBroadcast(ExtensionLoader.extensionsRendererChannel, (_event, extensions: [LensExtensionId, InstalledExtension][]) => {
|
ipcMainOn(ExtensionLoader.extensionsRendererChannel, (event, extensions: [LensExtensionId, InstalledExtension][]) => {
|
||||||
this.syncExtensions(extensions);
|
this.syncExtensions(extensions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ export class ExtensionLoader extends Singleton {
|
|||||||
});
|
});
|
||||||
|
|
||||||
requestMain(ExtensionLoader.extensionsMainChannel).then(extensionListHandler);
|
requestMain(ExtensionLoader.extensionsMainChannel).then(extensionListHandler);
|
||||||
subscribeToBroadcast(ExtensionLoader.extensionsMainChannel, (_event, extensions: [LensExtensionId, InstalledExtension][]) => {
|
ipcRendererOn(ExtensionLoader.extensionsMainChannel, (event, extensions: [LensExtensionId, InstalledExtension][]) => {
|
||||||
extensionListHandler(extensions);
|
extensionListHandler(extensions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { reaction, toJS } from "mobx";
|
import { reaction, toJS } from "mobx";
|
||||||
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "../common/ipc";
|
import { broadcastMessage, ipcMainOn } from "../common/ipc";
|
||||||
import type { CatalogEntityRegistry} from "../common/catalog";
|
import type { CatalogEntityRegistry} from "../common/catalog";
|
||||||
import "../common/catalog-entities/kubernetes-cluster";
|
import "../common/catalog-entities/kubernetes-cluster";
|
||||||
import type { Disposer } from "../common/utils";
|
import { disposer } from "../common/utils";
|
||||||
|
|
||||||
export class CatalogPusher {
|
export class CatalogPusher {
|
||||||
static init(catalog: CatalogEntityRegistry) {
|
static init(catalog: CatalogEntityRegistry) {
|
||||||
@ -33,20 +33,15 @@ export class CatalogPusher {
|
|||||||
private constructor(private catalog: CatalogEntityRegistry) {}
|
private constructor(private catalog: CatalogEntityRegistry) {}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
const disposers: Disposer[] = [];
|
return disposer(
|
||||||
|
reaction(() => toJS(this.catalog.items, { recurseEverything: true }), (items) => {
|
||||||
disposers.push(reaction(() => toJS(this.catalog.items, { recurseEverything: true }), (items) => {
|
broadcastMessage("catalog:items", items);
|
||||||
broadcastMessage("catalog:items", items);
|
}, {
|
||||||
}, {
|
fireImmediately: true,
|
||||||
fireImmediately: true,
|
}),
|
||||||
}));
|
ipcMainOn("catalog:broadcast", () => {
|
||||||
|
broadcastMessage("catalog:items", toJS(this.catalog.items, { recurseEverything: true }));
|
||||||
const listener = subscribeToBroadcast("catalog:broadcast", () => {
|
})
|
||||||
broadcastMessage("catalog:items", toJS(this.catalog.items, { recurseEverything: true }));
|
);
|
||||||
});
|
|
||||||
|
|
||||||
disposers.push(() => unsubscribeFromBroadcast("catalog:broadcast", listener));
|
|
||||||
|
|
||||||
return disposers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import { observable } from "mobx";
|
|||||||
import { app, BrowserWindow, dialog, shell, webContents } from "electron";
|
import { app, BrowserWindow, dialog, shell, webContents } from "electron";
|
||||||
import windowStateKeeper from "electron-window-state";
|
import windowStateKeeper from "electron-window-state";
|
||||||
import { appEventBus } from "../common/event-bus";
|
import { appEventBus } from "../common/event-bus";
|
||||||
import { subscribeToBroadcast } from "../common/ipc";
|
import { ipcMainOn } from "../common/ipc";
|
||||||
import { initMenu } from "./menu";
|
import { initMenu } from "./menu";
|
||||||
import { initTray } from "./tray";
|
import { initTray } from "./tray";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
@ -140,7 +140,7 @@ export class WindowManager extends Singleton {
|
|||||||
|
|
||||||
protected bindEvents() {
|
protected bindEvents() {
|
||||||
// track visible cluster from ui
|
// track visible cluster from ui
|
||||||
subscribeToBroadcast(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, (event, clusterId: ClusterId) => {
|
ipcMainOn(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, (event, clusterId: ClusterId) => {
|
||||||
this.activeClusterId = clusterId;
|
this.activeClusterId = clusterId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { action, observable } from "mobx";
|
import { action, observable } from "mobx";
|
||||||
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
import { broadcastMessage, ipcRendererOn } from "../../common/ipc";
|
||||||
import { CatalogCategory, CatalogEntity, CatalogEntityData, catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntityKindData } from "../../common/catalog";
|
import { CatalogCategory, CatalogEntity, CatalogEntityData, catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntityKindData } from "../../common/catalog";
|
||||||
import "../../common/catalog-entities";
|
import "../../common/catalog-entities";
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ export class CatalogEntityRegistry {
|
|||||||
constructor(private categoryRegistry: CatalogCategoryRegistry) {}
|
constructor(private categoryRegistry: CatalogCategoryRegistry) {}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
subscribeToBroadcast("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
|
ipcRendererOn("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
|
||||||
this.updateItems(items);
|
this.updateItems(items);
|
||||||
});
|
});
|
||||||
broadcastMessage("catalog:broadcast");
|
broadcastMessage("catalog:broadcast");
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import React from "react";
|
|||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import { computed, observable } from "mobx";
|
import { computed, observable } from "mobx";
|
||||||
import { requestMain, subscribeToBroadcast } from "../../../common/ipc";
|
import { ipcRendererOn, requestMain } from "../../../common/ipc";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { cssNames, IClassName } from "../../utils";
|
import { cssNames, IClassName } from "../../utils";
|
||||||
@ -54,7 +54,7 @@ export class ClusterStatus extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
subscribeToBroadcast(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
|
ipcRendererOn(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
|
||||||
this.authOutput.push({
|
this.authOutput.push({
|
||||||
data: res.data.trimRight(),
|
data: res.data.trimRight(),
|
||||||
error: res.error,
|
error: res.error,
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import { observer } from "mobx-react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Dialog } from "../dialog";
|
import { Dialog } from "../dialog";
|
||||||
import { EventEmitter } from "../../../common/event-emitter";
|
import { EventEmitter } from "../../../common/event-emitter";
|
||||||
import { subscribeToBroadcast } from "../../../common/ipc";
|
import { ipcRendererOn } from "../../../common/ipc";
|
||||||
import { CommandDialog } from "./command-dialog";
|
import { CommandDialog } from "./command-dialog";
|
||||||
import { CommandRegistration, CommandRegistry } from "../../../extensions/registries/command-registry";
|
import { CommandRegistration, CommandRegistry } from "../../../extensions/registries/command-registry";
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ export class CommandContainer extends React.Component<{ clusterId?: string }> {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.props.clusterId) {
|
if (this.props.clusterId) {
|
||||||
subscribeToBroadcast(`command-palette:run-action:${this.props.clusterId}`, (event, commandId: string) => {
|
ipcRendererOn(`command-palette:run-action:${this.props.clusterId}`, (event, commandId: string) => {
|
||||||
const command = this.findCommandById(commandId);
|
const command = this.findCommandById(commandId);
|
||||||
|
|
||||||
if (command) {
|
if (command) {
|
||||||
@ -82,7 +82,7 @@ export class CommandContainer extends React.Component<{ clusterId?: string }> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
subscribeToBroadcast("command-palette:open", () => {
|
ipcRendererOn("command-palette:open", () => {
|
||||||
CommandOverlay.open(<CommandDialog />);
|
CommandOverlay.open(<CommandDialog />);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { getMatchedClusterId, navigate } from "./helpers";
|
import { getMatchedClusterId, navigate } from "./helpers";
|
||||||
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
import { broadcastMessage, ipcRendererOn } from "../../common/ipc";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
|
|
||||||
export const enum IpcRendererNavigationEvents {
|
export const enum IpcRendererNavigationEvents {
|
||||||
@ -45,7 +45,7 @@ export function bindEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload dashboard window
|
// Reload dashboard window
|
||||||
subscribeToBroadcast(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
|
ipcRendererOn(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ function bindClusterManagerRouteEvents() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle navigation via IPC
|
// Handle navigation via IPC
|
||||||
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
|
ipcRendererOn(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
|
||||||
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
||||||
navigate(url);
|
navigate(url);
|
||||||
});
|
});
|
||||||
@ -68,7 +68,7 @@ function bindClusterManagerRouteEvents() {
|
|||||||
|
|
||||||
// Handle cluster-view renderer process events within iframes
|
// Handle cluster-view renderer process events within iframes
|
||||||
function bindClusterFrameRouteEvents() {
|
function bindClusterFrameRouteEvents() {
|
||||||
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
|
ipcRendererOn(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
|
||||||
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
||||||
navigate(url);
|
navigate(url);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user