diff --git a/src/common/cluster-store/cluster-store.ts b/src/common/cluster-store/cluster-store.ts index 343d793d59..aebdb79045 100644 --- a/src/common/cluster-store/cluster-store.ts +++ b/src/common/cluster-store/cluster-store.ts @@ -15,7 +15,7 @@ import { ipcMainHandle } from "../ipc"; import { disposer, toJS } from "../utils"; import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types"; import { requestInitialClusterStates } from "../../renderer/ipc"; -import { clusterStates } from "../cluster-ipc"; +import { clusterStates } from "../ipc/cluster"; export interface ClusterStoreModel { clusters?: ClusterModel[]; diff --git a/src/common/cluster/cluster.ts b/src/common/cluster/cluster.ts index 911c2dd8fa..6adf91151f 100644 --- a/src/common/cluster/cluster.ts +++ b/src/common/cluster/cluster.ts @@ -5,7 +5,7 @@ import { ipcMain } from "electron"; 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 { AuthorizationV1Api, CoreV1Api, HttpError, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node"; 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 { disposer, toJS } from "../utils"; import type { Response } from "request"; +import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster"; interface Dependencies { directoryForKubeConfigs: string, @@ -641,7 +642,7 @@ export class Cluster implements ClusterModel, ClusterState { const { response } = error as HttpError & { response: Response }; logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body }); - broadcastMessage(ClusterListNamespaceForbiddenChannel, this.id); + broadcastMessage(clusterListNamespaceForbiddenChannel, this.id); } return namespaceList; diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index 9375ba7231..3b4593111e 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -10,8 +10,9 @@ import { toJS } from "./utils"; import { CatalogEntity } from "./catalog"; import { catalogEntity } from "../main/catalog-sources/general"; import logger from "../main/logger"; -import { broadcastMessage, HotbarTooManyItems } from "./ipc"; +import { broadcastMessage } from "./ipc"; import { defaultHotbarCells, getEmptyHotbar, Hotbar, CreateHotbarData, CreateHotbarOptions } from "./hotbar-types"; +import { hotbarTooManyItemsChannel } from "./ipc/hotbar"; export interface HotbarStoreModel { hotbars: Hotbar[]; @@ -182,7 +183,7 @@ export class HotbarStore extends BaseStore { if (emptyCellIndex != -1) { hotbar.items[emptyCellIndex] = newItem; } else { - broadcastMessage(HotbarTooManyItems); + broadcastMessage(hotbarTooManyItemsChannel); } } else if (0 <= cellIndex && cellIndex < hotbar.items.length) { hotbar.items[cellIndex] = newItem; diff --git a/src/common/ipc/catalog.ts b/src/common/ipc/catalog.ts index 6bc4492083..3d316d211c 100644 --- a/src/common/ipc/catalog.ts +++ b/src/common/ipc/catalog.ts @@ -3,14 +3,17 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -export enum CatalogIpcEvents { - /** - * This is broadcast on whenever there is an update to any catalog item - */ - ITEMS = "catalog:items", +/** + * This is used to activate a specific entity in the renderer main frame + */ +export const catalogEntityRunListener = "catalog-entity:run"; - /** - * This can be sent from renderer to main to initialize a broadcast of ITEMS - */ - INIT = "catalog:init", -} +/** + * This is broadcast on whenever there is an update to any catalog item + */ +export const catalogItemsChannel = "catalog:items"; + +/** + * This can be sent from renderer to main to initialize a broadcast of ITEMS + */ +export const catalogInitChannel = "catalog:init"; diff --git a/src/common/ipc/cluster.ipc.ts b/src/common/ipc/cluster.ipc.ts deleted file mode 100644 index 5e44735b23..0000000000 --- a/src/common/ipc/cluster.ipc.ts +++ /dev/null @@ -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"; -} diff --git a/src/common/cluster-ipc.ts b/src/common/ipc/cluster.ts similarity index 64% rename from src/common/cluster-ipc.ts rename to src/common/ipc/cluster.ts index 6ed8182cba..9f69ff42d5 100644 --- a/src/common/cluster-ipc.ts +++ b/src/common/ipc/cluster.ts @@ -14,3 +14,15 @@ export const clusterClearDeletingHandler = "cluster:deleting:clear"; export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all"; export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all"; 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"; +} diff --git a/src/common/ipc/hotbar.ts b/src/common/ipc/hotbar.ts index e245e5dfb8..3617ebd6c5 100644 --- a/src/common/ipc/hotbar.ts +++ b/src/common/ipc/hotbar.ts @@ -3,4 +3,4 @@ * 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"; diff --git a/src/common/ipc/index.ts b/src/common/ipc/index.ts index 2d41d1cf31..60ae46438e 100644 --- a/src/common/ipc/index.ts +++ b/src/common/ipc/index.ts @@ -3,13 +3,7 @@ * 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 "./invalid-kubeconfig"; -export * from "./update-available.ipc"; -export * from "./cluster.ipc"; +export * from "./update-available"; export * from "./type-enforced-ipc"; -export * from "./hotbar"; -export * from "./window"; diff --git a/src/common/ipc/update-available.ipc.ts b/src/common/ipc/update-available.ts similarity index 100% rename from src/common/ipc/update-available.ipc.ts rename to src/common/ipc/update-available.ts diff --git a/src/common/ipc/window-actions.ts b/src/common/ipc/window-actions.ts deleted file mode 100644 index 58523ec08f..0000000000 --- a/src/common/ipc/window-actions.ts +++ /dev/null @@ -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", -} diff --git a/src/common/ipc/window.ts b/src/common/ipc/window.ts index 2846a841f0..23a83177c6 100644 --- a/src/common/ipc/window.ts +++ b/src/common/ipc/window.ts @@ -3,8 +3,37 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -export const enum IpcMainWindowEvents { - OPEN_CONTEXT_MENU = "window:open-context-menu", - WINDOW_ACTION = "window:window-action", - LOCATION_CHANGED = "window:location-changed", +export const windowActionHandleChannel = "window:window-action"; +export const windowOpenAppMenuAsContextMenuChannel = "window:open-app-context-menu"; +export const windowLocationChangedChannel = "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", } diff --git a/src/main/catalog-pusher.ts b/src/main/catalog-pusher.ts index 7a79c9f50c..14cf8cc5e9 100644 --- a/src/main/catalog-pusher.ts +++ b/src/main/catalog-pusher.ts @@ -10,15 +10,15 @@ import "../common/catalog-entities/kubernetes-cluster"; import { disposer, toJS } from "../common/utils"; import { debounce } from "lodash"; import type { CatalogEntity } from "../common/catalog"; -import { CatalogIpcEvents } from "../common/ipc/catalog"; +import { catalogInitChannel, catalogItemsChannel } from "../common/ipc/catalog"; const broadcaster = debounce((items: CatalogEntity[]) => { - broadcastMessage(CatalogIpcEvents.ITEMS, items); + broadcastMessage(catalogItemsChannel, items); }, 1_000, { leading: true, trailing: true }); export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) { return disposer( - ipcMainOn(CatalogIpcEvents.INIT, () => broadcaster(toJS(catalog.items))), + ipcMainOn(catalogInitChannel, () => broadcaster(toJS(catalog.items))), reaction(() => toJS(catalog.items), (items) => { broadcaster(items); }, { diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index b7e17ff762..12924a4b18 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -3,7 +3,7 @@ * 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 { action, makeObservable, observable, observe, reaction, toJS } from "mobx"; import { Cluster } from "../common/cluster/cluster"; diff --git a/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts b/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts index 28402cdccb..c48d807f7f 100644 --- a/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts +++ b/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts @@ -3,13 +3,13 @@ * 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 { 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 { ClusterStore } from "../../../common/cluster-store/cluster-store"; 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 { pushCatalogToRenderer } from "../../catalog-pusher"; import { ClusterManager } from "../../cluster-manager"; @@ -23,6 +23,7 @@ import type { IComputedValue } from "mobx"; import { onLocationChange, handleWindowAction } from "../../ipc/window"; import { openFilePickingDialogChannel } from "../../../common/ipc/dialog"; import { showOpenDialog } from "../../ipc/dialog"; +import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../common/ipc/window"; interface Dependencies { electronMenuItems: IComputedValue, @@ -139,21 +140,15 @@ export const initIpcMainHandlers = ({ electronMenuItems, directoryForLensLocalSt } }); - ipcMainHandle(dialogShowOpenDialogHandler, async (event, dialogOpts: Electron.OpenDialogOptions) => { - await WindowManager.getInstance().ensureMainWindow(); + ipcMainHandle(windowActionHandleChannel, (event, action) => handleWindowAction(action)); - return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts); - }); - - ipcMainHandle(IpcMainWindowEvents.WINDOW_ACTION, (event, action) => handleWindowAction(action)); - - ipcMainOn(IpcMainWindowEvents.LOCATION_CHANGED, () => onLocationChange()); + ipcMainOn(windowLocationChangedChannel, () => onLocationChange()); ipcMainHandle(openFilePickingDialogChannel, (event, opts) => showOpenDialog(opts)); 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 options = { ...BrowserWindow.fromWebContents(event.sender), diff --git a/src/main/ipc/window.ts b/src/main/ipc/window.ts index 5938f8ad02..b111eab243 100644 --- a/src/main/ipc/window.ts +++ b/src/main/ipc/window.ts @@ -5,7 +5,7 @@ import { BrowserWindow, webContents } from "electron"; import { broadcastMessage } from "../../common/ipc"; -import { WindowAction } from "../../common/ipc/window-actions"; +import { WindowAction } from "../../common/ipc/window"; export function handleWindowAction(action: WindowAction) { const window = BrowserWindow.getFocusedWindow(); diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts index 85477245a4..b7c97aa968 100644 --- a/src/renderer/api/catalog-entity-registry.ts +++ b/src/renderer/api/catalog-entity-registry.ts @@ -4,7 +4,7 @@ */ 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 "../../common/catalog-entities"; import type { Cluster } from "../../common/cluster/cluster"; @@ -14,7 +14,7 @@ import { once } from "lodash"; import logger from "../../common/logger"; import { CatalogRunEvent } from "../../common/catalog/catalog-run-event"; import { ipcRenderer } from "electron"; -import { CatalogIpcEvents } from "../../common/ipc/catalog"; +import { catalogInitChannel, catalogItemsChannel, catalogEntityRunListener } from "../../common/ipc/catalog"; import { navigate } from "../navigation"; import { isMainFrame } from "process"; @@ -79,12 +79,12 @@ export class CatalogEntityRegistry { } init() { - ipcRendererOn(CatalogIpcEvents.ITEMS, (event, items: (CatalogEntityData & CatalogEntityKindData)[]) => { + ipcRendererOn(catalogItemsChannel, (event, items: (CatalogEntityData & CatalogEntityKindData)[]) => { this.updateItems(items); }); // 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) { ipcRendererOn(catalogEntityRunListener, (event, id: string) => { diff --git a/src/renderer/components/activate-entity-command/activate-entity-command.tsx b/src/renderer/components/activate-entity-command/activate-entity-command.tsx index 9a7964dee6..939d750da4 100644 --- a/src/renderer/components/activate-entity-command/activate-entity-command.tsx +++ b/src/renderer/components/activate-entity-command/activate-entity-command.tsx @@ -7,7 +7,8 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import { computed, IComputedValue } from "mobx"; import { observer } from "mobx-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 { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import commandOverlayInjectable from "../command-palette/command-overlay.injectable"; diff --git a/src/renderer/components/cluster-manager/lens-views.ts b/src/renderer/components/cluster-manager/lens-views.ts index edd3b6d0c7..22d5cba586 100644 --- a/src/renderer/components/cluster-manager/lens-views.ts +++ b/src/renderer/components/cluster-manager/lens-views.ts @@ -5,7 +5,7 @@ import { action, IReactionDisposer, makeObservable, observable, when } from "mobx"; 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 type { ClusterId } from "../../../common/cluster-types"; import { getClusterFrameUrl, Singleton } from "../../utils"; diff --git a/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx b/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx index 8834213165..8368ae750d 100644 --- a/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx +++ b/src/renderer/components/layout/top-bar/top-bar-win-linux.test.tsx @@ -7,13 +7,14 @@ import React from "react"; import { fireEvent } from "@testing-library/react"; import "@testing-library/jest-dom/extend-expect"; import { TopBar } from "./top-bar"; -import { IpcMainWindowEvents, broadcastMessage } from "../../../../common/ipc"; +import { broadcastMessage } from "../../../../common/ipc"; import * as vars from "../../../../common/vars"; import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; import { DiRender, renderFor } from "../../test-utils/renderFor"; import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; import mockFs from "mock-fs"; import { requestWindowAction } from "../../../ipc"; +import { windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window"; const mockConfig = vars as { isWindows: boolean; isLinux: boolean }; @@ -87,7 +88,7 @@ describe(" in Windows and Linux", () => { const close = getByTestId("window-close"); fireEvent.click(menu); - expect(broadcastMessage).toHaveBeenCalledWith(IpcMainWindowEvents.OPEN_CONTEXT_MENU); + expect(broadcastMessage).toHaveBeenCalledWith(windowOpenAppMenuAsContextMenuChannel); fireEvent.click(minimize); expect(requestWindowAction).toHaveBeenCalledWith("minimize"); diff --git a/src/renderer/components/layout/top-bar/top-bar.test.tsx b/src/renderer/components/layout/top-bar/top-bar.test.tsx index c68c295636..e5d491401c 100644 --- a/src/renderer/components/layout/top-bar/top-bar.test.tsx +++ b/src/renderer/components/layout/top-bar/top-bar.test.tsx @@ -14,7 +14,6 @@ import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable"; import { computed } from "mobx"; import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; import mockFs from "mock-fs"; -import { IpcMainWindowEvents } from "../../../../common/ipc"; jest.mock("../../../../common/vars", () => { const SemVer = require("semver").SemVer; @@ -49,7 +48,7 @@ jest.mock( (channel: string, action: string) => { console.log("channel", channel, action); - if (channel !== IpcMainWindowEvents.WINDOW_ACTION) return; + if (channel !== "window:window-action") return; switch(action) { case "back": { diff --git a/src/renderer/components/layout/top-bar/top-bar.tsx b/src/renderer/components/layout/top-bar/top-bar.tsx index 21d99ad645..28c953baad 100644 --- a/src/renderer/components/layout/top-bar/top-bar.tsx +++ b/src/renderer/components/layout/top-bar/top-bar.tsx @@ -9,7 +9,7 @@ import { observer } from "mobx-react"; import type { IComputedValue } from "mobx"; import { Icon } from "../../icon"; import { observable } from "mobx"; -import { broadcastMessage, IpcMainWindowEvents, ipcRendererOn } from "../../../../common/ipc"; +import { ipcRendererOn } from "../../../../common/ipc"; import { watchHistoryState } from "../../../remote-helpers/history-updater"; import { isActiveRoute, navigate } from "../../../navigation"; 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 { withInjectables } from "@ogre-tools/injectable-react"; import type { TopBarRegistration } from "./top-bar-registration"; -import { requestWindowAction } from "../../../ipc"; -import { WindowAction } from "../../../../common/ipc/window-actions"; +import { emitOpenAppMenuAsContextMenu, requestWindowAction } from "../../../ipc"; +import { WindowAction } from "../../../../common/ipc/window"; interface Props extends React.HTMLAttributes {} @@ -42,7 +42,7 @@ const NonInjectedTopBar = (({ items, children, ...rest }: Props & Dependencies) const elem = useRef(); const openContextMenu = () => { - broadcastMessage(IpcMainWindowEvents.OPEN_CONTEXT_MENU); + emitOpenAppMenuAsContextMenu(); }; const goHome = () => { diff --git a/src/renderer/ipc/index.ts b/src/renderer/ipc/index.ts index 48e1ef6e7a..7a14f1e014 100644 --- a/src/renderer/ipc/index.ts +++ b/src/renderer/ipc/index.ts @@ -4,22 +4,34 @@ */ 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 { IpcMainWindowEvents } from "../../common/ipc"; +import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window"; import { openFilePickingDialogChannel } from "../../common/ipc/dialog"; 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 { LensExtensionId } from "../../extensions/lens-extension"; import { toJS } from "../utils"; +import type { Location } from "history"; function requestMain(channel: string, ...args: any[]) { 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 { - return requestMain(IpcMainWindowEvents.WINDOW_ACTION, type); + return requestMain(windowActionHandleChannel, type); } export function requestOpenFilePickingDialog(opts: OpenDialogOptions): Promise<{ canceled: boolean; filePaths: string[]; }> { diff --git a/src/renderer/ipc/register-listeners.tsx b/src/renderer/ipc/register-listeners.tsx index 3a4272c96f..99429a4596 100644 --- a/src/renderer/ipc/register-listeners.tsx +++ b/src/renderer/ipc/register-listeners.tsx @@ -5,7 +5,7 @@ import React from "react"; 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 { Button } from "../components/button"; import { isMac } from "../../common/vars"; @@ -13,6 +13,8 @@ import { ClusterStore } from "../../common/cluster-store/cluster-store"; import { navigate } from "../navigation"; import { entitySettingsURL } from "../../common/routes"; 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 { notificationsStore.remove(notificationId); @@ -127,13 +129,13 @@ export function registerIpcListeners() { }); onCorrect({ source: ipcRenderer, - channel: ClusterListNamespaceForbiddenChannel, + channel: clusterListNamespaceForbiddenChannel, listener: ListNamespacesForbiddenHandler, verifier: isListNamespaceForbiddenArgs, }); onCorrect({ source: ipcRenderer, - channel: HotbarTooManyItems, + channel: hotbarTooManyItemsChannel, listener: HotbarTooManyItemsHandler, verifier: (args: unknown[]): args is [] => args.length === 0, }); diff --git a/src/renderer/remote-helpers/history-updater.ts b/src/renderer/remote-helpers/history-updater.ts index 3380a4aeac..2927843776 100644 --- a/src/renderer/remote-helpers/history-updater.ts +++ b/src/renderer/remote-helpers/history-updater.ts @@ -3,13 +3,10 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { ipcRenderer } from "electron"; import { reaction } from "mobx"; -import { IpcMainWindowEvents } from "../../common/ipc"; +import { emitWindowLocationChanged } from "../ipc"; import { navigation } from "../navigation"; export function watchHistoryState() { - return reaction(() => navigation.location, (location) => { - ipcRenderer.send(IpcMainWindowEvents.LOCATION_CHANGED, location); - }); + return reaction(() => navigation.location, emitWindowLocationChanged); }