mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Split out more ipc channels
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
0e69d26e14
commit
36cb5aa006
@ -15,7 +15,7 @@ import { ipcMainHandle } from "../ipc";
|
|||||||
import { disposer, toJS } from "../utils";
|
import { disposer, toJS } from "../utils";
|
||||||
import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types";
|
import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types";
|
||||||
import { requestInitialClusterStates } from "../../renderer/ipc";
|
import { requestInitialClusterStates } from "../../renderer/ipc";
|
||||||
import { clusterStates } from "../cluster-ipc";
|
import { clusterStates } from "../ipc/cluster";
|
||||||
|
|
||||||
export interface ClusterStoreModel {
|
export interface ClusterStoreModel {
|
||||||
clusters?: ClusterModel[];
|
clusters?: ClusterModel[];
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
import { action, comparer, computed, makeObservable, observable, reaction, when } from "mobx";
|
import { action, comparer, computed, makeObservable, observable, reaction, when } from "mobx";
|
||||||
import { broadcastMessage, ClusterListNamespaceForbiddenChannel } from "../ipc";
|
import { broadcastMessage } from "../ipc";
|
||||||
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
||||||
import { AuthorizationV1Api, CoreV1Api, HttpError, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
|
import { AuthorizationV1Api, CoreV1Api, HttpError, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
|
||||||
import type { Kubectl } from "../../main/kubectl/kubectl";
|
import type { Kubectl } from "../../main/kubectl/kubectl";
|
||||||
@ -20,6 +20,7 @@ import type { ClusterState, ClusterRefreshOptions, ClusterMetricsResourceType, C
|
|||||||
import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus } from "../cluster-types";
|
import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus } from "../cluster-types";
|
||||||
import { disposer, toJS } from "../utils";
|
import { disposer, toJS } from "../utils";
|
||||||
import type { Response } from "request";
|
import type { Response } from "request";
|
||||||
|
import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
directoryForKubeConfigs: string,
|
directoryForKubeConfigs: string,
|
||||||
@ -641,7 +642,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
const { response } = error as HttpError & { response: Response };
|
const { response } = error as HttpError & { response: Response };
|
||||||
|
|
||||||
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body });
|
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body });
|
||||||
broadcastMessage(ClusterListNamespaceForbiddenChannel, this.id);
|
broadcastMessage(clusterListNamespaceForbiddenChannel, this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return namespaceList;
|
return namespaceList;
|
||||||
|
|||||||
@ -10,8 +10,9 @@ import { toJS } from "./utils";
|
|||||||
import { CatalogEntity } from "./catalog";
|
import { CatalogEntity } from "./catalog";
|
||||||
import { catalogEntity } from "../main/catalog-sources/general";
|
import { catalogEntity } from "../main/catalog-sources/general";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { broadcastMessage, HotbarTooManyItems } from "./ipc";
|
import { broadcastMessage } from "./ipc";
|
||||||
import { defaultHotbarCells, getEmptyHotbar, Hotbar, CreateHotbarData, CreateHotbarOptions } from "./hotbar-types";
|
import { defaultHotbarCells, getEmptyHotbar, Hotbar, CreateHotbarData, CreateHotbarOptions } from "./hotbar-types";
|
||||||
|
import { hotbarTooManyItemsChannel } from "./ipc/hotbar";
|
||||||
|
|
||||||
export interface HotbarStoreModel {
|
export interface HotbarStoreModel {
|
||||||
hotbars: Hotbar[];
|
hotbars: Hotbar[];
|
||||||
@ -182,7 +183,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
if (emptyCellIndex != -1) {
|
if (emptyCellIndex != -1) {
|
||||||
hotbar.items[emptyCellIndex] = newItem;
|
hotbar.items[emptyCellIndex] = newItem;
|
||||||
} else {
|
} else {
|
||||||
broadcastMessage(HotbarTooManyItems);
|
broadcastMessage(hotbarTooManyItemsChannel);
|
||||||
}
|
}
|
||||||
} else if (0 <= cellIndex && cellIndex < hotbar.items.length) {
|
} else if (0 <= cellIndex && cellIndex < hotbar.items.length) {
|
||||||
hotbar.items[cellIndex] = newItem;
|
hotbar.items[cellIndex] = newItem;
|
||||||
|
|||||||
@ -3,14 +3,17 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export enum CatalogIpcEvents {
|
/**
|
||||||
/**
|
* This is used to activate a specific entity in the renderer main frame
|
||||||
* This is broadcast on whenever there is an update to any catalog item
|
*/
|
||||||
*/
|
export const catalogEntityRunListener = "catalog-entity:run";
|
||||||
ITEMS = "catalog:items",
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This can be sent from renderer to main to initialize a broadcast of ITEMS
|
* This is broadcast on whenever there is an update to any catalog item
|
||||||
*/
|
*/
|
||||||
INIT = "catalog:init",
|
export const catalogItemsChannel = "catalog:items";
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* This can be sent from renderer to main to initialize a broadcast of ITEMS
|
||||||
|
*/
|
||||||
|
export const catalogInitChannel = "catalog:init";
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This channel is broadcast on whenever the cluster fails to list namespaces
|
|
||||||
* during a refresh and no `accessibleNamespaces` have been set.
|
|
||||||
*/
|
|
||||||
export const ClusterListNamespaceForbiddenChannel = "cluster:list-namespace-forbidden";
|
|
||||||
|
|
||||||
export type ListNamespaceForbiddenArgs = [clusterId: string];
|
|
||||||
|
|
||||||
export function isListNamespaceForbiddenArgs(args: unknown[]): args is ListNamespaceForbiddenArgs {
|
|
||||||
return args.length === 1 && typeof args[0] === "string";
|
|
||||||
}
|
|
||||||
@ -14,3 +14,15 @@ export const clusterClearDeletingHandler = "cluster:deleting:clear";
|
|||||||
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
||||||
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
||||||
export const clusterStates = "cluster:states";
|
export const clusterStates = "cluster:states";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This channel is broadcast on whenever the cluster fails to list namespaces
|
||||||
|
* during a refresh and no `accessibleNamespaces` have been set.
|
||||||
|
*/
|
||||||
|
export const clusterListNamespaceForbiddenChannel = "cluster:list-namespace-forbidden";
|
||||||
|
|
||||||
|
export type ListNamespaceForbiddenArgs = [clusterId: string];
|
||||||
|
|
||||||
|
export function isListNamespaceForbiddenArgs(args: unknown[]): args is ListNamespaceForbiddenArgs {
|
||||||
|
return args.length === 1 && typeof args[0] === "string";
|
||||||
|
}
|
||||||
@ -3,4 +3,4 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const HotbarTooManyItems = "hotbar:too-many-items";
|
export const hotbarTooManyItemsChannel = "hotbar:too-many-items";
|
||||||
|
|||||||
@ -3,13 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const dialogShowOpenDialogHandler = "dialog:show-open-dialog";
|
|
||||||
export const catalogEntityRunListener = "catalog-entity:run";
|
|
||||||
|
|
||||||
export * from "./ipc";
|
export * from "./ipc";
|
||||||
export * from "./invalid-kubeconfig";
|
export * from "./invalid-kubeconfig";
|
||||||
export * from "./update-available.ipc";
|
export * from "./update-available";
|
||||||
export * from "./cluster.ipc";
|
|
||||||
export * from "./type-enforced-ipc";
|
export * from "./type-enforced-ipc";
|
||||||
export * from "./hotbar";
|
|
||||||
export * from "./window";
|
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported actions on the current window
|
|
||||||
*/
|
|
||||||
export enum WindowAction {
|
|
||||||
/**
|
|
||||||
* Request that the current window goes back one step of browser history
|
|
||||||
*/
|
|
||||||
GO_BACK = "back",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request that the current window goes forward one step of browser history
|
|
||||||
*/
|
|
||||||
GO_FORWARD = "forward",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request that the current window is minimized
|
|
||||||
*/
|
|
||||||
MINIMIZE = "minimize",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request that the current window is maximized if it isn't, or unmaximized
|
|
||||||
* if it is
|
|
||||||
*/
|
|
||||||
TOGGLE_MAXIMIZE = "toggle-maximize",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request that the current window is closed
|
|
||||||
*/
|
|
||||||
CLOSE = "close",
|
|
||||||
}
|
|
||||||
@ -3,8 +3,37 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const enum IpcMainWindowEvents {
|
export const windowActionHandleChannel = "window:window-action";
|
||||||
OPEN_CONTEXT_MENU = "window:open-context-menu",
|
export const windowOpenAppMenuAsContextMenuChannel = "window:open-app-context-menu";
|
||||||
WINDOW_ACTION = "window:window-action",
|
export const windowLocationChangedChannel = "window:location-changed";
|
||||||
LOCATION_CHANGED = "window:location-changed",
|
|
||||||
|
/**
|
||||||
|
* The supported actions on the current window. The argument for `windowActionHandleChannel`
|
||||||
|
*/
|
||||||
|
export enum WindowAction {
|
||||||
|
/**
|
||||||
|
* Request that the current window goes back one step of browser history
|
||||||
|
*/
|
||||||
|
GO_BACK = "back",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the current window goes forward one step of browser history
|
||||||
|
*/
|
||||||
|
GO_FORWARD = "forward",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the current window is minimized
|
||||||
|
*/
|
||||||
|
MINIMIZE = "minimize",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the current window is maximized if it isn't, or unmaximized
|
||||||
|
* if it is
|
||||||
|
*/
|
||||||
|
TOGGLE_MAXIMIZE = "toggle-maximize",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the current window is closed
|
||||||
|
*/
|
||||||
|
CLOSE = "close",
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,15 +10,15 @@ import "../common/catalog-entities/kubernetes-cluster";
|
|||||||
import { disposer, toJS } from "../common/utils";
|
import { disposer, toJS } from "../common/utils";
|
||||||
import { debounce } from "lodash";
|
import { debounce } from "lodash";
|
||||||
import type { CatalogEntity } from "../common/catalog";
|
import type { CatalogEntity } from "../common/catalog";
|
||||||
import { CatalogIpcEvents } from "../common/ipc/catalog";
|
import { catalogInitChannel, catalogItemsChannel } from "../common/ipc/catalog";
|
||||||
|
|
||||||
const broadcaster = debounce((items: CatalogEntity[]) => {
|
const broadcaster = debounce((items: CatalogEntity[]) => {
|
||||||
broadcastMessage(CatalogIpcEvents.ITEMS, items);
|
broadcastMessage(catalogItemsChannel, items);
|
||||||
}, 1_000, { leading: true, trailing: true });
|
}, 1_000, { leading: true, trailing: true });
|
||||||
|
|
||||||
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
||||||
return disposer(
|
return disposer(
|
||||||
ipcMainOn(CatalogIpcEvents.INIT, () => broadcaster(toJS(catalog.items))),
|
ipcMainOn(catalogInitChannel, () => broadcaster(toJS(catalog.items))),
|
||||||
reaction(() => toJS(catalog.items), (items) => {
|
reaction(() => toJS(catalog.items), (items) => {
|
||||||
broadcaster(items);
|
broadcaster(items);
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "../common/cluster-ipc";
|
import "../common/ipc/cluster";
|
||||||
import type http from "http";
|
import type http from "http";
|
||||||
import { action, makeObservable, observable, observe, reaction, toJS } from "mobx";
|
import { action, makeObservable, observable, observe, reaction, toJS } from "mobx";
|
||||||
import { Cluster } from "../common/cluster/cluster";
|
import { Cluster } from "../common/cluster/cluster";
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BrowserWindow, dialog, IpcMainInvokeEvent, Menu } from "electron";
|
import { BrowserWindow, IpcMainInvokeEvent, Menu } from "electron";
|
||||||
import { clusterFrameMap } from "../../../common/cluster-frames";
|
import { clusterFrameMap } from "../../../common/cluster-frames";
|
||||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../../common/cluster-ipc";
|
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../../common/ipc/cluster";
|
||||||
import type { ClusterId } from "../../../common/cluster-types";
|
import type { ClusterId } from "../../../common/cluster-types";
|
||||||
import { ClusterStore } from "../../../common/cluster-store/cluster-store";
|
import { ClusterStore } from "../../../common/cluster-store/cluster-store";
|
||||||
import { appEventBus } from "../../../common/app-event-bus/event-bus";
|
import { appEventBus } from "../../../common/app-event-bus/event-bus";
|
||||||
import { broadcastMainChannel, broadcastMessage, dialogShowOpenDialogHandler, ipcMainHandle, ipcMainOn, IpcMainWindowEvents } from "../../../common/ipc";
|
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../common/ipc";
|
||||||
import { catalogEntityRegistry } from "../../catalog";
|
import { catalogEntityRegistry } from "../../catalog";
|
||||||
import { pushCatalogToRenderer } from "../../catalog-pusher";
|
import { pushCatalogToRenderer } from "../../catalog-pusher";
|
||||||
import { ClusterManager } from "../../cluster-manager";
|
import { ClusterManager } from "../../cluster-manager";
|
||||||
@ -23,6 +23,7 @@ import type { IComputedValue } from "mobx";
|
|||||||
import { onLocationChange, handleWindowAction } from "../../ipc/window";
|
import { onLocationChange, handleWindowAction } from "../../ipc/window";
|
||||||
import { openFilePickingDialogChannel } from "../../../common/ipc/dialog";
|
import { openFilePickingDialogChannel } from "../../../common/ipc/dialog";
|
||||||
import { showOpenDialog } from "../../ipc/dialog";
|
import { showOpenDialog } from "../../ipc/dialog";
|
||||||
|
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../common/ipc/window";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
electronMenuItems: IComputedValue<MenuRegistration[]>,
|
electronMenuItems: IComputedValue<MenuRegistration[]>,
|
||||||
@ -139,21 +140,15 @@ export const initIpcMainHandlers = ({ electronMenuItems, directoryForLensLocalSt
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMainHandle(dialogShowOpenDialogHandler, async (event, dialogOpts: Electron.OpenDialogOptions) => {
|
ipcMainHandle(windowActionHandleChannel, (event, action) => handleWindowAction(action));
|
||||||
await WindowManager.getInstance().ensureMainWindow();
|
|
||||||
|
|
||||||
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts);
|
ipcMainOn(windowLocationChangedChannel, () => onLocationChange());
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainHandle(IpcMainWindowEvents.WINDOW_ACTION, (event, action) => handleWindowAction(action));
|
|
||||||
|
|
||||||
ipcMainOn(IpcMainWindowEvents.LOCATION_CHANGED, () => onLocationChange());
|
|
||||||
|
|
||||||
ipcMainHandle(openFilePickingDialogChannel, (event, opts) => showOpenDialog(opts));
|
ipcMainHandle(openFilePickingDialogChannel, (event, opts) => showOpenDialog(opts));
|
||||||
|
|
||||||
ipcMainHandle(broadcastMainChannel, (event, channel, ...args) => broadcastMessage(channel, ...args));
|
ipcMainHandle(broadcastMainChannel, (event, channel, ...args) => broadcastMessage(channel, ...args));
|
||||||
|
|
||||||
ipcMainOn(IpcMainWindowEvents.OPEN_CONTEXT_MENU, async (event) => {
|
ipcMainOn(windowOpenAppMenuAsContextMenuChannel, async (event) => {
|
||||||
const menu = Menu.buildFromTemplate(getAppMenu(WindowManager.getInstance(), electronMenuItems.get()));
|
const menu = Menu.buildFromTemplate(getAppMenu(WindowManager.getInstance(), electronMenuItems.get()));
|
||||||
const options = {
|
const options = {
|
||||||
...BrowserWindow.fromWebContents(event.sender),
|
...BrowserWindow.fromWebContents(event.sender),
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { BrowserWindow, webContents } from "electron";
|
import { BrowserWindow, webContents } from "electron";
|
||||||
import { broadcastMessage } from "../../common/ipc";
|
import { broadcastMessage } from "../../common/ipc";
|
||||||
import { WindowAction } from "../../common/ipc/window-actions";
|
import { WindowAction } from "../../common/ipc/window";
|
||||||
|
|
||||||
export function handleWindowAction(action: WindowAction) {
|
export function handleWindowAction(action: WindowAction) {
|
||||||
const window = BrowserWindow.getFocusedWindow();
|
const window = BrowserWindow.getFocusedWindow();
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { computed, observable, makeObservable, action } from "mobx";
|
import { computed, observable, makeObservable, action } from "mobx";
|
||||||
import { catalogEntityRunListener, ipcRendererOn } from "../../common/ipc";
|
import { 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";
|
||||||
import type { Cluster } from "../../common/cluster/cluster";
|
import type { Cluster } from "../../common/cluster/cluster";
|
||||||
@ -14,7 +14,7 @@ import { once } from "lodash";
|
|||||||
import logger from "../../common/logger";
|
import logger from "../../common/logger";
|
||||||
import { CatalogRunEvent } from "../../common/catalog/catalog-run-event";
|
import { CatalogRunEvent } from "../../common/catalog/catalog-run-event";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import { CatalogIpcEvents } from "../../common/ipc/catalog";
|
import { catalogInitChannel, catalogItemsChannel, catalogEntityRunListener } from "../../common/ipc/catalog";
|
||||||
import { navigate } from "../navigation";
|
import { navigate } from "../navigation";
|
||||||
import { isMainFrame } from "process";
|
import { isMainFrame } from "process";
|
||||||
|
|
||||||
@ -79,12 +79,12 @@ export class CatalogEntityRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
ipcRendererOn(CatalogIpcEvents.ITEMS, (event, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
|
ipcRendererOn(catalogItemsChannel, (event, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
|
||||||
this.updateItems(items);
|
this.updateItems(items);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure that we get items ASAP and not the next time one of them changes
|
// Make sure that we get items ASAP and not the next time one of them changes
|
||||||
ipcRenderer.send(CatalogIpcEvents.INIT);
|
ipcRenderer.send(catalogInitChannel);
|
||||||
|
|
||||||
if (isMainFrame) {
|
if (isMainFrame) {
|
||||||
ipcRendererOn(catalogEntityRunListener, (event, id: string) => {
|
ipcRendererOn(catalogEntityRunListener, (event, id: string) => {
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import { withInjectables } from "@ogre-tools/injectable-react";
|
|||||||
import { computed, IComputedValue } from "mobx";
|
import { computed, IComputedValue } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { broadcastMessage, catalogEntityRunListener } from "../../../common/ipc";
|
import { broadcastMessage } from "../../../common/ipc";
|
||||||
|
import { catalogEntityRunListener } from "../../../common/ipc/catalog";
|
||||||
import type { CatalogEntity } from "../../api/catalog-entity";
|
import type { CatalogEntity } from "../../api/catalog-entity";
|
||||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||||
import commandOverlayInjectable from "../command-palette/command-overlay.injectable";
|
import commandOverlayInjectable from "../command-palette/command-overlay.injectable";
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { action, IReactionDisposer, makeObservable, observable, when } from "mobx";
|
import { action, IReactionDisposer, makeObservable, observable, when } from "mobx";
|
||||||
import logger from "../../../main/logger";
|
import logger from "../../../main/logger";
|
||||||
import { clusterVisibilityHandler } from "../../../common/cluster-ipc";
|
import { clusterVisibilityHandler } from "../../../common/ipc/cluster";
|
||||||
import { ClusterStore } from "../../../common/cluster-store/cluster-store";
|
import { ClusterStore } from "../../../common/cluster-store/cluster-store";
|
||||||
import type { ClusterId } from "../../../common/cluster-types";
|
import type { ClusterId } from "../../../common/cluster-types";
|
||||||
import { getClusterFrameUrl, Singleton } from "../../utils";
|
import { getClusterFrameUrl, Singleton } from "../../utils";
|
||||||
|
|||||||
@ -7,13 +7,14 @@ import React from "react";
|
|||||||
import { fireEvent } from "@testing-library/react";
|
import { fireEvent } from "@testing-library/react";
|
||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
import { TopBar } from "./top-bar";
|
import { TopBar } from "./top-bar";
|
||||||
import { IpcMainWindowEvents, broadcastMessage } from "../../../../common/ipc";
|
import { broadcastMessage } from "../../../../common/ipc";
|
||||||
import * as vars from "../../../../common/vars";
|
import * as vars from "../../../../common/vars";
|
||||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||||
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
||||||
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import { requestWindowAction } from "../../../ipc";
|
import { requestWindowAction } from "../../../ipc";
|
||||||
|
import { windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
|
||||||
|
|
||||||
const mockConfig = vars as { isWindows: boolean; isLinux: boolean };
|
const mockConfig = vars as { isWindows: boolean; isLinux: boolean };
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ describe("<TopBar/> in Windows and Linux", () => {
|
|||||||
const close = getByTestId("window-close");
|
const close = getByTestId("window-close");
|
||||||
|
|
||||||
fireEvent.click(menu);
|
fireEvent.click(menu);
|
||||||
expect(broadcastMessage).toHaveBeenCalledWith(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
|
expect(broadcastMessage).toHaveBeenCalledWith(windowOpenAppMenuAsContextMenuChannel);
|
||||||
|
|
||||||
fireEvent.click(minimize);
|
fireEvent.click(minimize);
|
||||||
expect(requestWindowAction).toHaveBeenCalledWith("minimize");
|
expect(requestWindowAction).toHaveBeenCalledWith("minimize");
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
|||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import { IpcMainWindowEvents } from "../../../../common/ipc";
|
|
||||||
|
|
||||||
jest.mock("../../../../common/vars", () => {
|
jest.mock("../../../../common/vars", () => {
|
||||||
const SemVer = require("semver").SemVer;
|
const SemVer = require("semver").SemVer;
|
||||||
@ -49,7 +48,7 @@ jest.mock(
|
|||||||
(channel: string, action: string) => {
|
(channel: string, action: string) => {
|
||||||
console.log("channel", channel, action);
|
console.log("channel", channel, action);
|
||||||
|
|
||||||
if (channel !== IpcMainWindowEvents.WINDOW_ACTION) return;
|
if (channel !== "window:window-action") return;
|
||||||
|
|
||||||
switch(action) {
|
switch(action) {
|
||||||
case "back": {
|
case "back": {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { observer } from "mobx-react";
|
|||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
import { Icon } from "../../icon";
|
import { Icon } from "../../icon";
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { broadcastMessage, IpcMainWindowEvents, ipcRendererOn } from "../../../../common/ipc";
|
import { ipcRendererOn } from "../../../../common/ipc";
|
||||||
import { watchHistoryState } from "../../../remote-helpers/history-updater";
|
import { watchHistoryState } from "../../../remote-helpers/history-updater";
|
||||||
import { isActiveRoute, navigate } from "../../../navigation";
|
import { isActiveRoute, navigate } from "../../../navigation";
|
||||||
import { catalogRoute, catalogURL } from "../../../../common/routes";
|
import { catalogRoute, catalogURL } from "../../../../common/routes";
|
||||||
@ -18,8 +18,8 @@ import { cssNames } from "../../../utils";
|
|||||||
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import type { TopBarRegistration } from "./top-bar-registration";
|
import type { TopBarRegistration } from "./top-bar-registration";
|
||||||
import { requestWindowAction } from "../../../ipc";
|
import { emitOpenAppMenuAsContextMenu, requestWindowAction } from "../../../ipc";
|
||||||
import { WindowAction } from "../../../../common/ipc/window-actions";
|
import { WindowAction } from "../../../../common/ipc/window";
|
||||||
|
|
||||||
interface Props extends React.HTMLAttributes<any> {}
|
interface Props extends React.HTMLAttributes<any> {}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ const NonInjectedTopBar = (({ items, children, ...rest }: Props & Dependencies)
|
|||||||
const elem = useRef<HTMLDivElement>();
|
const elem = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
const openContextMenu = () => {
|
const openContextMenu = () => {
|
||||||
broadcastMessage(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
|
emitOpenAppMenuAsContextMenu();
|
||||||
};
|
};
|
||||||
|
|
||||||
const goHome = () => {
|
const goHome = () => {
|
||||||
|
|||||||
@ -4,22 +4,34 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ipcRenderer, OpenDialogOptions } from "electron";
|
import { ipcRenderer, OpenDialogOptions } from "electron";
|
||||||
import { clusterActivateHandler, clusterClearDeletingHandler, clusterDeleteHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterSetDeletingHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/cluster-ipc";
|
import { clusterActivateHandler, clusterClearDeletingHandler, clusterDeleteHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterSetDeletingHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/ipc/cluster";
|
||||||
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
||||||
import { IpcMainWindowEvents } from "../../common/ipc";
|
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
||||||
import { openFilePickingDialogChannel } from "../../common/ipc/dialog";
|
import { openFilePickingDialogChannel } from "../../common/ipc/dialog";
|
||||||
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
||||||
import type { WindowAction } from "../../common/ipc/window-actions";
|
|
||||||
import type { InstalledExtension } from "../../extensions/extension-discovery/extension-discovery";
|
import type { InstalledExtension } from "../../extensions/extension-discovery/extension-discovery";
|
||||||
import type { LensExtensionId } from "../../extensions/lens-extension";
|
import type { LensExtensionId } from "../../extensions/lens-extension";
|
||||||
import { toJS } from "../utils";
|
import { toJS } from "../utils";
|
||||||
|
import type { Location } from "history";
|
||||||
|
|
||||||
function requestMain(channel: string, ...args: any[]) {
|
function requestMain(channel: string, ...args: any[]) {
|
||||||
return ipcRenderer.invoke(channel, ...args.map(toJS));
|
return ipcRenderer.invoke(channel, ...args.map(toJS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function emitToMain(channel: string, ...args: any[]) {
|
||||||
|
return ipcRenderer.send(channel, ...args.map(toJS));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function emitOpenAppMenuAsContextMenu(): void {
|
||||||
|
emitToMain(windowOpenAppMenuAsContextMenuChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function emitWindowLocationChanged(location: Location): void {
|
||||||
|
emitToMain(windowLocationChangedChannel, location);
|
||||||
|
}
|
||||||
|
|
||||||
export function requestWindowAction(type: WindowAction): Promise<void> {
|
export function requestWindowAction(type: WindowAction): Promise<void> {
|
||||||
return requestMain(IpcMainWindowEvents.WINDOW_ACTION, type);
|
return requestMain(windowActionHandleChannel, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestOpenFilePickingDialog(opts: OpenDialogOptions): Promise<{ canceled: boolean; filePaths: string[]; }> {
|
export function requestOpenFilePickingDialog(opts: OpenDialogOptions): Promise<{ canceled: boolean; filePaths: string[]; }> {
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ipcRenderer, IpcRendererEvent } from "electron";
|
import { ipcRenderer, IpcRendererEvent } from "electron";
|
||||||
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ClusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs, ListNamespaceForbiddenArgs, HotbarTooManyItems, ipcRendererOn, AutoUpdateChecking, AutoUpdateNoUpdateAvailable } from "../../common/ipc";
|
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ipcRendererOn, AutoUpdateChecking, AutoUpdateNoUpdateAvailable } from "../../common/ipc";
|
||||||
import { Notifications, notificationsStore } from "../components/notifications";
|
import { Notifications, notificationsStore } from "../components/notifications";
|
||||||
import { Button } from "../components/button";
|
import { Button } from "../components/button";
|
||||||
import { isMac } from "../../common/vars";
|
import { isMac } from "../../common/vars";
|
||||||
@ -13,6 +13,8 @@ import { ClusterStore } from "../../common/cluster-store/cluster-store";
|
|||||||
import { navigate } from "../navigation";
|
import { navigate } from "../navigation";
|
||||||
import { entitySettingsURL } from "../../common/routes";
|
import { entitySettingsURL } from "../../common/routes";
|
||||||
import { defaultHotbarCells } from "../../common/hotbar-types";
|
import { defaultHotbarCells } from "../../common/hotbar-types";
|
||||||
|
import { type ListNamespaceForbiddenArgs, clusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs } from "../../common/ipc/cluster";
|
||||||
|
import { hotbarTooManyItemsChannel } from "../../common/ipc/hotbar";
|
||||||
|
|
||||||
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
|
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
|
||||||
notificationsStore.remove(notificationId);
|
notificationsStore.remove(notificationId);
|
||||||
@ -127,13 +129,13 @@ export function registerIpcListeners() {
|
|||||||
});
|
});
|
||||||
onCorrect({
|
onCorrect({
|
||||||
source: ipcRenderer,
|
source: ipcRenderer,
|
||||||
channel: ClusterListNamespaceForbiddenChannel,
|
channel: clusterListNamespaceForbiddenChannel,
|
||||||
listener: ListNamespacesForbiddenHandler,
|
listener: ListNamespacesForbiddenHandler,
|
||||||
verifier: isListNamespaceForbiddenArgs,
|
verifier: isListNamespaceForbiddenArgs,
|
||||||
});
|
});
|
||||||
onCorrect({
|
onCorrect({
|
||||||
source: ipcRenderer,
|
source: ipcRenderer,
|
||||||
channel: HotbarTooManyItems,
|
channel: hotbarTooManyItemsChannel,
|
||||||
listener: HotbarTooManyItemsHandler,
|
listener: HotbarTooManyItemsHandler,
|
||||||
verifier: (args: unknown[]): args is [] => args.length === 0,
|
verifier: (args: unknown[]): args is [] => args.length === 0,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,13 +3,10 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ipcRenderer } from "electron";
|
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { IpcMainWindowEvents } from "../../common/ipc";
|
import { emitWindowLocationChanged } from "../ipc";
|
||||||
import { navigation } from "../navigation";
|
import { navigation } from "../navigation";
|
||||||
|
|
||||||
export function watchHistoryState() {
|
export function watchHistoryState() {
|
||||||
return reaction(() => navigation.location, (location) => {
|
return reaction(() => navigation.location, emitWindowLocationChanged);
|
||||||
ipcRenderer.send(IpcMainWindowEvents.LOCATION_CHANGED, location);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user