Add better type safety around Channels (#6133)

* Add better type safety around Channels

- Reallow non-JSON serializable complex types

- Remove unnecessary JSON serialization step to IPC

- Remove unnecesary injectable-ization of MessageChannel and
  RequestChannel declarations

- Add channel listener injectable getter function to remove general need
  for type casting and improve type safety

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add check to verify data in IPC related tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix implementation in light of new safety check in tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix listener ID clash potential

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Switch to not forcing split of request channel handlers being seperate from the listener decl

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move message channels to changed signature too

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix not registering listener

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test imports

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Refactor listening of different channel kinds

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add test covering new checking code for request channel handlers

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-10-13 07:50:19 -04:00
1 parent d96918c966
commit 5a5eda935b
115 files changed
+949 -1568

No files matched your search

+2 -10
View File
@@ -5,14 +5,11 @@
import { ipcRenderer } from "electron";
import { reaction } from "mobx";
import { broadcastMessage, ipcRendererOn } from "../../common/ipc";
import {
getLegacyGlobalDiForExtensionApi,
} from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import { broadcastMessage } from "../../common/ipc";
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import matchedClusterIdInjectable from "./matched-cluster-id.injectable";
export const enum IpcRendererNavigationEvents {
RELOAD_PAGE = "renderer:page-reload",
CLUSTER_VIEW_CURRENT_ID = "renderer:cluster-id-of-active-view",
NAVIGATE_IN_APP = "renderer:navigate",
NAVIGATE_IN_CLUSTER = "renderer:navigate-in-cluster",
@@ -27,11 +24,6 @@ export function bindEvents() {
if (process.isMainFrame) {
bindClusterManagerRouteEvents();
}
// Reload dashboard window
ipcRendererOn(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
location.reload();
});
}
// Handle events only in main window renderer process (see also: cluster-manager.tsx)
@@ -2,12 +2,14 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { InjectionToken } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import currentlyInClusterFrameInjectable from "../routes/currently-in-cluster-frame.injectable";
import appNavigationChannelInjectable from "../../common/front-end-routing/app-navigation-channel.injectable";
import clusterFrameNavigationChannelInjectable from "../../common/front-end-routing/cluster-frame-navigation-channel.injectable";
import { appNavigationChannel } from "../../common/front-end-routing/app-navigation-channel";
import { clusterFrameNavigationChannel } from "../../common/front-end-routing/cluster-frame-navigation-channel";
import focusWindowInjectable from "./focus-window.injectable";
import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token";
import type { MessageChannel, MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
import { messageChannelListenerInjectionToken } from "../../common/utils/channel/message-channel-listener-injection-token";
const navigationChannelListenerInjectable = getInjectable({
@@ -15,8 +17,6 @@ const navigationChannelListenerInjectable = getInjectable({
instantiate: (di) => {
const currentlyInClusterFrame = di.inject(currentlyInClusterFrameInjectable);
const appNavigationChannel = di.inject(appNavigationChannelInjectable);
const clusterFrameNavigationChannel = di.inject(clusterFrameNavigationChannelInjectable);
const focusWindow = di.inject(focusWindowInjectable);
const navigateToUrl = di.inject(navigateToUrlInjectionToken);
@@ -34,7 +34,7 @@ const navigationChannelListenerInjectable = getInjectable({
},
};
},
injectionToken: messageChannelListenerInjectionToken,
injectionToken: messageChannelListenerInjectionToken as InjectionToken<MessageChannelListener<MessageChannel<string>>, void>,
});
export default navigationChannelListenerInjectable;