diff --git a/packages/core/package.json b/packages/core/package.json index 6c629b55d9..f5bacfcda5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -328,6 +328,9 @@ "@k8slens/application": "^6.5.0-alpha.0", "@k8slens/application-for-electron-main": "^6.5.0-alpha.0", "@k8slens/legacy-extensions": "^1.0.0-alpha.0", + "@k8slens/messaging": "^1.0.0-alpha.1", + "@k8slens/messaging-for-main": "^1.0.0-alpha.1", + "@k8slens/messaging-for-renderer": "^1.0.0-alpha.1", "@k8slens/run-many": "^1.0.0-alpha.1", "@k8slens/startable-stoppable": "^1.0.0-alpha.1", "@k8slens/test-utils": "^1.0.0-alpha.1", diff --git a/packages/core/src/common/app-paths/app-paths-channel.ts b/packages/core/src/common/app-paths/app-paths-channel.ts index 4502569d3b..aac1d9a8c3 100644 --- a/packages/core/src/common/app-paths/app-paths-channel.ts +++ b/packages/core/src/common/app-paths/app-paths-channel.ts @@ -3,11 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { AppPaths } from "./app-path-injection-token"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import { getRequestChannel } from "@k8slens/messaging"; -export type AppPathsChannel = RequestChannel; - -export const appPathsChannel: AppPathsChannel = { - id: "app-paths", -}; +export const appPathsChannel = getRequestChannel('app-paths') diff --git a/packages/core/src/common/base-store/base-store.ts b/packages/core/src/common/base-store/base-store.ts index be7abf1293..a1dd26f0f7 100644 --- a/packages/core/src/common/base-store/base-store.ts +++ b/packages/core/src/common/base-store/base-store.ts @@ -15,7 +15,7 @@ import type { GetConfigurationFileModel } from "../get-configuration-file-model/ import type { Logger } from "../logger"; import type { PersistStateToConfig } from "./save-to-file"; import type { GetBasenameOfPath } from "../path/get-basename.injectable"; -import type { EnlistMessageChannelListener } from "../utils/channel/enlist-message-channel-listener-injection-token"; +import type { EnlistMessageChannelListener } from "@k8slens/messaging"; import { toJS } from "../utils"; export interface BaseStoreParams extends Omit, "migrations"> { @@ -108,6 +108,7 @@ export abstract class BaseStore { this.params.syncOptions, ), this.dependencies.enlistMessageChannelListener({ + id: this.displayName, channel: { id: `${this.dependencies.ipcChannelPrefixes.local}:${config.path}`, }, diff --git a/packages/core/src/common/certificate/lens-proxy-certificate-channel.ts b/packages/core/src/common/certificate/lens-proxy-certificate-channel.ts index 7d9652ce5c..9dd339ee65 100644 --- a/packages/core/src/common/certificate/lens-proxy-certificate-channel.ts +++ b/packages/core/src/common/certificate/lens-proxy-certificate-channel.ts @@ -4,6 +4,6 @@ */ import type { SelfSignedCert } from "selfsigned"; -import { getRequestChannel } from "../utils/channel/get-request-channel"; +import { getRequestChannel } from "@k8slens/messaging"; export const lensProxyCertificateChannel = getRequestChannel("request-lens-proxy-certificate"); diff --git a/packages/core/src/common/cluster-store/cluster-store.injectable.ts b/packages/core/src/common/cluster-store/cluster-store.injectable.ts index ddd811c760..79eb02e36c 100644 --- a/packages/core/src/common/cluster-store/cluster-store.injectable.ts +++ b/packages/core/src/common/cluster-store/cluster-store.injectable.ts @@ -16,7 +16,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync"; import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; import getBasenameOfPathInjectable from "../path/get-basename.injectable"; -import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; const clusterStoreInjectable = getInjectable({ id: "cluster-store", diff --git a/packages/core/src/common/cluster/current-cluster-channel.ts b/packages/core/src/common/cluster/current-cluster-channel.ts index 957baa6f9c..c16af7832b 100644 --- a/packages/core/src/common/cluster/current-cluster-channel.ts +++ b/packages/core/src/common/cluster/current-cluster-channel.ts @@ -4,7 +4,7 @@ */ import type { ClusterId } from "../cluster-types"; -import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export const currentClusterMessageChannel: MessageChannel = { id: "current-visible-cluster", diff --git a/packages/core/src/common/cluster/visibility-channel.ts b/packages/core/src/common/cluster/visibility-channel.ts index 8a1a297ff2..554217a409 100644 --- a/packages/core/src/common/cluster/visibility-channel.ts +++ b/packages/core/src/common/cluster/visibility-channel.ts @@ -4,7 +4,7 @@ */ import type { ClusterId } from "../cluster-types"; -import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export const clusterVisibilityChannel: MessageChannel = { id: "cluster-visibility", diff --git a/packages/core/src/common/front-end-routing/app-navigation-channel.ts b/packages/core/src/common/front-end-routing/app-navigation-channel.ts index b3d8f02c66..8670fc4953 100644 --- a/packages/core/src/common/front-end-routing/app-navigation-channel.ts +++ b/packages/core/src/common/front-end-routing/app-navigation-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { IpcRendererNavigationEvents } from "../ipc/navigation-events"; -import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export type AppNavigationChannel = MessageChannel; diff --git a/packages/core/src/common/front-end-routing/cluster-frame-navigation-channel.ts b/packages/core/src/common/front-end-routing/cluster-frame-navigation-channel.ts index 2439f523e2..5f96526da4 100644 --- a/packages/core/src/common/front-end-routing/cluster-frame-navigation-channel.ts +++ b/packages/core/src/common/front-end-routing/cluster-frame-navigation-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { IpcRendererNavigationEvents } from "../ipc/navigation-events"; -import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export type ClusterFrameNavigationChannel = MessageChannel; diff --git a/packages/core/src/common/helm/add-helm-repository-channel.ts b/packages/core/src/common/helm/add-helm-repository-channel.ts index 258367c7ec..1744192059 100644 --- a/packages/core/src/common/helm/add-helm-repository-channel.ts +++ b/packages/core/src/common/helm/add-helm-repository-channel.ts @@ -3,11 +3,10 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { HelmRepo } from "./helm-repo"; -import type { AsyncResult } from "@k8slens/utilities"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { Result } from "@k8slens/utilities"; +import { getRequestChannel } from "@k8slens/messaging"; -export type AddHelmRepositoryChannel = RequestChannel>; - -export const addHelmRepositoryChannel: AddHelmRepositoryChannel = { - id: "add-helm-repository-channel", -}; +export const addHelmRepositoryChannel = getRequestChannel< + HelmRepo, + Result +>("add-helm-repository-channel"); diff --git a/packages/core/src/common/helm/get-active-helm-repositories-channel.ts b/packages/core/src/common/helm/get-active-helm-repositories-channel.ts index 2ea5a80030..ba4e0ae956 100644 --- a/packages/core/src/common/helm/get-active-helm-repositories-channel.ts +++ b/packages/core/src/common/helm/get-active-helm-repositories-channel.ts @@ -4,10 +4,9 @@ */ import type { HelmRepo } from "./helm-repo"; import type { AsyncResult } from "@k8slens/utilities"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import { getRequestChannel } from "@k8slens/messaging"; -export type GetActiveHelmRepositoriesChannel = RequestChannel>; - -export const getActiveHelmRepositoriesChannel: GetActiveHelmRepositoriesChannel = { - id: "get-helm-active-list-repositories", -}; +export const getActiveHelmRepositoriesChannel = getRequestChannel< + void, + AsyncResult +>("get-helm-active-list-repositories"); diff --git a/packages/core/src/common/helm/remove-helm-repository-channel.ts b/packages/core/src/common/helm/remove-helm-repository-channel.ts index f1189cb580..09c7630f34 100644 --- a/packages/core/src/common/helm/remove-helm-repository-channel.ts +++ b/packages/core/src/common/helm/remove-helm-repository-channel.ts @@ -3,11 +3,10 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { AsyncResult } from "@k8slens/utilities"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import { getRequestChannel } from "@k8slens/messaging"; import type { HelmRepo } from "./helm-repo"; -export type RemoveHelmRepositoryChannel = RequestChannel>; - -export const removeHelmRepositoryChannel: RemoveHelmRepositoryChannel = { - id: "remove-helm-repository-channel", -}; +export const removeHelmRepositoryChannel = getRequestChannel< + HelmRepo, + AsyncResult +>("remove-helm-repository-channel"); diff --git a/packages/core/src/common/hotbars/store.injectable.ts b/packages/core/src/common/hotbars/store.injectable.ts index cc15f93bf8..ea25840e11 100644 --- a/packages/core/src/common/hotbars/store.injectable.ts +++ b/packages/core/src/common/hotbars/store.injectable.ts @@ -14,7 +14,7 @@ import { hotbarStoreMigrationInjectionToken } from "./migrations-token"; import getBasenameOfPathInjectable from "../path/get-basename.injectable"; import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel-prefix"; import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; -import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync"; const hotbarStoreInjectable = getInjectable({ diff --git a/packages/core/src/common/kube-helpers/channels.ts b/packages/core/src/common/kube-helpers/channels.ts index b48f9f1f99..cc265e02ab 100644 --- a/packages/core/src/common/kube-helpers/channels.ts +++ b/packages/core/src/common/kube-helpers/channels.ts @@ -4,11 +4,9 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; -import type { Asyncify } from "type-fest"; -import type { RequestChannelHandler } from "../../main/utils/channel/channel-listeners/listener-tokens"; import type { ClusterId } from "../cluster-types"; -import type { AsyncResult } from "@k8slens/utilities"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { AsyncResult, Result } from "@k8slens/utilities"; +import { getRequestChannel } from "@k8slens/messaging"; export interface KubectlApplyAllArgs { clusterId: ClusterId; @@ -16,11 +14,12 @@ export interface KubectlApplyAllArgs { extraArgs: string[]; } -export const kubectlApplyAllChannel: RequestChannel> = { - id: "kubectl-apply-all", -}; +export const kubectlApplyAllChannel = getRequestChannel< + KubectlApplyAllArgs, + Result +>("kubectl-apply-all"); -export type KubectlApplyAll = Asyncify>; +export type KubectlApplyAll = (req: KubectlApplyAllArgs) => AsyncResult export const kubectlApplyAllInjectionToken = getInjectionToken({ id: "kubectl-apply-all", @@ -32,11 +31,12 @@ export interface KubectlDeleteAllArgs { extraArgs: string[]; } -export const kubectlDeleteAllChannel: RequestChannel> = { - id: "kubectl-delete-all", -}; +export const kubectlDeleteAllChannel = getRequestChannel< + KubectlDeleteAllArgs, + Result +>("kubectl-delete-all"); -export type KubectlDeleteAll = Asyncify>; +export type KubectlDeleteAll = (req: KubectlDeleteAllArgs) => AsyncResult; export const kubectlDeleteAllInjectionToken = getInjectionToken({ id: "kubectl-delete-all", diff --git a/packages/core/src/common/root-frame/root-frame-rendered-channel.ts b/packages/core/src/common/root-frame/root-frame-rendered-channel.ts index 060ae8735c..c4dc0cefa6 100644 --- a/packages/core/src/common/root-frame/root-frame-rendered-channel.ts +++ b/packages/core/src/common/root-frame/root-frame-rendered-channel.ts @@ -2,7 +2,7 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export type RootFrameHasRenderedChannel = MessageChannel; diff --git a/packages/core/src/common/user-store/user-store.injectable.ts b/packages/core/src/common/user-store/user-store.injectable.ts index 3b45b03b1d..10806007a2 100644 --- a/packages/core/src/common/user-store/user-store.injectable.ts +++ b/packages/core/src/common/user-store/user-store.injectable.ts @@ -16,7 +16,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync"; import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; import getBasenameOfPathInjectable from "../path/get-basename.injectable"; -import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; import userStorePreferenceDescriptorsInjectable from "./preference-descriptors.injectable"; const userStoreInjectable = getInjectable({ diff --git a/packages/core/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts b/packages/core/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts index c823a8a8f9..91706825fd 100644 --- a/packages/core/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts +++ b/packages/core/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts @@ -2,10 +2,8 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { RequestChannel } from "../channel/request-channel-listener-injection-token"; +import { getRequestChannel } from "@k8slens/messaging"; -export type ResolveSystemProxyChannel = RequestChannel; - -export const resolveSystemProxyChannel: ResolveSystemProxyChannel = { - id: "resolve-system-proxy-channel", -}; +export const resolveSystemProxyChannel = getRequestChannel( + "resolve-system-proxy-channel" +); diff --git a/packages/core/src/common/utils/sync-box/channel-listener.injectable.ts b/packages/core/src/common/utils/sync-box/channel-listener.injectable.ts index a97d95d726..482886d178 100644 --- a/packages/core/src/common/utils/sync-box/channel-listener.injectable.ts +++ b/packages/core/src/common/utils/sync-box/channel-listener.injectable.ts @@ -3,13 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { syncBoxChannel } from "./channels"; -import { getMessageChannelListenerInjectable } from "../channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import syncBoxStateInjectable from "./sync-box-state.injectable"; const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({ id: "init", channel: syncBoxChannel, - handler: (di) => ({ id, value }) => di.inject(syncBoxStateInjectable, id).set(value), + getHandler: (di) => ({ id, value }) => di.inject(syncBoxStateInjectable, id).set(value), }); export default syncBoxChannelListenerInjectable; diff --git a/packages/core/src/common/utils/sync-box/channels.ts b/packages/core/src/common/utils/sync-box/channels.ts index 4df0462dc3..5178ff013c 100644 --- a/packages/core/src/common/utils/sync-box/channels.ts +++ b/packages/core/src/common/utils/sync-box/channels.ts @@ -2,20 +2,12 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../channel/message-channel-listener-injection-token"; -import type { RequestChannel } from "../channel/request-channel-listener-injection-token"; +import { getMessageChannel, getRequestChannel } from "@k8slens/messaging"; -export type SyncBoxChannel = MessageChannel<{ id: string; value: any }>; +export const syncBoxChannel = + getMessageChannel<{ id: string; value: any }>("sync-box-channel"); -export const syncBoxChannel: SyncBoxChannel = { - id: "sync-box-channel", -}; - -export type SyncBoxInitialValueChannel = RequestChannel< +export const syncBoxInitialValueChannel = getRequestChannel< void, { id: string; value: any }[] ->; - -export const syncBoxInitialValueChannel: SyncBoxInitialValueChannel = { - id: "sync-box-initial-value-channel", -}; +>("sync-box-initial-value-channel"); diff --git a/packages/core/src/common/utils/sync-box/create-sync-box.injectable.ts b/packages/core/src/common/utils/sync-box/create-sync-box.injectable.ts index 4a01fe71a0..2a142dc573 100644 --- a/packages/core/src/common/utils/sync-box/create-sync-box.injectable.ts +++ b/packages/core/src/common/utils/sync-box/create-sync-box.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import type { IObservableValue } from "mobx"; import { computed } from "mobx"; import { syncBoxChannel } from "./channels"; -import { sendMessageToChannelInjectionToken } from "../channel/message-to-channel-injection-token"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import syncBoxStateInjectable from "./sync-box-state.injectable"; import type { SyncBox } from "./sync-box-injection-token"; import { toJS } from "../toJS"; diff --git a/packages/core/src/common/utils/sync-box/handler.injectable.ts b/packages/core/src/common/utils/sync-box/handler.injectable.ts deleted file mode 100644 index f520585474..0000000000 --- a/packages/core/src/common/utils/sync-box/handler.injectable.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { getInjectable } from "@ogre-tools/injectable"; -import type { MessageChannelHandler } from "../channel/message-channel-listener-injection-token"; -import type { SyncBoxChannel } from "./channels"; -import syncBoxStateInjectable from "./sync-box-state.injectable"; - -const syncBoxChannelHandlerInjectable = getInjectable({ - id: "sync-box-channel-handler", - instantiate: (di): MessageChannelHandler => { - const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id); - - return ({ id, value }) => getSyncBoxState(id)?.set(value); - }, -}); - -export default syncBoxChannelHandlerInjectable; diff --git a/packages/core/src/common/vars/build-semantic-version.injectable.ts b/packages/core/src/common/vars/build-semantic-version.injectable.ts index 2a49327480..402fb9d442 100644 --- a/packages/core/src/common/vars/build-semantic-version.injectable.ts +++ b/packages/core/src/common/vars/build-semantic-version.injectable.ts @@ -7,7 +7,7 @@ import { getInjectionToken } from "@ogre-tools/injectable"; import { SemVer } from "semver"; import type { InitializableState } from "../initializable-state/create"; import { createInitializableState } from "../initializable-state/create"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "@k8slens/messaging"; export const buildVersionInjectionToken = getInjectionToken>({ id: "build-version-token", diff --git a/packages/core/src/common/weblinks-store/weblink-store.injectable.ts b/packages/core/src/common/weblinks-store/weblink-store.injectable.ts index cf793a2e58..843c8716e5 100644 --- a/packages/core/src/common/weblinks-store/weblink-store.injectable.ts +++ b/packages/core/src/common/weblinks-store/weblink-store.injectable.ts @@ -11,7 +11,7 @@ import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable"; import loggerInjectable from "../logger.injectable"; import getBasenameOfPathInjectable from "../path/get-basename.injectable"; -import { enlistMessageChannelListenerInjectionToken } from "../utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable"; import { weblinkStoreMigrationInjectionToken } from "./migration-token"; import { WeblinkStore } from "./weblink-store"; diff --git a/packages/core/src/extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable.ts b/packages/core/src/extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable.ts index 847ae37f03..2295608520 100644 --- a/packages/core/src/extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable.ts +++ b/packages/core/src/extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable.ts @@ -12,7 +12,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../../../common/base- import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../../common/base-store/disable-sync"; import { persistStateToConfigInjectionToken } from "../../../common/base-store/save-to-file"; import getBasenameOfPathInjectable from "../../../common/path/get-basename.injectable"; -import { enlistMessageChannelListenerInjectionToken } from "../../../common/utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; import ensureHashedDirectoryForExtensionInjectable from "./ensure-hashed-directory-for-extension.injectable"; import { registeredExtensionsInjectable } from "./registered-extensions.injectable"; diff --git a/packages/core/src/extensions/extension-store.ts b/packages/core/src/extensions/extension-store.ts index cf435fb474..fe9cff2a02 100644 --- a/packages/core/src/extensions/extension-store.ts +++ b/packages/core/src/extensions/extension-store.ts @@ -20,7 +20,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../common/base-store/ import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../common/base-store/disable-sync"; import { persistStateToConfigInjectionToken } from "../common/base-store/save-to-file"; import getBasenameOfPathInjectable from "../common/path/get-basename.injectable"; -import { enlistMessageChannelListenerInjectionToken } from "../common/utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; export interface ExtensionStoreParams extends BaseStoreParams { migrations?: Migrations; diff --git a/packages/core/src/extensions/extensions-store/extensions-store.injectable.ts b/packages/core/src/extensions/extensions-store/extensions-store.injectable.ts index 9f5ff83270..9e08a96aac 100644 --- a/packages/core/src/extensions/extensions-store/extensions-store.injectable.ts +++ b/packages/core/src/extensions/extensions-store/extensions-store.injectable.ts @@ -10,7 +10,7 @@ import { persistStateToConfigInjectionToken } from "../../common/base-store/save import getConfigurationFileModelInjectable from "../../common/get-configuration-file-model/get-configuration-file-model.injectable"; import loggerInjectable from "../../common/logger.injectable"; import getBasenameOfPathInjectable from "../../common/path/get-basename.injectable"; -import { enlistMessageChannelListenerInjectionToken } from "../../common/utils/channel/enlist-message-channel-listener-injection-token"; +import { enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging"; import storeMigrationVersionInjectable from "../../common/vars/store-migration-version.injectable"; import { ExtensionsStore } from "./extensions-store"; diff --git a/packages/core/src/features/application-update/common/restart-and-install-update-channel.ts b/packages/core/src/features/application-update/common/restart-and-install-update-channel.ts index 470debf981..87b8f76cf3 100644 --- a/packages/core/src/features/application-update/common/restart-and-install-update-channel.ts +++ b/packages/core/src/features/application-update/common/restart-and-install-update-channel.ts @@ -2,7 +2,7 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export type RestartAndInstallUpdateChannel = MessageChannel; diff --git a/packages/core/src/features/application-update/main/restart-and-install-update/restart-and-install-update-listener.injectable.ts b/packages/core/src/features/application-update/main/restart-and-install-update/restart-and-install-update-listener.injectable.ts index 940856ad3b..768ad50ffd 100644 --- a/packages/core/src/features/application-update/main/restart-and-install-update/restart-and-install-update-listener.injectable.ts +++ b/packages/core/src/features/application-update/main/restart-and-install-update/restart-and-install-update-listener.injectable.ts @@ -3,13 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { restartAndInstallUpdateChannel } from "../../common/restart-and-install-update-channel"; -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable"; const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({ id: "restart", channel: restartAndInstallUpdateChannel, - handler: (di) => di.inject(quitAndInstallUpdateInjectable), + getHandler: (di) => di.inject(quitAndInstallUpdateInjectable), }); export default restartAndInstallUpdateListenerInjectable; diff --git a/packages/core/src/features/application-update/renderer/restart-and-install-update.injectable.ts b/packages/core/src/features/application-update/renderer/restart-and-install-update.injectable.ts index 2502a599a2..d60f8da909 100644 --- a/packages/core/src/features/application-update/renderer/restart-and-install-update.injectable.ts +++ b/packages/core/src/features/application-update/renderer/restart-and-install-update.injectable.ts @@ -4,13 +4,13 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { restartAndInstallUpdateChannel } from "../common/restart-and-install-update-channel"; -import messageToChannelInjectable from "../../../renderer/utils/channel/message-to-channel.injectable"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; const restartAndInstallUpdateInjectable = getInjectable({ id: "restart-and-install-update", instantiate: (di) => { - const messageToChannel = di.inject(messageToChannelInjectable); + const messageToChannel = di.inject(sendMessageToChannelInjectionToken); return () => { messageToChannel(restartAndInstallUpdateChannel); diff --git a/packages/core/src/features/certificate-authorities/common/channel.ts b/packages/core/src/features/certificate-authorities/common/channel.ts index 5fb58ee1ca..c81ba9be44 100644 --- a/packages/core/src/features/certificate-authorities/common/channel.ts +++ b/packages/core/src/features/certificate-authorities/common/channel.ts @@ -2,7 +2,6 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ - -import { getRequestChannel } from "../../../common/utils/channel/get-request-channel"; +import { getRequestChannel } from "@k8slens/messaging"; export const casChannel = getRequestChannel("certificate-authorities"); diff --git a/packages/core/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts b/packages/core/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts index 62882fb49f..2a19d9706d 100644 --- a/packages/core/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts +++ b/packages/core/src/features/certificate-authorities/main/channel-handler.global-override-for-injectable.ts @@ -8,6 +8,7 @@ import { casChannel } from "../common/channel"; import certificateAuthoritiesChannelListenerInjectable from "./channel-handler.injectable"; export default getGlobalOverride(certificateAuthoritiesChannelListenerInjectable, () => ({ + id: 'certificate-authorities-channel-listener', channel: casChannel, handler: () => [], })); diff --git a/packages/core/src/features/certificate-authorities/main/channel-handler.injectable.ts b/packages/core/src/features/certificate-authorities/main/channel-handler.injectable.ts index 206a68ba94..ef518b7761 100644 --- a/packages/core/src/features/certificate-authorities/main/channel-handler.injectable.ts +++ b/packages/core/src/features/certificate-authorities/main/channel-handler.injectable.ts @@ -2,14 +2,15 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getRequestChannelListenerInjectable } from "../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { casChannel } from "../common/channel"; import { globalAgent } from "https"; import { isString } from "@k8slens/utilities"; const certificateAuthoritiesChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'certificate-authorities-channel-listener', channel: casChannel, - handler: () => () => { + getHandler: () => () => { if (Array.isArray(globalAgent.options.ca)) { return globalAgent.options.ca.filter(isString); } diff --git a/packages/core/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts b/packages/core/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts index e3c840a95a..e9ac074989 100644 --- a/packages/core/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts +++ b/packages/core/src/features/certificate-authorities/renderer/request-system-cas.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { casChannel } from "../common/channel"; import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token"; diff --git a/packages/core/src/features/cluster/activation/common/channels.ts b/packages/core/src/features/cluster/activation/common/channels.ts index 3631c4d9b8..55172e75fc 100644 --- a/packages/core/src/features/cluster/activation/common/channels.ts +++ b/packages/core/src/features/cluster/activation/common/channels.ts @@ -4,7 +4,7 @@ */ import type { ClusterId } from "../../../../common/cluster-types"; -import { getRequestChannel } from "../../../../common/utils/channel/get-request-channel"; +import { getRequestChannel } from "@k8slens/messaging"; export interface ActivateCluster { clusterId: ClusterId; diff --git a/packages/core/src/features/cluster/activation/common/request-token.ts b/packages/core/src/features/cluster/activation/common/request-token.ts index 5bee44208f..0abe5775b3 100644 --- a/packages/core/src/features/cluster/activation/common/request-token.ts +++ b/packages/core/src/features/cluster/activation/common/request-token.ts @@ -4,7 +4,7 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; -import type { ChannelRequester } from "../../../../common/utils/channel/request-from-channel-injection-token"; +import type { ChannelRequester } from "@k8slens/messaging"; import type { activateClusterChannel, deactivateClusterChannel } from "./channels"; export type RequestClusterActivation = ChannelRequester; diff --git a/packages/core/src/features/cluster/activation/main/activate-listener.injectable.ts b/packages/core/src/features/cluster/activation/main/activate-listener.injectable.ts index 4ce22e6311..5f6bfdf110 100644 --- a/packages/core/src/features/cluster/activation/main/activate-listener.injectable.ts +++ b/packages/core/src/features/cluster/activation/main/activate-listener.injectable.ts @@ -2,13 +2,14 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { activateClusterChannel } from "../common/channels"; import requestClusterActivationInjectable from "./request-activation.injectable"; const activateClusterRequestChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'activate-cluster-request-channel-listener', channel: activateClusterChannel, - handler: (di) => di.inject(requestClusterActivationInjectable), + getHandler: (di) => di.inject(requestClusterActivationInjectable), }); export default activateClusterRequestChannelListenerInjectable; diff --git a/packages/core/src/features/cluster/activation/main/deactivate-listener.injectable.ts b/packages/core/src/features/cluster/activation/main/deactivate-listener.injectable.ts index e24ce48ba6..7d84d37242 100644 --- a/packages/core/src/features/cluster/activation/main/deactivate-listener.injectable.ts +++ b/packages/core/src/features/cluster/activation/main/deactivate-listener.injectable.ts @@ -2,13 +2,14 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { deactivateClusterChannel } from "../common/channels"; import requestClusterDeactivationInjectable from "./request-deactivation.injectable"; const clusterDeactivationRequestChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'cluster-deactivation-request-channel-listener', channel: deactivateClusterChannel, - handler: (di) => di.inject(requestClusterDeactivationInjectable), + getHandler: (di) => di.inject(requestClusterDeactivationInjectable), }); export default clusterDeactivationRequestChannelListenerInjectable; diff --git a/packages/core/src/features/cluster/activation/renderer/request-activation.injectable.ts b/packages/core/src/features/cluster/activation/renderer/request-activation.injectable.ts index 1677d67792..6609516918 100644 --- a/packages/core/src/features/cluster/activation/renderer/request-activation.injectable.ts +++ b/packages/core/src/features/cluster/activation/renderer/request-activation.injectable.ts @@ -3,14 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { activateClusterChannel } from "../common/channels"; import { requestClusterActivationInjectionToken } from "../common/request-token"; const requestClusterActivationInjectable = getInjectable({ id: "request-cluster-activation", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return (req) => requestFromChannel(activateClusterChannel, req); }, diff --git a/packages/core/src/features/cluster/activation/renderer/request-deactivation.injectable.ts b/packages/core/src/features/cluster/activation/renderer/request-deactivation.injectable.ts index 362784e91b..e019b8b615 100644 --- a/packages/core/src/features/cluster/activation/renderer/request-deactivation.injectable.ts +++ b/packages/core/src/features/cluster/activation/renderer/request-deactivation.injectable.ts @@ -3,14 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { deactivateClusterChannel } from "../common/channels"; import { requestClusterDeactivationInjectionToken } from "../common/request-token"; const requestClusterDeactivationInjectable = getInjectable({ id: "request-cluster-deactivation", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return (clusterId) => requestFromChannel(deactivateClusterChannel, clusterId); }, diff --git a/packages/core/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts b/packages/core/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts index bf33a23165..e8293c62b4 100644 --- a/packages/core/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts +++ b/packages/core/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts @@ -3,10 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterId } from "../../../../common/cluster-types"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import { getRequestChannel } from "@k8slens/messaging"; -export type ClearClusterAsDeletingChannel = RequestChannel; - -export const clearClusterAsDeletingChannel: ClearClusterAsDeletingChannel = { - id: "clear-cluster-as-deleting", -}; +export const clearClusterAsDeletingChannel = getRequestChannel( + "clear-cluster-as-deleting" +); diff --git a/packages/core/src/features/cluster/delete-dialog/common/delete-channel.ts b/packages/core/src/features/cluster/delete-dialog/common/delete-channel.ts index 0e9142fcd3..f151b86794 100644 --- a/packages/core/src/features/cluster/delete-dialog/common/delete-channel.ts +++ b/packages/core/src/features/cluster/delete-dialog/common/delete-channel.ts @@ -3,10 +3,10 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterId } from "../../../../common/cluster-types"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import { getRequestChannel, RequestChannel } from "@k8slens/messaging"; export type DeleteClusterChannel = RequestChannel; -export const deleteClusterChannel: DeleteClusterChannel = { - id: "delete-cluster", -}; +export const deleteClusterChannel = getRequestChannel( + "delete-cluster" +); diff --git a/packages/core/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts b/packages/core/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts index 57ef2e3a8d..e41ef3a3f6 100644 --- a/packages/core/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts +++ b/packages/core/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts @@ -3,10 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterId } from "../../../../common/cluster-types"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import { getRequestChannel } from "@k8slens/messaging"; -export type SetClusterAsDeletingChannel = RequestChannel; - -export const setClusterAsDeletingChannel: SetClusterAsDeletingChannel = { - id: "set-cluster-as-deleting", -}; +export const setClusterAsDeletingChannel = getRequestChannel( + "set-cluster-as-deleting" +); diff --git a/packages/core/src/features/cluster/delete-dialog/main/clear-as-deleting-channel-listener.injectable.ts b/packages/core/src/features/cluster/delete-dialog/main/clear-as-deleting-channel-listener.injectable.ts index a8dd2a80b0..99a26a5bc0 100644 --- a/packages/core/src/features/cluster/delete-dialog/main/clear-as-deleting-channel-listener.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/main/clear-as-deleting-channel-listener.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable"; -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel"; const clearClusterAsDeletingChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'clear-cluster-as-deleting-channel-listener', channel: clearClusterAsDeletingChannel, - handler: (di) => { + getHandler: (di) => { const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable); return (clusterId) => { diff --git a/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts b/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts index 94caf169ba..e30586db2d 100644 --- a/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts @@ -10,12 +10,13 @@ import removePathInjectable from "../../../../common/fs/remove.injectable"; import joinPathsInjectable from "../../../../common/path/join-paths.injectable"; import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable"; import { noop } from "@k8slens/utilities"; -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { deleteClusterChannel } from "../common/delete-channel"; const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'delete-cluster-channel-listener', channel: deleteClusterChannel, - handler: (di) => { + getHandler: (di) => { const emitAppEvent = di.inject(emitAppEventInjectable); const clusterStore = di.inject(clusterStoreInjectable); const clusterFrames = di.inject(clusterFramesInjectable); diff --git a/packages/core/src/features/cluster/delete-dialog/main/set-as-deleteing-channel-listener.injectable.ts b/packages/core/src/features/cluster/delete-dialog/main/set-as-deleteing-channel-listener.injectable.ts index f532b4a81f..3db564f0d5 100644 --- a/packages/core/src/features/cluster/delete-dialog/main/set-as-deleteing-channel-listener.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/main/set-as-deleteing-channel-listener.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable"; -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel"; const setClusterAsDeletingChannelHandlerInjectable = getRequestChannelListenerInjectable({ + id: 'set-cluster-as-deleting-channel-handler', channel: setClusterAsDeletingChannel, - handler: (di) => { + getHandler: (di) => { const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable); return (clusterId) => { diff --git a/packages/core/src/features/cluster/delete-dialog/renderer/request-clear-as-deleting.injectable.ts b/packages/core/src/features/cluster/delete-dialog/renderer/request-clear-as-deleting.injectable.ts index e476998ca0..1e3125a52a 100644 --- a/packages/core/src/features/cluster/delete-dialog/renderer/request-clear-as-deleting.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/renderer/request-clear-as-deleting.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { ClusterId } from "../../../../common/cluster-types"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel"; export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise; @@ -12,7 +12,7 @@ export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise { - const requestChannel = di.inject(requestFromChannelInjectable); + const requestChannel = di.inject(requestFromChannelInjectionToken); return (clusterId) => requestChannel(clearClusterAsDeletingChannel, clusterId); }, diff --git a/packages/core/src/features/cluster/delete-dialog/renderer/request-delete.injectable.ts b/packages/core/src/features/cluster/delete-dialog/renderer/request-delete.injectable.ts index c1286e3103..9e415e79d0 100644 --- a/packages/core/src/features/cluster/delete-dialog/renderer/request-delete.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/renderer/request-delete.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { ClusterId } from "../../../../common/cluster-types"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { deleteClusterChannel } from "../common/delete-channel"; export type RequestDeleteCluster = (clusterId: ClusterId) => Promise; @@ -12,7 +12,7 @@ export type RequestDeleteCluster = (clusterId: ClusterId) => Promise; const requestDeleteClusterInjectable = getInjectable({ id: "request-delete-cluster", instantiate: (di): RequestDeleteCluster => { - const requestChannel = di.inject(requestFromChannelInjectable); + const requestChannel = di.inject(requestFromChannelInjectionToken); return (clusterId) => requestChannel(deleteClusterChannel, clusterId); }, diff --git a/packages/core/src/features/cluster/delete-dialog/renderer/request-set-as-deleting.injectable.ts b/packages/core/src/features/cluster/delete-dialog/renderer/request-set-as-deleting.injectable.ts index de3a6393b3..0e86632f89 100644 --- a/packages/core/src/features/cluster/delete-dialog/renderer/request-set-as-deleting.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/renderer/request-set-as-deleting.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { ClusterId } from "../../../../common/cluster-types"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel"; export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise; @@ -12,7 +12,7 @@ export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise { - const requestChannel = di.inject(requestFromChannelInjectable); + const requestChannel = di.inject(requestFromChannelInjectionToken); return (clusterId) => requestChannel(setClusterAsDeletingChannel, clusterId); }, diff --git a/packages/core/src/features/cluster/state-sync/common/channels.ts b/packages/core/src/features/cluster/state-sync/common/channels.ts index 7ceeb82f84..fe125e3941 100644 --- a/packages/core/src/features/cluster/state-sync/common/channels.ts +++ b/packages/core/src/features/cluster/state-sync/common/channels.ts @@ -4,8 +4,8 @@ */ import type { ClusterId, ClusterState } from "../../../../common/cluster-types"; -import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; +import type { RequestChannel } from "@k8slens/messaging"; export interface ClusterStateSync { clusterId: ClusterId; diff --git a/packages/core/src/features/cluster/state-sync/main/emit-update.injectable.ts b/packages/core/src/features/cluster/state-sync/main/emit-update.injectable.ts index 8cadd32864..4191ef88f0 100644 --- a/packages/core/src/features/cluster/state-sync/main/emit-update.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/main/emit-update.injectable.ts @@ -3,18 +3,15 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token"; -import { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token"; -import { clusterStateSyncChannel } from "../common/channels"; - -export type EmitClusterStateUpdate = MessageChannelHandler; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; +import { ClusterStateSync, clusterStateSyncChannel } from "../common/channels"; const emitClusterStateUpdateInjectable = getInjectable({ id: "emit-cluster-state-update", - instantiate: (di): EmitClusterStateUpdate => { + instantiate: (di) => { const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); - return (message) => sendMessageToChannel(clusterStateSyncChannel, message); + return (message: ClusterStateSync) => sendMessageToChannel(clusterStateSyncChannel, message); }, }); diff --git a/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts b/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts index 708f032d48..76d3a86d54 100644 --- a/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { initialClusterStatesChannel } from "../common/channels"; const handleInitialClusterStateSyncInjectable = getRequestChannelListenerInjectable({ + id: 'handle-initial-cluster-state-sync', channel: initialClusterStatesChannel, - handler: (di) => { + getHandler: (di) => { const clusterStore = di.inject(clusterStoreInjectable); return () => clusterStore.clustersList.map(cluster => ({ diff --git a/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts b/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts index 9863a391e8..a3778d096e 100644 --- a/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts @@ -3,13 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import { clusterStateSyncChannel } from "../common/channels"; const clusterStateListenerInjectable = getMessageChannelListenerInjectable({ channel: clusterStateSyncChannel, id: "main", - handler: (di) => { + getHandler: (di) => { const getClusterById = di.inject(getClusterByIdInjectable); return ({ clusterId, state }) => getClusterById(clusterId)?.setState(state); diff --git a/packages/core/src/features/cluster/state-sync/renderer/request-initial.injectable.ts b/packages/core/src/features/cluster/state-sync/renderer/request-initial.injectable.ts index 89f72fbcf5..497d2c5aaf 100644 --- a/packages/core/src/features/cluster/state-sync/renderer/request-initial.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/renderer/request-initial.injectable.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { RequestChannelHandler } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import type { RequestChannelHandler } from "@k8slens/messaging"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { initialClusterStatesChannel } from "../common/channels"; export type RequestInitialClusterStates = RequestChannelHandler; @@ -12,7 +12,7 @@ export type RequestInitialClusterStates = RequestChannelHandler { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return () => requestFromChannel(initialClusterStatesChannel); }, diff --git a/packages/core/src/features/extensions/navigate/common/channel.ts b/packages/core/src/features/extensions/navigate/common/channel.ts index 4c6892e6cb..ec7bc967dc 100644 --- a/packages/core/src/features/extensions/navigate/common/channel.ts +++ b/packages/core/src/features/extensions/navigate/common/channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export interface NavigateForExtensionArgs { extId: string; diff --git a/packages/core/src/features/extensions/navigate/renderer/listener.injectable.ts b/packages/core/src/features/extensions/navigate/renderer/listener.injectable.ts index fccf0efca6..763b8238b2 100644 --- a/packages/core/src/features/extensions/navigate/renderer/listener.injectable.ts +++ b/packages/core/src/features/extensions/navigate/renderer/listener.injectable.ts @@ -2,7 +2,7 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import extensionLoaderInjectable from "../../../../extensions/extension-loader/extension-loader.injectable"; import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension"; import { navigateForExtensionChannel } from "../common/channel"; @@ -10,7 +10,7 @@ import { navigateForExtensionChannel } from "../common/channel"; const navigateForExtensionListenerInjectable = getMessageChannelListenerInjectable({ channel: navigateForExtensionChannel, id: "main", - handler: (di) => { + getHandler: (di) => { const extensionLoader = di.inject(extensionLoaderInjectable); return ({ extId, pageId, params }) => { diff --git a/packages/core/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts b/packages/core/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts index 7a0d5e6b47..b4195a876f 100644 --- a/packages/core/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts +++ b/packages/core/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { asyncComputed } from "@ogre-tools/injectable-react"; import { getActiveHelmRepositoriesChannel } from "../../../../../common/helm/get-active-helm-repositories-channel"; -import { requestFromChannelInjectionToken } from "../../../../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import showErrorNotificationInjectable from "../../../../../renderer/components/notifications/show-error-notification.injectable"; import helmRepositoriesErrorStateInjectable from "./helm-repositories-error-state.injectable"; import { runInAction } from "mobx"; diff --git a/packages/core/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts b/packages/core/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts index 6b39d8dddf..3c2199c490 100644 --- a/packages/core/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts +++ b/packages/core/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { HelmRepo } from "../../../../../../../common/helm/helm-repo"; -import { requestFromChannelInjectionToken } from "../../../../../../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import activeHelmRepositoriesInjectable from "../../active-helm-repositories.injectable"; import showErrorNotificationInjectable from "../../../../../../../renderer/components/notifications/show-error-notification.injectable"; import showSuccessNotificationInjectable from "../../../../../../../renderer/components/notifications/show-success-notification.injectable"; diff --git a/packages/core/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts b/packages/core/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts index 3aa56a4b04..4af5543c28 100644 --- a/packages/core/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts +++ b/packages/core/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { HelmRepo } from "../../../../../common/helm/helm-repo"; -import { requestFromChannelInjectionToken } from "../../../../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import activeHelmRepositoriesInjectable from "./active-helm-repositories.injectable"; import { removeHelmRepositoryChannel } from "../../../../../common/helm/remove-helm-repository-channel"; diff --git a/packages/core/src/features/navigation/reload-page/common/channel.ts b/packages/core/src/features/navigation/reload-page/common/channel.ts index b920067a4d..50cdaa8918 100644 --- a/packages/core/src/features/navigation/reload-page/common/channel.ts +++ b/packages/core/src/features/navigation/reload-page/common/channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export type ReloadPageChannel = MessageChannel; diff --git a/packages/core/src/features/navigation/reload-page/renderer/register-listener.global-override-for-injectable.ts b/packages/core/src/features/navigation/reload-page/renderer/register-listener.global-override-for-injectable.ts index 9953ddcbf9..fd8640408a 100644 --- a/packages/core/src/features/navigation/reload-page/renderer/register-listener.global-override-for-injectable.ts +++ b/packages/core/src/features/navigation/reload-page/renderer/register-listener.global-override-for-injectable.ts @@ -8,6 +8,7 @@ import { reloadPageChannel } from "../common/channel"; import reloadPageChannelListenerInjectable from "./register-listener.injectable"; export default getGlobalOverride(reloadPageChannelListenerInjectable, () => ({ + id: 'reload-page-channel-listener', channel: reloadPageChannel, handler: () => {}, })); diff --git a/packages/core/src/features/navigation/reload-page/renderer/register-listener.injectable.ts b/packages/core/src/features/navigation/reload-page/renderer/register-listener.injectable.ts index a42d818729..f71096bebf 100644 --- a/packages/core/src/features/navigation/reload-page/renderer/register-listener.injectable.ts +++ b/packages/core/src/features/navigation/reload-page/renderer/register-listener.injectable.ts @@ -2,13 +2,13 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import { reloadPageChannel } from "../common/channel"; const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({ id: "handler", channel: reloadPageChannel, - handler: () => () => location.reload(), + getHandler: () => () => location.reload(), causesSideEffects: true, }); diff --git a/packages/core/src/features/path-picking-dialog/common/channel.ts b/packages/core/src/features/path-picking-dialog/common/channel.ts index 98c19b4ad6..c5e8b9386d 100644 --- a/packages/core/src/features/path-picking-dialog/common/channel.ts +++ b/packages/core/src/features/path-picking-dialog/common/channel.ts @@ -4,7 +4,7 @@ */ import type { OpenDialogOptions } from "electron"; -import type { RequestChannel } from "../../../common/utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "@k8slens/messaging"; export type PathPickingResponse = { canceled: true; diff --git a/packages/core/src/features/path-picking-dialog/main/handle-pick-paths.injectable.ts b/packages/core/src/features/path-picking-dialog/main/handle-pick-paths.injectable.ts index d566ac9728..a914bb2c03 100644 --- a/packages/core/src/features/path-picking-dialog/main/handle-pick-paths.injectable.ts +++ b/packages/core/src/features/path-picking-dialog/main/handle-pick-paths.injectable.ts @@ -4,12 +4,13 @@ */ import askUserForFilePathsInjectable from "../../../main/ipc/ask-user-for-file-paths.injectable"; -import { getRequestChannelListenerInjectable } from "../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { openPathPickingDialogChannel } from "../common/channel"; const openPathPickingDialogListener = getRequestChannelListenerInjectable({ + id: 'open-path-picking-dialog', channel: openPathPickingDialogChannel, - handler: (di) => di.inject(askUserForFilePathsInjectable), + getHandler: (di) => di.inject(askUserForFilePathsInjectable), }); export default openPathPickingDialogListener; diff --git a/packages/core/src/features/path-picking-dialog/renderer/pick-paths.injectable.ts b/packages/core/src/features/path-picking-dialog/renderer/pick-paths.injectable.ts index 5dde31f46d..528bffc634 100644 --- a/packages/core/src/features/path-picking-dialog/renderer/pick-paths.injectable.ts +++ b/packages/core/src/features/path-picking-dialog/renderer/pick-paths.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { PathPickOpts } from "../../../renderer/components/path-picker"; -import requestFromChannelInjectable from "../../../renderer/utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { openPathPickingDialogChannel } from "../common/channel"; export type OpenPathPickingDialog = (options: PathPickOpts) => Promise; @@ -12,7 +12,7 @@ export type OpenPathPickingDialog = (options: PathPickOpts) => Promise; const openPathPickingDialogInjectable = getInjectable({ id: "open-path-picking-dialog", instantiate: (di): OpenPathPickingDialog => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return async (options) => { const { onPick, onCancel, ...dialogOptions } = options; diff --git a/packages/core/src/features/shell-sync/common/failure-channel.ts b/packages/core/src/features/shell-sync/common/failure-channel.ts index aed25b0da0..268640fe89 100644 --- a/packages/core/src/features/shell-sync/common/failure-channel.ts +++ b/packages/core/src/features/shell-sync/common/failure-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; export const shellSyncFailedChannel: MessageChannel = { id: "shell-sync-failed-channel", diff --git a/packages/core/src/features/shell-sync/main/emit-failure.injectable.ts b/packages/core/src/features/shell-sync/main/emit-failure.injectable.ts index 5abdfafa52..7dbfb094f2 100644 --- a/packages/core/src/features/shell-sync/main/emit-failure.injectable.ts +++ b/packages/core/src/features/shell-sync/main/emit-failure.injectable.ts @@ -3,16 +3,15 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { MessageChannelSender } from "../../../common/utils/channel/message-to-channel-injection-token"; -import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import { shellSyncFailedChannel } from "../common/failure-channel"; const emitShellSyncFailedInjectable = getInjectable({ id: "emit-shell-sync-failed", - instantiate: (di): MessageChannelSender => { + instantiate: (di) => { const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); - return (error) => sendMessageToChannel(shellSyncFailedChannel, error); + return (error: string) => sendMessageToChannel(shellSyncFailedChannel, error); }, }); diff --git a/packages/core/src/features/shell-sync/renderer/failure-listener.injectable.ts b/packages/core/src/features/shell-sync/renderer/failure-listener.injectable.ts index 2014397fad..135143b3a6 100644 --- a/packages/core/src/features/shell-sync/renderer/failure-listener.injectable.ts +++ b/packages/core/src/features/shell-sync/renderer/failure-listener.injectable.ts @@ -2,14 +2,14 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getMessageChannelListenerInjectable } from "../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import showErrorNotificationInjectable from "../../../renderer/components/notifications/show-error-notification.injectable"; import { shellSyncFailedChannel } from "../common/failure-channel"; const shellSyncFailureListenerInjectable = getMessageChannelListenerInjectable({ id: "notification", channel: shellSyncFailedChannel, - handler: (di) => { + getHandler: (di) => { const showErrorNotification = di.inject(showErrorNotificationInjectable); return (errorMessage) => showErrorNotification(`Failed to sync shell environment: ${errorMessage}`); diff --git a/packages/core/src/features/theme/system-type/common/channels.ts b/packages/core/src/features/theme/system-type/common/channels.ts index 3134f20378..032fa77222 100644 --- a/packages/core/src/features/theme/system-type/common/channels.ts +++ b/packages/core/src/features/theme/system-type/common/channels.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; +import type { RequestChannel } from "@k8slens/messaging"; export type SystemThemeType = "dark" | "light"; diff --git a/packages/core/src/features/theme/system-type/main/emit-update.injectable.ts b/packages/core/src/features/theme/system-type/main/emit-update.injectable.ts index c085e6615a..c2c5a05d06 100644 --- a/packages/core/src/features/theme/system-type/main/emit-update.injectable.ts +++ b/packages/core/src/features/theme/system-type/main/emit-update.injectable.ts @@ -3,18 +3,15 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token"; -import { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token"; -import { systemThemeTypeUpdateChannel } from "../common/channels"; - -export type EmitSystemThemeTypeUpdate = MessageChannelHandler; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; +import { SystemThemeType, systemThemeTypeUpdateChannel } from "../common/channels"; const emitSystemThemeTypeUpdateInjectable = getInjectable({ id: "emit-system-theme-type-update", - instantiate: (di): EmitSystemThemeTypeUpdate => { + instantiate: (di) => { const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); - return (type) => sendMessageToChannel(systemThemeTypeUpdateChannel, type); + return (type: SystemThemeType) => sendMessageToChannel(systemThemeTypeUpdateChannel, type); }, }); diff --git a/packages/core/src/features/theme/system-type/main/handle-initial.injectable.ts b/packages/core/src/features/theme/system-type/main/handle-initial.injectable.ts index 1468b1eeda..5ffb6dbf8b 100644 --- a/packages/core/src/features/theme/system-type/main/handle-initial.injectable.ts +++ b/packages/core/src/features/theme/system-type/main/handle-initial.injectable.ts @@ -4,12 +4,13 @@ */ import operatingSystemThemeInjectable from "../../../../main/theme/operating-system-theme.injectable"; -import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { initialSystemThemeTypeChannel } from "../common/channels"; const initialSystemThemeTypeHandler = getRequestChannelListenerInjectable({ + id: 'initial-system-theme-type-listener', channel: initialSystemThemeTypeChannel, - handler: (di) => { + getHandler: (di) => { const operatingSystemTheme = di.inject(operatingSystemThemeInjectable); return () => operatingSystemTheme.get(); diff --git a/packages/core/src/features/theme/system-type/renderer/request-initial.injectable.ts b/packages/core/src/features/theme/system-type/renderer/request-initial.injectable.ts index 74fe73cf03..fd84d7f90c 100644 --- a/packages/core/src/features/theme/system-type/renderer/request-initial.injectable.ts +++ b/packages/core/src/features/theme/system-type/renderer/request-initial.injectable.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { RequestChannelHandler } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; -import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; +import type { RequestChannelHandler } from "@k8slens/messaging"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { initialSystemThemeTypeChannel } from "../common/channels"; export type RequestInitialSystemThemeType = RequestChannelHandler; @@ -12,7 +12,7 @@ export type RequestInitialSystemThemeType = RequestChannelHandler { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return () => requestFromChannel(initialSystemThemeTypeChannel); }, diff --git a/packages/core/src/features/theme/system-type/renderer/update-listener.injectable.ts b/packages/core/src/features/theme/system-type/renderer/update-listener.injectable.ts index 4eb57c9b85..dac9061c28 100644 --- a/packages/core/src/features/theme/system-type/renderer/update-listener.injectable.ts +++ b/packages/core/src/features/theme/system-type/renderer/update-listener.injectable.ts @@ -2,14 +2,14 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import systemThemeConfigurationInjectable from "../../../../renderer/themes/system-theme.injectable"; import { systemThemeTypeUpdateChannel } from "../common/channels"; const systemThemeTypeUpdateListenerInjectable = getMessageChannelListenerInjectable({ channel: systemThemeTypeUpdateChannel, id: "main", - handler: (di) => { + getHandler: (di) => { const systemThemeConfiguration = di.inject(systemThemeConfigurationInjectable); return (type) => systemThemeConfiguration.set(type); diff --git a/packages/core/src/main/app-paths/app-paths-request-channel-listener.injectable.ts b/packages/core/src/main/app-paths/app-paths-request-channel-listener.injectable.ts index 568d63f1ea..b9ee17234d 100644 --- a/packages/core/src/main/app-paths/app-paths-request-channel-listener.injectable.ts +++ b/packages/core/src/main/app-paths/app-paths-request-channel-listener.injectable.ts @@ -4,11 +4,12 @@ */ import { appPathsChannel } from "../../common/app-paths/app-paths-channel"; import appPathsInjectable from "../../common/app-paths/app-paths.injectable"; -import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; const appPathsRequestChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'app-paths-request-channel-listener', channel: appPathsChannel, - handler: (di) => { + getHandler: (di) => { const appPaths = di.inject(appPathsInjectable); return () => appPaths; diff --git a/packages/core/src/main/build-version/setup-channel.injectable.ts b/packages/core/src/main/build-version/setup-channel.injectable.ts index 05da92db6e..dd51366690 100644 --- a/packages/core/src/main/build-version/setup-channel.injectable.ts +++ b/packages/core/src/main/build-version/setup-channel.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { buildVersionChannel } from "../../common/vars/build-semantic-version.injectable"; -import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import buildVersionInjectable from "../vars/build-version/build-version.injectable"; const buildVersionChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'build-version-channel-listener', channel: buildVersionChannel, - handler: (di) => { + getHandler: (di) => { const buildVersion = di.inject(buildVersionInjectable); return () => buildVersion.get(); diff --git a/packages/core/src/main/cluster/visibility-handler.injectable.ts b/packages/core/src/main/cluster/visibility-handler.injectable.ts index 31f6ff13ec..ef4277e905 100644 --- a/packages/core/src/main/cluster/visibility-handler.injectable.ts +++ b/packages/core/src/main/cluster/visibility-handler.injectable.ts @@ -3,13 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { clusterVisibilityChannel } from "../../common/cluster/visibility-channel"; -import { getMessageChannelListenerInjectable } from "../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import visibleClusterInjectable from "./visible-cluster.injectable"; const clusterVisibilityHandlerInjectable = getMessageChannelListenerInjectable({ channel: clusterVisibilityChannel, id: "base", - handler: (di) => { + getHandler: (di) => { const visibleCluster = di.inject(visibleClusterInjectable); return (clusterId) => visibleCluster.set(clusterId); diff --git a/packages/core/src/main/getDiForUnitTesting.ts b/packages/core/src/main/getDiForUnitTesting.ts index b71ab53239..41061240b4 100644 --- a/packages/core/src/main/getDiForUnitTesting.ts +++ b/packages/core/src/main/getDiForUnitTesting.ts @@ -30,6 +30,8 @@ import { setLegacyGlobalDiForExtensionApi, } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; +import { registerFeature } from "@k8slens/feature-core"; +import { messagingFeature, testUtils as messagingTestUtils } from "@k8slens/messaging"; export function getDiForUnitTesting() { const di = createContainer("main"); @@ -37,6 +39,11 @@ export function getDiForUnitTesting() { registerMobX(di); setLegacyGlobalDiForExtensionApi(di, "main"); + runInAction(() => { + registerFeature(di, messagingFeature, messagingTestUtils.messagingFeatureForUnitTesting); + + }); + di.preventSideEffects(); runInAction(() => { diff --git a/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository-channel-listener.injectable.ts b/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository-channel-listener.injectable.ts index 1c68bf6fd7..d5343b1d4f 100644 --- a/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository-channel-listener.injectable.ts +++ b/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository-channel-listener.injectable.ts @@ -3,12 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { addHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel"; -import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import addHelmRepositoryInjectable from "./add-helm-repository.injectable"; -const addHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({ - channel: addHelmRepositoryChannel, - handler: (di) => di.inject(addHelmRepositoryInjectable), -}); +const addHelmRepositoryChannelListenerInjectable = + getRequestChannelListenerInjectable({ + id: "add-helm-repository-channel-listener", + channel: addHelmRepositoryChannel, + getHandler: (di) => di.inject(addHelmRepositoryInjectable), + }); export default addHelmRepositoryChannelListenerInjectable; diff --git a/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository.injectable.ts b/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository.injectable.ts index 5292f8a662..27272a76f3 100644 --- a/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository.injectable.ts +++ b/packages/core/src/main/helm/repositories/add-helm-repository/add-helm-repository.injectable.ts @@ -5,17 +5,16 @@ import { getInjectable } from "@ogre-tools/injectable"; import execHelmInjectable from "../../exec-helm/exec-helm.injectable"; import loggerInjectable from "../../../../common/logger.injectable"; -import type { AddHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel"; -import type { RequestChannelHandler } from "../../../utils/channel/channel-listeners/listener-tokens"; +import type { HelmRepo } from "../../../../common/helm/helm-repo"; const addHelmRepositoryInjectable = getInjectable({ id: "add-helm-repository", - instantiate: (di): RequestChannelHandler => { + instantiate: (di) => { const execHelm = di.inject(execHelmInjectable); const logger = di.inject(loggerInjectable); - return async (repo) => { + return async (repo: HelmRepo) => { const { name, url, @@ -59,12 +58,12 @@ const addHelmRepositoryInjectable = getInjectable({ if (result.callWasSuccessful) { return { - callWasSuccessful: true, + callWasSuccessful: true as const, }; } return { - callWasSuccessful: false, + callWasSuccessful: false as const, error: result.error.stderr || result.error.message, }; }; diff --git a/packages/core/src/main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories-channel-listener.injectable.ts b/packages/core/src/main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories-channel-listener.injectable.ts index 5ef0f2b5a4..e92548ea54 100644 --- a/packages/core/src/main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories-channel-listener.injectable.ts +++ b/packages/core/src/main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories-channel-listener.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getActiveHelmRepositoriesChannel } from "../../../../common/helm/get-active-helm-repositories-channel"; -import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import getActiveHelmRepositoriesInjectable from "./get-active-helm-repositories.injectable"; const getActiveHelmRepositoriesChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'get-active-helm-repositories-channel-listener', channel: getActiveHelmRepositoriesChannel, - handler: (di) => di.inject(getActiveHelmRepositoriesInjectable), + getHandler: (di) => di.inject(getActiveHelmRepositoriesInjectable), }); export default getActiveHelmRepositoriesChannelListenerInjectable; diff --git a/packages/core/src/main/helm/repositories/remove-helm-repository/remove-helm-repository-channel-listener.injectable.ts b/packages/core/src/main/helm/repositories/remove-helm-repository/remove-helm-repository-channel-listener.injectable.ts index 8a4e04b87c..fc0a524715 100644 --- a/packages/core/src/main/helm/repositories/remove-helm-repository/remove-helm-repository-channel-listener.injectable.ts +++ b/packages/core/src/main/helm/repositories/remove-helm-repository/remove-helm-repository-channel-listener.injectable.ts @@ -4,11 +4,12 @@ */ import removeHelmRepositoryInjectable from "./remove-helm-repository.injectable"; import { removeHelmRepositoryChannel } from "../../../../common/helm/remove-helm-repository-channel"; -import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; const removeHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'remove-helm-repository-channel-listener', channel: removeHelmRepositoryChannel, - handler: (di) => di.inject(removeHelmRepositoryInjectable), + getHandler: (di) => di.inject(removeHelmRepositoryInjectable), }); export default removeHelmRepositoryChannelListenerInjectable; diff --git a/packages/core/src/main/ipc/ask-user-for-file-paths.injectable.ts b/packages/core/src/main/ipc/ask-user-for-file-paths.injectable.ts index f8a0685d7c..3d0326711e 100644 --- a/packages/core/src/main/ipc/ask-user-for-file-paths.injectable.ts +++ b/packages/core/src/main/ipc/ask-user-for-file-paths.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.injectable"; -import type { RequestChannelHandler } from "../utils/channel/channel-listeners/listener-tokens"; +import type { RequestChannelHandler } from "@k8slens/messaging"; import type { openPathPickingDialogChannel } from "../../features/path-picking-dialog/common/channel"; import showOpenDialogInjectable from "../electron-app/features/show-open-dialog.injectable"; diff --git a/packages/core/src/main/kubectl/apply-all-handler.injectable.ts b/packages/core/src/main/kubectl/apply-all-handler.injectable.ts index 7f62ca14fc..5bc8af82f6 100644 --- a/packages/core/src/main/kubectl/apply-all-handler.injectable.ts +++ b/packages/core/src/main/kubectl/apply-all-handler.injectable.ts @@ -6,11 +6,12 @@ import emitAppEventInjectable from "../../common/app-event-bus/emit-event.inject import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable"; import { kubectlApplyAllChannel } from "../../common/kube-helpers/channels"; import resourceApplierInjectable from "../resource-applier/create-resource-applier.injectable"; -import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; const kubectlApplyAllChannelHandlerInjectable = getRequestChannelListenerInjectable({ + id: 'kubectl-apply-all-channel-handler-listener', channel: kubectlApplyAllChannel, - handler: (di) => { + getHandler: (di) => { const getClusterById = di.inject(getClusterByIdInjectable); const emitAppEvent = di.inject(emitAppEventInjectable); diff --git a/packages/core/src/main/kubectl/delete-all-handler.injectable.ts b/packages/core/src/main/kubectl/delete-all-handler.injectable.ts index 715eb0caf9..a79ca1ee5f 100644 --- a/packages/core/src/main/kubectl/delete-all-handler.injectable.ts +++ b/packages/core/src/main/kubectl/delete-all-handler.injectable.ts @@ -6,11 +6,12 @@ import emitAppEventInjectable from "../../common/app-event-bus/emit-event.inject import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable"; import { kubectlDeleteAllChannel } from "../../common/kube-helpers/channels"; import resourceApplierInjectable from "../resource-applier/create-resource-applier.injectable"; -import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; const kubectlDeleteAllChannelHandlerInjectable = getRequestChannelListenerInjectable({ + id: 'kubectl-delete-all-channel-handler-listener', channel: kubectlDeleteAllChannel, - handler: (di) => { + getHandler: (di) => { const emitAppEvent = di.inject(emitAppEventInjectable); const getClusterById = di.inject(getClusterByIdInjectable); diff --git a/packages/core/src/main/lens-proxy/lens-proxy-certificate-request-handler.injectable.ts b/packages/core/src/main/lens-proxy/lens-proxy-certificate-request-handler.injectable.ts index 5f6938912a..de9bda3d5d 100644 --- a/packages/core/src/main/lens-proxy/lens-proxy-certificate-request-handler.injectable.ts +++ b/packages/core/src/main/lens-proxy/lens-proxy-certificate-request-handler.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { lensProxyCertificateChannel } from "../../common/certificate/lens-proxy-certificate-channel"; -import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import lensProxyCertificateInjectable from "../../common/certificate/lens-proxy-certificate.injectable"; const lensProxyCertificateRequestHandlerInjectable = getRequestChannelListenerInjectable({ + id: 'lens-proxy-certificate-request-handler-listener', channel: lensProxyCertificateChannel, - handler: (di) => { + getHandler: (di) => { const lensProxyCertificate = di.inject(lensProxyCertificateInjectable).get(); return () => ({ diff --git a/packages/core/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts b/packages/core/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts index d29210cda1..11d23e6a4f 100644 --- a/packages/core/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts +++ b/packages/core/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts @@ -3,17 +3,17 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { currentClusterMessageChannel } from "../../../../common/cluster/current-cluster-channel"; -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import currentClusterFrameClusterIdStateInjectable from "./current-cluster-frame-cluster-id-state.injectable"; -const currentVisibileClusterListenerInjectable = getMessageChannelListenerInjectable({ - id: "current-visibile-cluster", +const currentVisibleClusterListenerInjectable = getMessageChannelListenerInjectable({ + id: "current-visible-cluster", channel: currentClusterMessageChannel, - handler: (di) => { + getHandler: (di) => { const currentClusterFrameState = di.inject(currentClusterFrameClusterIdStateInjectable); return clusterId => currentClusterFrameState.set(clusterId); }, }); -export default currentVisibileClusterListenerInjectable; +export default currentVisibleClusterListenerInjectable; diff --git a/packages/core/src/main/start-main-application/runnables/root-frame-has-rendered/channel-listener.injectable.ts b/packages/core/src/main/start-main-application/runnables/root-frame-has-rendered/channel-listener.injectable.ts index 8b906c79e9..4769c12256 100644 --- a/packages/core/src/main/start-main-application/runnables/root-frame-has-rendered/channel-listener.injectable.ts +++ b/packages/core/src/main/start-main-application/runnables/root-frame-has-rendered/channel-listener.injectable.ts @@ -2,7 +2,7 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import { rootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel"; import { runManyFor } from "@k8slens/run-many"; import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phases"; @@ -10,7 +10,7 @@ import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phase const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({ id: "action", channel: rootFrameHasRenderedChannel, - handler: (di) => { + getHandler: (di) => { const runMany = runManyFor(di); return runMany(afterRootFrameIsReadyInjectionToken); diff --git a/packages/core/src/main/utils/resolve-system-proxy/resolve-system-proxy-channel-responder.injectable.ts b/packages/core/src/main/utils/resolve-system-proxy/resolve-system-proxy-channel-responder.injectable.ts index a2cd605633..b21de6d91f 100644 --- a/packages/core/src/main/utils/resolve-system-proxy/resolve-system-proxy-channel-responder.injectable.ts +++ b/packages/core/src/main/utils/resolve-system-proxy/resolve-system-proxy-channel-responder.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { resolveSystemProxyChannel } from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-channel"; -import { getRequestChannelListenerInjectable } from "../channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import resolveSystemProxyInjectable from "./resolve-system-proxy.injectable"; const resolveSystemProxyChannelResponderInjectable = getRequestChannelListenerInjectable({ + id: 'resolve-system-proxy-channel-responder-listener', channel: resolveSystemProxyChannel, - handler: (di) => di.inject(resolveSystemProxyInjectable), + getHandler: (di) => di.inject(resolveSystemProxyInjectable), }); export default resolveSystemProxyChannelResponderInjectable; diff --git a/packages/core/src/main/utils/sync-box/sync-box-initial-value-channel-listener.injectable.ts b/packages/core/src/main/utils/sync-box/sync-box-initial-value-channel-listener.injectable.ts index da78d76c36..0faef38367 100644 --- a/packages/core/src/main/utils/sync-box/sync-box-initial-value-channel-listener.injectable.ts +++ b/packages/core/src/main/utils/sync-box/sync-box-initial-value-channel-listener.injectable.ts @@ -4,11 +4,12 @@ */ import { syncBoxInitialValueChannel } from "../../../common/utils/sync-box/channels"; import { syncBoxInjectionToken } from "../../../common/utils/sync-box/sync-box-injection-token"; -import { getRequestChannelListenerInjectable } from "../channel/channel-listeners/listener-tokens"; +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; const syncBoxInitialValueChannelListenerInjectable = getRequestChannelListenerInjectable({ + id: 'sync-box-initial-value-channel-listener', channel: syncBoxInitialValueChannel, - handler: (di) => { + getHandler: (di) => { const syncBoxes = di.injectMany(syncBoxInjectionToken); return () => syncBoxes.map((box) => ({ diff --git a/packages/core/src/renderer/app-paths/setup-app-paths.injectable.ts b/packages/core/src/renderer/app-paths/setup-app-paths.injectable.ts index d80cc668ac..424f857d9b 100644 --- a/packages/core/src/renderer/app-paths/setup-app-paths.injectable.ts +++ b/packages/core/src/renderer/app-paths/setup-app-paths.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable"; import { beforeFrameStartsFirstInjectionToken } from "../before-frame-starts/tokens"; import { appPathsChannel } from "../../common/app-paths/app-paths-channel"; -import { requestFromChannelInjectionToken } from "../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; const setupAppPathsInjectable = getInjectable({ id: "setup-app-paths", diff --git a/packages/core/src/renderer/before-frame-starts/runnables/setup-current-cluster-broadcast.injectable.ts b/packages/core/src/renderer/before-frame-starts/runnables/setup-current-cluster-broadcast.injectable.ts index 0d9c8bc65a..e60eb3fae1 100644 --- a/packages/core/src/renderer/before-frame-starts/runnables/setup-current-cluster-broadcast.injectable.ts +++ b/packages/core/src/renderer/before-frame-starts/runnables/setup-current-cluster-broadcast.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { reaction } from "mobx"; import { currentClusterMessageChannel } from "../../../common/cluster/current-cluster-channel"; -import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import matchedClusterIdInjectable from "../../navigation/matched-cluster-id.injectable"; import { beforeMainFrameStartsFirstInjectionToken } from "../tokens"; diff --git a/packages/core/src/renderer/certificate/request-lens-proxy-certificate.injectable.ts b/packages/core/src/renderer/certificate/request-lens-proxy-certificate.injectable.ts index e1322096bf..f80911c7a5 100644 --- a/packages/core/src/renderer/certificate/request-lens-proxy-certificate.injectable.ts +++ b/packages/core/src/renderer/certificate/request-lens-proxy-certificate.injectable.ts @@ -4,12 +4,12 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { lensProxyCertificateChannel } from "../../common/certificate/lens-proxy-certificate-channel"; -import requestFromChannelInjectable from "../utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; const requestLensProxyCertificateInjectable = getInjectable({ id: "request-lens-proxy-certificate", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return () => requestFromChannel(lensProxyCertificateChannel); }, diff --git a/packages/core/src/renderer/components/+extensions/attempt-install-by-info.injectable.tsx b/packages/core/src/renderer/components/+extensions/attempt-install-by-info.injectable.tsx index 523a91596e..8f2e5692d1 100644 --- a/packages/core/src/renderer/components/+extensions/attempt-install-by-info.injectable.tsx +++ b/packages/core/src/renderer/components/+extensions/attempt-install-by-info.injectable.tsx @@ -26,6 +26,7 @@ export interface ExtensionInfo { requireConfirmation?: boolean; } +// @ts-ignore interface NpmPackageVersionDescriptor extends PackageJson { dist: { integrity: string; diff --git a/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts b/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts index 08a49bb496..7420fa680a 100644 --- a/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts +++ b/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts @@ -10,7 +10,6 @@ import { onceDefined } from "@k8slens/utilities"; import assert from "assert"; import type { Logger } from "../../../common/logger"; import type { GetClusterById } from "../../../common/cluster-store/get-by-id.injectable"; -import type { EmitClusterVisibility } from "./emit-cluster-visibility.injectable"; import { getClusterFrameUrl } from "../../../common/utils"; export interface LensView { @@ -21,7 +20,7 @@ export interface LensView { interface Dependencies { readonly logger: Logger; getClusterById: GetClusterById; - emitClusterVisibility: EmitClusterVisibility; + emitClusterVisibility: (clusterId: ClusterId | null) => void; } export class ClusterFrameHandler { diff --git a/packages/core/src/renderer/components/cluster-manager/emit-cluster-visibility.injectable.ts b/packages/core/src/renderer/components/cluster-manager/emit-cluster-visibility.injectable.ts index 261582d136..5c941c60e6 100644 --- a/packages/core/src/renderer/components/cluster-manager/emit-cluster-visibility.injectable.ts +++ b/packages/core/src/renderer/components/cluster-manager/emit-cluster-visibility.injectable.ts @@ -3,18 +3,16 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { MessageChannelHandler } from "../../../common/utils/channel/message-channel-listener-injection-token"; -import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import { clusterVisibilityChannel } from "../../../common/cluster/visibility-channel"; - -export type EmitClusterVisibility = MessageChannelHandler; +import type { ClusterId } from "../../../common/cluster-types"; const emitClusterVisibilityInjectable = getInjectable({ id: "emit-cluster-visibility", - instantiate: (di): EmitClusterVisibility => { + instantiate: (di) => { const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); - return (id) => sendMessageToChannel(clusterVisibilityChannel, id); + return (id: ClusterId | null) => sendMessageToChannel(clusterVisibilityChannel, id); }, }); diff --git a/packages/core/src/renderer/components/test-utils/get-application-builder.tsx b/packages/core/src/renderer/components/test-utils/get-application-builder.tsx index 0d202aa1e5..cad903da39 100644 --- a/packages/core/src/renderer/components/test-utils/get-application-builder.tsx +++ b/packages/core/src/renderer/components/test-utils/get-application-builder.tsx @@ -29,7 +29,6 @@ import type { MinimalTrayMenuItem } from "../../../main/tray/electron-tray/elect import electronTrayInjectable from "../../../main/tray/electron-tray/electron-tray.injectable"; import { getDiForUnitTesting as getRendererDi } from "../../getDiForUnitTesting"; import { getDiForUnitTesting as getMainDi } from "../../../main/getDiForUnitTesting"; -import { overrideChannels } from "../../../test-utils/channel-fakes/override-channels"; import assert from "assert"; import { openMenu } from "react-select-event"; import userEvent from "@testing-library/user-event"; @@ -40,7 +39,7 @@ import { navigateToRouteInjectionToken } from "../../../common/front-end-routing import type { LensMainExtension } from "../../../extensions/lens-main-extension"; import type { LensExtension } from "../../../extensions/lens-extension"; import extensionInjectable from "../../../extensions/extension-loader/extension/extension.injectable"; -import { renderFor } from "./renderFor"; +import { renderFor } from "@k8slens/test-utils"; import { RootFrame } from "../../frames/root-frame/root-frame"; import { ClusterFrame } from "../../frames/cluster-frame/cluster-frame"; import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable"; @@ -71,6 +70,7 @@ import { registerFeature } from "@k8slens/feature-core"; import { applicationFeatureForElectronMain, testUtils as applicationForElectronTestUtils } from "@k8slens/application-for-electron-main"; import { applicationFeature, startApplicationInjectionToken } from "@k8slens/application"; import { testUsingFakeTime } from "../../../test-utils/use-fake-time"; +import { sendMessageToChannelInjectionToken, testUtils as messagingTestUtils } from "@k8slens/messaging"; type MainDiCallback = (container: { mainDi: DiContainer }) => void | Promise; type WindowDiCallback = (container: { windowDi: DiContainer }) => void | Promise; @@ -179,7 +179,9 @@ export const getApplicationBuilder = () => { testUsingFakeTime(); - const { overrideForWindow, sendToWindow } = overrideChannels(mainDi); + const messageBridgeFake = messagingTestUtils.getMessageBridgeFake(); + + messageBridgeFake.involve(mainDi); const beforeApplicationStartCallbacks: MainDiCallback[] = []; const afterApplicationStartCallbacks: MainDiCallback[] = []; @@ -229,7 +231,8 @@ export const getApplicationBuilder = () => { const windowDi = getRendererDi(); - overrideForWindow(windowDi, windowId); + messageBridgeFake.involve(windowDi); + overrideFsWithFakes(windowDi); runInAction(() => { @@ -284,8 +287,10 @@ export const getApplicationBuilder = () => { ); }, - send: (arg) => { - sendToWindow(windowId, arg); + send: ({ channel: channelId, data }) => { + const sendMessageToChannel = mainDi.inject(sendMessageToChannelInjectionToken); + + sendMessageToChannel({ id: channelId }, data); }, reload: () => { diff --git a/packages/core/src/renderer/frames/root-frame/broadcast-that-root-frame-is-rendered.injectable.ts b/packages/core/src/renderer/frames/root-frame/broadcast-that-root-frame-is-rendered.injectable.ts index 841d19e002..dd43cbd301 100644 --- a/packages/core/src/renderer/frames/root-frame/broadcast-that-root-frame-is-rendered.injectable.ts +++ b/packages/core/src/renderer/frames/root-frame/broadcast-that-root-frame-is-rendered.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import { rootFrameHasRenderedChannel } from "../../../common/root-frame/root-frame-rendered-channel"; const broadcastThatRootFrameIsRenderedInjectable = getInjectable({ diff --git a/packages/core/src/renderer/getDiForUnitTesting.tsx b/packages/core/src/renderer/getDiForUnitTesting.tsx index fbee046de2..ec389e1b10 100644 --- a/packages/core/src/renderer/getDiForUnitTesting.tsx +++ b/packages/core/src/renderer/getDiForUnitTesting.tsx @@ -5,7 +5,6 @@ import { noop, chunk } from "lodash/fp"; import { createContainer, isInjectable } from "@ogre-tools/injectable"; -import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable"; import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes"; import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable"; import hostedClusterIdInjectable from "./cluster-frame-context/hosted-cluster-id.injectable"; @@ -18,6 +17,8 @@ import type { GlobalOverride } from "@k8slens/test-utils"; import { setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import { registerInjectableReact } from "@ogre-tools/injectable-react"; +import { registerFeature } from "@k8slens/feature-core"; +import { messagingFeature, testUtils as messagingTestUtils } from "@k8slens/messaging"; export const getDiForUnitTesting = () => { const environment = "renderer"; @@ -27,6 +28,10 @@ export const getDiForUnitTesting = () => { registerInjectableReact(di); setLegacyGlobalDiForExtensionApi(di, environment); + runInAction(() => { + registerFeature(di, messagingFeature, messagingTestUtils.messagingFeatureForUnitTesting); + }); + di.preventSideEffects(); runInAction(() => { @@ -63,8 +68,6 @@ export const getDiForUnitTesting = () => { di.override(requestAnimationFrameInjectable, () => (callback) => callback()); di.override(watchHistoryStateInjectable, () => () => () => {}); - di.override(requestFromChannelInjectable, () => () => Promise.resolve(undefined as never)); - getOverrideFsWithFakes()(di); return di; diff --git a/packages/core/src/renderer/kubectl/apply-all.injectable.ts b/packages/core/src/renderer/kubectl/apply-all.injectable.ts index 989017f9d9..ffc5be14ba 100644 --- a/packages/core/src/renderer/kubectl/apply-all.injectable.ts +++ b/packages/core/src/renderer/kubectl/apply-all.injectable.ts @@ -4,12 +4,12 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { kubectlApplyAllChannel, kubectlApplyAllInjectionToken } from "../../common/kube-helpers/channels"; -import requestFromChannelInjectable from "../utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; const kubectlApplyAllInjectable = getInjectable({ id: "kubectl-apply-all", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return (req) => requestFromChannel(kubectlApplyAllChannel, req); }, diff --git a/packages/core/src/renderer/kubectl/delete-all.injectable.ts b/packages/core/src/renderer/kubectl/delete-all.injectable.ts index 586895c75c..4a3ee05f54 100644 --- a/packages/core/src/renderer/kubectl/delete-all.injectable.ts +++ b/packages/core/src/renderer/kubectl/delete-all.injectable.ts @@ -4,12 +4,12 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { kubectlDeleteAllChannel, kubectlDeleteAllInjectionToken } from "../../common/kube-helpers/channels"; -import requestFromChannelInjectable from "../utils/channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; const kubectlDeleteAllInjectable = getInjectable({ id: "kubectl-delete-all", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return (req) => requestFromChannel(kubectlDeleteAllChannel, req); }, diff --git a/packages/core/src/renderer/navigation/navigation-channel-listener.injectable.ts b/packages/core/src/renderer/navigation/navigation-channel-listener.injectable.ts index 1b33b4fe2c..15b29b3463 100644 --- a/packages/core/src/renderer/navigation/navigation-channel-listener.injectable.ts +++ b/packages/core/src/renderer/navigation/navigation-channel-listener.injectable.ts @@ -2,25 +2,25 @@ * 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 { 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"; +import type { MessageChannel, MessageChannelListener } from "@k8slens/messaging"; +import { messageChannelListenerInjectionToken } from "@k8slens/messaging"; const navigationChannelListenerInjectable = getInjectable({ id: "navigation-channel-listener", - instantiate: (di) => { + instantiate: (di): MessageChannelListener> => { const currentlyInClusterFrame = di.inject(currentlyInClusterFrameInjectable); const focusWindow = di.inject(focusWindowInjectable); const navigateToUrl = di.inject(navigateToUrlInjectionToken); return { + id: 'navigation-channel-listener', channel: currentlyInClusterFrame ? clusterFrameNavigationChannel : appNavigationChannel, @@ -34,7 +34,8 @@ const navigationChannelListenerInjectable = getInjectable({ }, }; }, - injectionToken: messageChannelListenerInjectionToken as InjectionToken>, void>, + + injectionToken: messageChannelListenerInjectionToken }); export default navigationChannelListenerInjectable; diff --git a/packages/core/src/renderer/utils/resolve-proxy/resolve-system-proxy.injectable.ts b/packages/core/src/renderer/utils/resolve-proxy/resolve-system-proxy.injectable.ts index 5468a8c7b7..55cd0d66d5 100644 --- a/packages/core/src/renderer/utils/resolve-proxy/resolve-system-proxy.injectable.ts +++ b/packages/core/src/renderer/utils/resolve-proxy/resolve-system-proxy.injectable.ts @@ -4,14 +4,14 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { resolveSystemProxyInjectionToken } from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token"; -import requestFromChannelInjectable from "../channel/request-from-channel.injectable"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { resolveSystemProxyChannel } from "../../../common/utils/resolve-system-proxy/resolve-system-proxy-channel"; const resolveSystemProxyInjectable = getInjectable({ id: "resolve-system-proxy-for-renderer", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectable); + const requestFromChannel = di.inject(requestFromChannelInjectionToken); return async (url) => requestFromChannel(resolveSystemProxyChannel, url); }, diff --git a/packages/core/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts b/packages/core/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts index aceb20cea4..b4eb648c87 100644 --- a/packages/core/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts +++ b/packages/core/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { beforeFrameStartsSecondInjectionToken } from "../../before-frame-starts/tokens"; import { syncBoxInitialValueChannel } from "../../../common/utils/sync-box/channels"; import createSyncBoxStateInjectable from "../../../common/utils/sync-box/sync-box-state.injectable"; -import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { runInAction } from "mobx"; import { syncBoxInjectionToken } from "../../../common/utils/sync-box/sync-box-injection-token"; import assert from "assert"; diff --git a/packages/core/src/renderer/vars/build-version/build-version.injectable.ts b/packages/core/src/renderer/vars/build-version/build-version.injectable.ts index a63a4102b0..f9ba5e34b0 100644 --- a/packages/core/src/renderer/vars/build-version/build-version.injectable.ts +++ b/packages/core/src/renderer/vars/build-version/build-version.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { createInitializableState } from "../../../common/initializable-state/create"; -import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { buildVersionChannel, buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable"; const buildVersionInjectable = createInitializableState({ diff --git a/packages/open-lens/package.json b/packages/open-lens/package.json index da7069a3b8..daeca1a6d6 100644 --- a/packages/open-lens/package.json +++ b/packages/open-lens/package.json @@ -203,6 +203,9 @@ "@k8slens/generate-tray-icons": "^6.5.0-alpha.1", "@k8slens/legacy-extension-example": "^1.0.0-alpha.1", "@k8slens/legacy-extensions": "^1.0.0-alpha.1", + "@k8slens/messaging": "^1.0.0-alpha.1", + "@k8slens/messaging-for-main": "^1.0.0-alpha.1", + "@k8slens/messaging-for-renderer": "^1.0.0-alpha.1", "@k8slens/run-many": "^1.0.0-alpha.1", "@k8slens/startable-stoppable": "^1.0.0-alpha.1", "@k8slens/test-utils": "^1.0.0-alpha.1", diff --git a/packages/open-lens/src/main/index.ts b/packages/open-lens/src/main/index.ts index 5329be4595..84e187ba5c 100644 --- a/packages/open-lens/src/main/index.ts +++ b/packages/open-lens/src/main/index.ts @@ -10,6 +10,7 @@ import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import { registerFeature } from "@k8slens/feature-core"; import { applicationFeature, startApplicationInjectionToken } from '@k8slens/application' import { applicationFeatureForElectronMain } from '@k8slens/application-for-electron-main' +import { messagingFeatureForMain } from "@k8slens/messaging-for-main"; const environment = "main"; @@ -20,7 +21,7 @@ registerMobX(di); runInAction(() => { registerLensCore(di, environment); - registerFeature(di, applicationFeature, applicationFeatureForElectronMain); + registerFeature(di, applicationFeature, applicationFeatureForElectronMain, messagingFeatureForMain); try { autoRegister({ diff --git a/packages/open-lens/src/renderer/index.ts b/packages/open-lens/src/renderer/index.ts index 9f0770de26..207fc2265c 100644 --- a/packages/open-lens/src/renderer/index.ts +++ b/packages/open-lens/src/renderer/index.ts @@ -14,6 +14,7 @@ import { import { createContainer } from "@ogre-tools/injectable"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import { registerInjectableReact } from "@ogre-tools/injectable-react"; +import { messagingFeatureForRenderer } from "@k8slens/messaging-for-renderer"; const environment = "renderer"; @@ -23,7 +24,7 @@ runInAction(() => { registerMobX(di); registerInjectableReact(di); registerLensCore(di, environment); - registerFeature(di, applicationFeature); + registerFeature(di, applicationFeature, messagingFeatureForRenderer); autoRegister({ di,