1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Switch to using messaging and startable stoppable from NPM package (#7368)

* Add custom jest resolver to fix requiring "uuid" module

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Update dependencies

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Introduce test utils for rendering and running with thrown mobx reactions

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Extract startable-stoppable to NPM package

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Extract messaging to NPM package

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Switch to using startable-stoppable from NPM package

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Switch to using messaging from the Feature

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove old implementation of messaging

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make setupping app paths happen earlier in renderer

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Fix typo

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add kludge to make testing-library work properly from test-utils package

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Fix code style

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add lint:fix -root script

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Fix unrelated failing unit tests

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Turn of no-floating-promises from typescript linting for being broken

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make linting not happen for dist -directories

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make linting failures appear as failure

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Stop running prettier twice

It already gets ran as eslint-plugin.

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make CI run unit tests for all packages by consolidating name of NPM script

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add missing unit tests for coverage

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Skip coverage for test utils

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove check for coverage in packages which are not ready for it

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Stop collecting coverage from index.ts files them being indirections to the implementation

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Implement sending message to channel in main

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add missing feature dependencies

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add dummy implementations for requesting in main from renderer

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Re-enable communicating from main to cluster frames

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Ignore trivial files from coverage

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Update package-lock

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Extract message-bridge to separate NPM package to prevent dev dependencies being in the production bundle

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Extract computed channel to own NPM package for clear dependencies

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Consolidate electron related stuff to a directory

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add missing publish configurations

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Ignore test implementation from coverage being not interesting

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

---------

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-03-21 11:38:43 +02:00 committed by GitHub
parent df49ff9b96
commit 0f1f030a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
261 changed files with 4447 additions and 1795 deletions

1200
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@
"clean:node_modules": "lerna clean -y && rimraf node_modules", "clean:node_modules": "lerna clean -y && rimraf node_modules",
"dev": "lerna run dev --stream --skip-nx-cache", "dev": "lerna run dev --stream --skip-nx-cache",
"lint": "lerna run lint --stream", "lint": "lerna run lint --stream",
"lint:fix": "lerna run lint:fix --stream",
"mkdocs:serve-local": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest", "mkdocs:serve-local": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest",
"mkdocs:verify": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -v ${PWD}:/docs mkdocs-serve-local:latest build --strict", "mkdocs:verify": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -v ${PWD}:/docs mkdocs-serve-local:latest build --strict",
"test:unit": "lerna run --stream test:unit", "test:unit": "lerna run --stream test:unit",

View File

@ -189,6 +189,7 @@
}, },
"devDependencies": { "devDependencies": {
"@async-fn/jest": "1.6.4", "@async-fn/jest": "1.6.4",
"@k8slens/messaging-fake-bridge": "^1.0.0-alpha.1",
"@material-ui/core": "^4.12.3", "@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2", "@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60", "@material-ui/lab": "^4.0.0-alpha.60",
@ -322,7 +323,11 @@
"@k8slens/application": "^6.5.0-alpha.0", "@k8slens/application": "^6.5.0-alpha.0",
"@k8slens/application-for-electron-main": "^6.5.0-alpha.0", "@k8slens/application-for-electron-main": "^6.5.0-alpha.0",
"@k8slens/legacy-extensions": "^1.0.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/run-many": "^1.0.0-alpha.1",
"@k8slens/startable-stoppable": "^1.0.0-alpha.1",
"@k8slens/test-utils": "^1.0.0-alpha.1", "@k8slens/test-utils": "^1.0.0-alpha.1",
"@k8slens/utilities": "^1.0.0-alpha.1", "@k8slens/utilities": "^1.0.0-alpha.1",
"@types/byline": "^4.2.33", "@types/byline": "^4.2.33",

View File

@ -3,11 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { AppPaths } from "./app-path-injection-token"; 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<void, AppPaths>; export const appPathsChannel = getRequestChannel<void, AppPaths>("app-paths");
export const appPathsChannel: AppPathsChannel = {
id: "app-paths",
};

View File

@ -15,7 +15,7 @@ import type { GetConfigurationFileModel } from "../get-configuration-file-model/
import type { Logger } from "../logger"; import type { Logger } from "../logger";
import type { PersistStateToConfig } from "./save-to-file"; import type { PersistStateToConfig } from "./save-to-file";
import type { GetBasenameOfPath } from "../path/get-basename.injectable"; 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"; import { toJS } from "../utils";
export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> { export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> {
@ -108,6 +108,7 @@ export abstract class BaseStore<T extends object> {
this.params.syncOptions, this.params.syncOptions,
), ),
this.dependencies.enlistMessageChannelListener({ this.dependencies.enlistMessageChannelListener({
id: this.displayName,
channel: { channel: {
id: `${this.dependencies.ipcChannelPrefixes.local}:${config.path}`, id: `${this.dependencies.ipcChannelPrefixes.local}:${config.path}`,
}, },

View File

@ -4,6 +4,6 @@
*/ */
import type { SelfSignedCert } from "selfsigned"; import type { SelfSignedCert } from "selfsigned";
import { getRequestChannel } from "../utils/channel/get-request-channel"; import { getRequestChannel } from "@k8slens/messaging";
export const lensProxyCertificateChannel = getRequestChannel<void, SelfSignedCert>("request-lens-proxy-certificate"); export const lensProxyCertificateChannel = getRequestChannel<void, SelfSignedCert>("request-lens-proxy-certificate");

View File

@ -16,7 +16,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync"; import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; import { persistStateToConfigInjectionToken } from "../base-store/save-to-file";
import getBasenameOfPathInjectable from "../path/get-basename.injectable"; 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({ const clusterStoreInjectable = getInjectable({
id: "cluster-store", id: "cluster-store",

View File

@ -4,7 +4,7 @@
*/ */
import type { ClusterId } from "../cluster-types"; 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<ClusterId> = { export const currentClusterMessageChannel: MessageChannel<ClusterId> = {
id: "current-visible-cluster", id: "current-visible-cluster",

View File

@ -4,7 +4,7 @@
*/ */
import type { ClusterId } from "../cluster-types"; 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<ClusterId | null> = { export const clusterVisibilityChannel: MessageChannel<ClusterId | null> = {
id: "cluster-visibility", id: "cluster-visibility",

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { IpcRendererNavigationEvents } from "../ipc/navigation-events"; 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<string>; export type AppNavigationChannel = MessageChannel<string>;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { IpcRendererNavigationEvents } from "../ipc/navigation-events"; 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<string>; export type ClusterFrameNavigationChannel = MessageChannel<string>;

View File

@ -3,11 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { HelmRepo } from "./helm-repo"; import type { HelmRepo } from "./helm-repo";
import type { AsyncResult } from "@k8slens/utilities"; import type { Result } from "@k8slens/utilities";
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; import { getRequestChannel } from "@k8slens/messaging";
export type AddHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<void, string>>; export const addHelmRepositoryChannel = getRequestChannel<
HelmRepo,
export const addHelmRepositoryChannel: AddHelmRepositoryChannel = { Result<void, string>
id: "add-helm-repository-channel", >("add-helm-repository-channel");
};

View File

@ -4,10 +4,9 @@
*/ */
import type { HelmRepo } from "./helm-repo"; import type { HelmRepo } from "./helm-repo";
import type { AsyncResult } from "@k8slens/utilities"; 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<void, AsyncResult<HelmRepo[]>>; export const getActiveHelmRepositoriesChannel = getRequestChannel<
void,
export const getActiveHelmRepositoriesChannel: GetActiveHelmRepositoriesChannel = { AsyncResult<HelmRepo[]>
id: "get-helm-active-list-repositories", >("get-helm-active-list-repositories");
};

View File

@ -3,11 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { AsyncResult } from "@k8slens/utilities"; 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"; import type { HelmRepo } from "./helm-repo";
export type RemoveHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<void, string>>; export const removeHelmRepositoryChannel = getRequestChannel<
HelmRepo,
export const removeHelmRepositoryChannel: RemoveHelmRepositoryChannel = { AsyncResult<void, string>
id: "remove-helm-repository-channel", >("remove-helm-repository-channel");
};

View File

@ -14,7 +14,7 @@ import { hotbarStoreMigrationInjectionToken } from "./migrations-token";
import getBasenameOfPathInjectable from "../path/get-basename.injectable"; import getBasenameOfPathInjectable from "../path/get-basename.injectable";
import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel-prefix"; import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel-prefix";
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; 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"; import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
const hotbarStoreInjectable = getInjectable({ const hotbarStoreInjectable = getInjectable({

View File

@ -4,11 +4,9 @@
*/ */
import { getInjectionToken } from "@ogre-tools/injectable"; 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 { ClusterId } from "../cluster-types";
import type { AsyncResult } from "@k8slens/utilities"; import type { AsyncResult, Result } from "@k8slens/utilities";
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; import { getRequestChannel } from "@k8slens/messaging";
export interface KubectlApplyAllArgs { export interface KubectlApplyAllArgs {
clusterId: ClusterId; clusterId: ClusterId;
@ -16,11 +14,12 @@ export interface KubectlApplyAllArgs {
extraArgs: string[]; extraArgs: string[];
} }
export const kubectlApplyAllChannel: RequestChannel<KubectlApplyAllArgs, AsyncResult<string, string>> = { export const kubectlApplyAllChannel = getRequestChannel<
id: "kubectl-apply-all", KubectlApplyAllArgs,
}; Result<string, string>
>("kubectl-apply-all");
export type KubectlApplyAll = Asyncify<RequestChannelHandler<typeof kubectlApplyAllChannel>>; export type KubectlApplyAll = (req: KubectlApplyAllArgs) => AsyncResult<string, string>;
export const kubectlApplyAllInjectionToken = getInjectionToken<KubectlApplyAll>({ export const kubectlApplyAllInjectionToken = getInjectionToken<KubectlApplyAll>({
id: "kubectl-apply-all", id: "kubectl-apply-all",
@ -32,11 +31,12 @@ export interface KubectlDeleteAllArgs {
extraArgs: string[]; extraArgs: string[];
} }
export const kubectlDeleteAllChannel: RequestChannel<KubectlDeleteAllArgs, AsyncResult<string, string>> = { export const kubectlDeleteAllChannel = getRequestChannel<
id: "kubectl-delete-all", KubectlDeleteAllArgs,
}; Result<string, string>
>("kubectl-delete-all");
export type KubectlDeleteAll = Asyncify<RequestChannelHandler<typeof kubectlDeleteAllChannel>>; export type KubectlDeleteAll = (req: KubectlDeleteAllArgs) => AsyncResult<string, string>;
export const kubectlDeleteAllInjectionToken = getInjectionToken<KubectlDeleteAll>({ export const kubectlDeleteAllInjectionToken = getInjectionToken<KubectlDeleteAll>({
id: "kubectl-delete-all", id: "kubectl-delete-all",

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; import type { MessageChannel } from "@k8slens/messaging";
export type RootFrameHasRenderedChannel = MessageChannel<void>; export type RootFrameHasRenderedChannel = MessageChannel<void>;

View File

@ -16,7 +16,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../base-store/channel
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync"; import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../base-store/disable-sync";
import { persistStateToConfigInjectionToken } from "../base-store/save-to-file"; import { persistStateToConfigInjectionToken } from "../base-store/save-to-file";
import getBasenameOfPathInjectable from "../path/get-basename.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 userStorePreferenceDescriptorsInjectable from "./preference-descriptors.injectable"; import userStorePreferenceDescriptorsInjectable from "./preference-descriptors.injectable";
const userStoreInjectable = getInjectable({ const userStoreInjectable = getInjectable({

View File

@ -1,245 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { SendMessageToChannel } from "./message-to-channel-injection-token";
import { sendMessageToChannelInjectionToken } from "./message-to-channel-injection-token";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import type { LensWindow } from "../../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
import type { MessageChannel } from "./message-channel-listener-injection-token";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
import type { RequestFromChannel } from "./request-from-channel-injection-token";
import { requestFromChannelInjectionToken } from "./request-from-channel-injection-token";
import type { RequestChannel } from "./request-channel-listener-injection-token";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import { getPromiseStatus } from "@k8slens/test-utils";
import { runInAction } from "mobx";
import type { RequestChannelHandler } from "../../../main/utils/channel/channel-listeners/listener-tokens";
import {
getRequestChannelListenerInjectable,
requestChannelListenerInjectionToken,
} from "../../../main/utils/channel/channel-listeners/listener-tokens";
type TestMessageChannel = MessageChannel<string>;
type TestRequestChannel = RequestChannel<string, string>;
describe("channel", () => {
describe("messaging from main to renderer, given listener for channel in a window and application has started", () => {
let messageListenerInWindowMock: jest.Mock;
let mainDi: DiContainer;
let messageToChannel: SendMessageToChannel;
let builder: ApplicationBuilder;
beforeEach(async () => {
builder = getApplicationBuilder();
messageListenerInWindowMock = jest.fn();
const testChannelListenerInTestWindowInjectable = getInjectable({
id: "test-channel-listener-in-test-window",
instantiate: () => ({
channel: testMessageChannel,
handler: messageListenerInWindowMock,
}),
injectionToken: messageChannelListenerInjectionToken,
});
builder.beforeWindowStart(({ windowDi }) => {
runInAction(() => {
windowDi.register(testChannelListenerInTestWindowInjectable);
});
});
mainDi = builder.mainDi;
await builder.startHidden();
messageToChannel = mainDi.inject(sendMessageToChannelInjectionToken);
});
describe("given window is started", () => {
let someWindowFake: LensWindow;
beforeEach(async () => {
someWindowFake = builder.applicationWindow.create("some-window");
await someWindowFake.start();
});
it("when sending message, triggers listener in window", () => {
messageToChannel(testMessageChannel, "some-message");
expect(messageListenerInWindowMock).toHaveBeenCalledWith("some-message");
});
it("given window is hidden, when sending message, does not trigger listener in window", () => {
someWindowFake.close();
messageToChannel(testMessageChannel, "some-message");
expect(messageListenerInWindowMock).not.toHaveBeenCalled();
});
});
it("given multiple started windows, when sending message, triggers listeners in all windows", async () => {
const someWindowFake = builder.applicationWindow.create("some-window");
const someOtherWindowFake = builder.applicationWindow.create("some-other-window");
await someWindowFake.start();
await someOtherWindowFake.start();
messageToChannel(testMessageChannel, "some-message");
expect(messageListenerInWindowMock.mock.calls).toEqual([
["some-message"],
["some-message"],
]);
});
});
describe("messaging from renderer to main, given listener for channel in a main and application has started", () => {
let messageListenerInMainMock: jest.Mock;
let messageToChannel: SendMessageToChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
messageListenerInMainMock = jest.fn();
const testChannelListenerInMainInjectable = getInjectable({
id: "test-channel-listener-in-main",
instantiate: () => ({
channel: testMessageChannel,
handler: messageListenerInMainMock,
}),
injectionToken: messageChannelListenerInjectionToken,
});
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
runInAction(() => {
mainDi.register(testChannelListenerInMainInjectable);
});
});
await applicationBuilder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
messageToChannel = windowDi.inject(sendMessageToChannelInjectionToken);
});
it("when sending message, triggers listener in main", () => {
messageToChannel(testMessageChannel, "some-message");
expect(messageListenerInMainMock).toHaveBeenCalledWith("some-message");
});
});
describe("requesting from main in renderer, given listener for channel in a main and application has started", () => {
let requestListenerInMainMock: AsyncFnMock<RequestChannelHandler<TestRequestChannel>>;
let requestFromChannel: RequestFromChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
requestListenerInMainMock = asyncFn();
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
channel: testRequestChannel,
handler: () => requestListenerInMainMock,
});
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
runInAction(() => {
mainDi.register(testChannelListenerInMainInjectable);
});
});
await applicationBuilder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
requestFromChannel = windowDi.inject(
requestFromChannelInjectionToken,
);
});
describe("when requesting from channel", () => {
let actualPromise: Promise<string>;
beforeEach(() => {
actualPromise = requestFromChannel(testRequestChannel, "some-request");
});
it("triggers listener in main", () => {
expect(requestListenerInMainMock).toHaveBeenCalledWith("some-request");
});
it("does not resolve yet", async () => {
const promiseStatus = await getPromiseStatus(actualPromise);
expect(promiseStatus.fulfilled).toBe(false);
});
it("when main resolves with response, resolves with response", async () => {
await requestListenerInMainMock.resolve("some-response");
const actual = await actualPromise;
expect(actual).toBe("some-response");
});
});
});
it("when registering multiple handlers for the same channel, throws", async () => {
const applicationBuilder = getApplicationBuilder();
const someChannelListenerInjectable = getInjectable({
id: "some-channel-listener",
instantiate: () => ({
channel: testRequestChannel,
handler: () => () => "irrelevant",
}),
injectionToken: requestChannelListenerInjectionToken,
});
const someOtherChannelListenerInjectable = getInjectable({
id: "some-other-channel-listener",
instantiate: () => ({
channel: testRequestChannel,
handler: () => () => "irrelevant",
}),
injectionToken: requestChannelListenerInjectionToken,
});
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
runInAction(() => {
mainDi.register(someChannelListenerInjectable);
mainDi.register(someOtherChannelListenerInjectable);
});
});
await expect(applicationBuilder.render()).rejects.toThrow('Tried to register a multiple channel handlers for "some-request-channel-id", only one handler is supported for a request channel.');
});
});
const testMessageChannel: TestMessageChannel = {
id: "some-message-channel-id",
};
const testRequestChannel: TestRequestChannel = {
id: "some-request-channel-id",
};

View File

@ -1,13 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Disposer } from "@k8slens/utilities";
import type { MessageChannel, MessageChannelListener } from "./message-channel-listener-injection-token";
export type EnlistMessageChannelListener = (listener: MessageChannelListener<MessageChannel<unknown>>) => Disposer;
export const enlistMessageChannelListenerInjectionToken = getInjectionToken<EnlistMessageChannelListener>({
id: "enlist-message-channel-listener",
});

View File

@ -1,9 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RequestChannel } from "./request-channel-listener-injection-token";
export const getRequestChannel = <Request, Response>(id: string): RequestChannel<Request, Response> => ({
id,
});

View File

@ -1,25 +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 { getStartableStoppable } from "../get-startable-stoppable";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
import { disposer } from "@k8slens/utilities";
const listeningOnMessageChannelsInjectable = getInjectable({
id: "listening-on-message-channels",
instantiate: (di) => {
const enlistMessageChannelListener = di.inject(enlistMessageChannelListenerInjectionToken);
const messageChannelListeners = di.injectMany(messageChannelListenerInjectionToken);
return getStartableStoppable("listening-on-channels", () => (
disposer(messageChannelListeners.map(enlistMessageChannelListener))
));
},
});
export default listeningOnMessageChannelsInjectable;

View File

@ -1,51 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainerForInjection } from "@ogre-tools/injectable";
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
export interface MessageChannel<Message> {
id: string;
_messageSignature?: Message; // only used to mark `Message` as used
}
export type MessageChannelHandler<Channel> = Channel extends MessageChannel<infer Message>
? (message: Message) => void
: never;
export interface MessageChannelListener<Channel> {
channel: Channel;
handler: MessageChannelHandler<Channel>;
}
export const messageChannelListenerInjectionToken = getInjectionToken<MessageChannelListener<MessageChannel<unknown>>>(
{
id: "message-channel-listener",
},
);
export interface GetMessageChannelListenerInfo<
Channel extends MessageChannel<Message>,
Message,
> {
id: string;
channel: Channel;
handler: (di: DiContainerForInjection) => MessageChannelHandler<Channel>;
causesSideEffects?: boolean;
}
export function getMessageChannelListenerInjectable<
Channel extends MessageChannel<Message>,
Message,
>(info: GetMessageChannelListenerInfo<Channel, Message>) {
return getInjectable({
id: `${info.channel.id}-listener-${info.id}`,
instantiate: (di) => ({
channel: info.channel,
handler: info.handler(di),
}),
injectionToken: messageChannelListenerInjectionToken,
causesSideEffects: info.causesSideEffects,
});
}

View File

@ -1,10 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export interface RequestChannel<Request, Response> {
id: string;
_requestSignature?: Request; // used only to mark `Request` as "used"
_responseSignature?: Response; // used only to mark `Response` as "used"
}

View File

@ -2,10 +2,8 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { RequestChannel } from "../channel/request-channel-listener-injection-token"; import { getRequestChannel } from "@k8slens/messaging";
export type ResolveSystemProxyChannel = RequestChannel<string, string>; export const resolveSystemProxyChannel = getRequestChannel<string, string>(
"resolve-system-proxy-channel",
export const resolveSystemProxyChannel: ResolveSystemProxyChannel = { );
id: "resolve-system-proxy-channel",
};

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { syncBoxChannel } from "./channels"; 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"; import syncBoxStateInjectable from "./sync-box-state.injectable";
const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({ const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "init", id: "init",
channel: syncBoxChannel, 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; export default syncBoxChannelListenerInjectable;

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../channel/message-channel-listener-injection-token"; import { getMessageChannel, getRequestChannel } from "@k8slens/messaging";
import type { RequestChannel } from "../channel/request-channel-listener-injection-token";
export type SyncBoxChannel = MessageChannel<{ id: string; value: any }>; export const syncBoxChannel =
getMessageChannel<{ id: string; value: any }>("sync-box-channel");
export const syncBoxChannel: SyncBoxChannel = { export const syncBoxInitialValueChannel = getRequestChannel<
id: "sync-box-channel",
};
export type SyncBoxInitialValueChannel = RequestChannel<
void, void,
{ id: string; value: any }[] { id: string; value: any }[]
>; >("sync-box-initial-value-channel");
export const syncBoxInitialValueChannel: SyncBoxInitialValueChannel = {
id: "sync-box-initial-value-channel",
};

View File

@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { IObservableValue } from "mobx"; import type { IObservableValue } from "mobx";
import { computed } from "mobx"; import { computed } from "mobx";
import { syncBoxChannel } from "./channels"; 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 syncBoxStateInjectable from "./sync-box-state.injectable";
import type { SyncBox } from "./sync-box-injection-token"; import type { SyncBox } from "./sync-box-injection-token";
import { toJS } from "../toJS"; import { toJS } from "../toJS";

View File

@ -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<SyncBoxChannel> => {
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
return ({ id, value }) => getSyncBoxState(id)?.set(value);
},
});
export default syncBoxChannelHandlerInjectable;

View File

@ -7,7 +7,7 @@ import { getInjectionToken } from "@ogre-tools/injectable";
import { SemVer } from "semver"; import { SemVer } from "semver";
import type { InitializableState } from "../initializable-state/create"; import type { InitializableState } from "../initializable-state/create";
import { createInitializableState } 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<InitializableState<string>>({ export const buildVersionInjectionToken = getInjectionToken<InitializableState<string>>({
id: "build-version-token", id: "build-version-token",

View File

@ -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 getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
import loggerInjectable from "../logger.injectable"; import loggerInjectable from "../logger.injectable";
import getBasenameOfPathInjectable from "../path/get-basename.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 storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
import { weblinkStoreMigrationInjectionToken } from "./migration-token"; import { weblinkStoreMigrationInjectionToken } from "./migration-token";
import { WeblinkStore } from "./weblink-store"; import { WeblinkStore } from "./weblink-store";

View File

@ -12,7 +12,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../../../common/base-
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../../common/base-store/disable-sync"; import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../../../common/base-store/disable-sync";
import { persistStateToConfigInjectionToken } from "../../../common/base-store/save-to-file"; import { persistStateToConfigInjectionToken } from "../../../common/base-store/save-to-file";
import getBasenameOfPathInjectable from "../../../common/path/get-basename.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 ensureHashedDirectoryForExtensionInjectable from "./ensure-hashed-directory-for-extension.injectable"; import ensureHashedDirectoryForExtensionInjectable from "./ensure-hashed-directory-for-extension.injectable";
import { registeredExtensionsInjectable } from "./registered-extensions.injectable"; import { registeredExtensionsInjectable } from "./registered-extensions.injectable";

View File

@ -20,7 +20,7 @@ import { baseStoreIpcChannelPrefixesInjectionToken } from "../common/base-store/
import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../common/base-store/disable-sync"; import { shouldBaseStoreDisableSyncInIpcListenerInjectionToken } from "../common/base-store/disable-sync";
import { persistStateToConfigInjectionToken } from "../common/base-store/save-to-file"; import { persistStateToConfigInjectionToken } from "../common/base-store/save-to-file";
import getBasenameOfPathInjectable from "../common/path/get-basename.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";
export interface ExtensionStoreParams<T extends object> extends BaseStoreParams<T> { export interface ExtensionStoreParams<T extends object> extends BaseStoreParams<T> {
migrations?: Migrations<T>; migrations?: Migrations<T>;

View File

@ -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 getConfigurationFileModelInjectable from "../../common/get-configuration-file-model/get-configuration-file-model.injectable";
import loggerInjectable from "../../common/logger.injectable"; import loggerInjectable from "../../common/logger.injectable";
import getBasenameOfPathInjectable from "../../common/path/get-basename.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 storeMigrationVersionInjectable from "../../common/vars/store-migration-version.injectable";
import { ExtensionsStore } from "./extensions-store"; import { ExtensionsStore } from "./extensions-store";

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { autorun } from "mobx"; import { autorun } from "mobx";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getStartableStoppable } from "@k8slens/startable-stoppable";
import populateApplicationMenuInjectable from "./populate-application-menu.injectable"; import populateApplicationMenuInjectable from "./populate-application-menu.injectable";
import applicationMenuItemCompositeInjectable from "./application-menu-item-composite.injectable"; import applicationMenuItemCompositeInjectable from "./application-menu-item-composite.injectable";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../../../common/utils/get-startable-stoppable"; import { getStartableStoppable } from "@k8slens/startable-stoppable";
import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable"; import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable";
import withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable"; import withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel } from "@k8slens/messaging";
export type RestartAndInstallUpdateChannel = MessageChannel<void>; export type RestartAndInstallUpdateChannel = MessageChannel<void>;

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { restartAndInstallUpdateChannel } from "../../common/restart-and-install-update-channel"; 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"; import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({ const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({
id: "restart", id: "restart",
channel: restartAndInstallUpdateChannel, channel: restartAndInstallUpdateChannel,
handler: (di) => di.inject(quitAndInstallUpdateInjectable), getHandler: (di) => di.inject(quitAndInstallUpdateInjectable),
}); });
export default restartAndInstallUpdateListenerInjectable; export default restartAndInstallUpdateListenerInjectable;

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { autorun } from "mobx"; import { autorun } from "mobx";
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable"; import { getStartableStoppable } from "@k8slens/startable-stoppable";
import setUpdateOnQuitInjectable from "../../../../main/electron-app/features/set-update-on-quit.injectable"; import setUpdateOnQuitInjectable from "../../../../main/electron-app/features/set-update-on-quit.injectable";
import selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable"; import selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable";
import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels"; import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels";

View File

@ -4,13 +4,13 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { restartAndInstallUpdateChannel } from "../common/restart-and-install-update-channel"; 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({ const restartAndInstallUpdateInjectable = getInjectable({
id: "restart-and-install-update", id: "restart-and-install-update",
instantiate: (di) => { instantiate: (di) => {
const messageToChannel = di.inject(messageToChannelInjectable); const messageToChannel = di.inject(sendMessageToChannelInjectionToken);
return () => { return () => {
messageToChannel(restartAndInstallUpdateChannel); messageToChannel(restartAndInstallUpdateChannel);

View File

@ -2,7 +2,6 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getRequestChannel } from "@k8slens/messaging";
import { getRequestChannel } from "../../../common/utils/channel/get-request-channel";
export const casChannel = getRequestChannel<void, string[]>("certificate-authorities"); export const casChannel = getRequestChannel<void, string[]>("certificate-authorities");

View File

@ -8,6 +8,7 @@ import { casChannel } from "../common/channel";
import certificateAuthoritiesChannelListenerInjectable from "./channel-handler.injectable"; import certificateAuthoritiesChannelListenerInjectable from "./channel-handler.injectable";
export default getGlobalOverride(certificateAuthoritiesChannelListenerInjectable, () => ({ export default getGlobalOverride(certificateAuthoritiesChannelListenerInjectable, () => ({
id: "certificate-authorities-channel-listener",
channel: casChannel, channel: casChannel,
handler: () => [], handler: () => [],
})); }));

View File

@ -2,14 +2,15 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getRequestChannelListenerInjectable } from "../../../main/utils/channel/channel-listeners/listener-tokens"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging";
import { casChannel } from "../common/channel"; import { casChannel } from "../common/channel";
import { globalAgent } from "https"; import { globalAgent } from "https";
import { isString } from "@k8slens/utilities"; import { isString } from "@k8slens/utilities";
const certificateAuthoritiesChannelListenerInjectable = getRequestChannelListenerInjectable({ const certificateAuthoritiesChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "certificate-authorities-channel-listener",
channel: casChannel, channel: casChannel,
handler: () => () => { getHandler: () => () => {
if (Array.isArray(globalAgent.options.ca)) { if (Array.isArray(globalAgent.options.ca)) {
return globalAgent.options.ca.filter(isString); return globalAgent.options.ca.filter(isString);
} }

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; 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 { casChannel } from "../common/channel";
import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token"; import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token";

View File

@ -4,7 +4,7 @@
*/ */
import type { ClusterId } from "../../../../common/cluster-types"; import type { ClusterId } from "../../../../common/cluster-types";
import { getRequestChannel } from "../../../../common/utils/channel/get-request-channel"; import { getRequestChannel } from "@k8slens/messaging";
export interface ActivateCluster { export interface ActivateCluster {
clusterId: ClusterId; clusterId: ClusterId;

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectionToken } from "@ogre-tools/injectable"; 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"; import type { activateClusterChannel, deactivateClusterChannel } from "./channels";
export type RequestClusterActivation = ChannelRequester<typeof activateClusterChannel>; export type RequestClusterActivation = ChannelRequester<typeof activateClusterChannel>;

View File

@ -2,13 +2,14 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging";
import { activateClusterChannel } from "../common/channels"; import { activateClusterChannel } from "../common/channels";
import requestClusterActivationInjectable from "./request-activation.injectable"; import requestClusterActivationInjectable from "./request-activation.injectable";
const activateClusterRequestChannelListenerInjectable = getRequestChannelListenerInjectable({ const activateClusterRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "activate-cluster-request-channel-listener",
channel: activateClusterChannel, channel: activateClusterChannel,
handler: (di) => di.inject(requestClusterActivationInjectable), getHandler: (di) => di.inject(requestClusterActivationInjectable),
}); });
export default activateClusterRequestChannelListenerInjectable; export default activateClusterRequestChannelListenerInjectable;

View File

@ -2,13 +2,14 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging";
import { deactivateClusterChannel } from "../common/channels"; import { deactivateClusterChannel } from "../common/channels";
import requestClusterDeactivationInjectable from "./request-deactivation.injectable"; import requestClusterDeactivationInjectable from "./request-deactivation.injectable";
const clusterDeactivationRequestChannelListenerInjectable = getRequestChannelListenerInjectable({ const clusterDeactivationRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "cluster-deactivation-request-channel-listener",
channel: deactivateClusterChannel, channel: deactivateClusterChannel,
handler: (di) => di.inject(requestClusterDeactivationInjectable), getHandler: (di) => di.inject(requestClusterDeactivationInjectable),
}); });
export default clusterDeactivationRequestChannelListenerInjectable; export default clusterDeactivationRequestChannelListenerInjectable;

View File

@ -3,14 +3,14 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; 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 { activateClusterChannel } from "../common/channels";
import { requestClusterActivationInjectionToken } from "../common/request-token"; import { requestClusterActivationInjectionToken } from "../common/request-token";
const requestClusterActivationInjectable = getInjectable({ const requestClusterActivationInjectable = getInjectable({
id: "request-cluster-activation", id: "request-cluster-activation",
instantiate: (di) => { instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectable); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
return (req) => requestFromChannel(activateClusterChannel, req); return (req) => requestFromChannel(activateClusterChannel, req);
}, },

View File

@ -3,14 +3,14 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; 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 { deactivateClusterChannel } from "../common/channels";
import { requestClusterDeactivationInjectionToken } from "../common/request-token"; import { requestClusterDeactivationInjectionToken } from "../common/request-token";
const requestClusterDeactivationInjectable = getInjectable({ const requestClusterDeactivationInjectable = getInjectable({
id: "request-cluster-deactivation", id: "request-cluster-deactivation",
instantiate: (di) => { instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectable); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
return (clusterId) => requestFromChannel(deactivateClusterChannel, clusterId); return (clusterId) => requestFromChannel(deactivateClusterChannel, clusterId);
}, },

View File

@ -3,10 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { ClusterId } from "../../../../common/cluster-types"; 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<ClusterId, void>; export const clearClusterAsDeletingChannel = getRequestChannel<ClusterId, void>(
"clear-cluster-as-deleting",
export const clearClusterAsDeletingChannel: ClearClusterAsDeletingChannel = { );
id: "clear-cluster-as-deleting",
};

View File

@ -3,10 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { ClusterId } from "../../../../common/cluster-types"; import type { ClusterId } from "../../../../common/cluster-types";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "@k8slens/messaging";
import { getRequestChannel } from "@k8slens/messaging";
export type DeleteClusterChannel = RequestChannel<ClusterId, void>; export type DeleteClusterChannel = RequestChannel<ClusterId, void>;
export const deleteClusterChannel: DeleteClusterChannel = { export const deleteClusterChannel = getRequestChannel<ClusterId, void>(
id: "delete-cluster", "delete-cluster",
}; );

View File

@ -3,10 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { ClusterId } from "../../../../common/cluster-types"; 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<ClusterId, void>; export const setClusterAsDeletingChannel = getRequestChannel<ClusterId, void>(
"set-cluster-as-deleting",
export const setClusterAsDeletingChannel: SetClusterAsDeletingChannel = { );
id: "set-cluster-as-deleting",
};

View File

@ -3,12 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable"; 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"; import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel";
const clearClusterAsDeletingChannelListenerInjectable = getRequestChannelListenerInjectable({ const clearClusterAsDeletingChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "clear-cluster-as-deleting-channel-listener",
channel: clearClusterAsDeletingChannel, channel: clearClusterAsDeletingChannel,
handler: (di) => { getHandler: (di) => {
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable); const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
return (clusterId) => { return (clusterId) => {

View File

@ -10,12 +10,13 @@ import removePathInjectable from "../../../../common/fs/remove.injectable";
import joinPathsInjectable from "../../../../common/path/join-paths.injectable"; import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable"; import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable";
import { noop } from "@k8slens/utilities"; 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"; import { deleteClusterChannel } from "../common/delete-channel";
const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectable({ const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "delete-cluster-channel-listener",
channel: deleteClusterChannel, channel: deleteClusterChannel,
handler: (di) => { getHandler: (di) => {
const emitAppEvent = di.inject(emitAppEventInjectable); const emitAppEvent = di.inject(emitAppEventInjectable);
const clusterStore = di.inject(clusterStoreInjectable); const clusterStore = di.inject(clusterStoreInjectable);
const clusterFrames = di.inject(clusterFramesInjectable); const clusterFrames = di.inject(clusterFramesInjectable);

View File

@ -3,12 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable"; 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"; import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel";
const setClusterAsDeletingChannelHandlerInjectable = getRequestChannelListenerInjectable({ const setClusterAsDeletingChannelHandlerInjectable = getRequestChannelListenerInjectable({
id: "set-cluster-as-deleting-channel-handler",
channel: setClusterAsDeletingChannel, channel: setClusterAsDeletingChannel,
handler: (di) => { getHandler: (di) => {
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable); const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
return (clusterId) => { return (clusterId) => {

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../../../../common/cluster-types"; 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"; import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel";
export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise<void>; export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise<void>;
@ -12,7 +12,7 @@ export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise<vo
const requestClearClusterAsDeletingInjectable = getInjectable({ const requestClearClusterAsDeletingInjectable = getInjectable({
id: "request-clear-cluster-as-deleting", id: "request-clear-cluster-as-deleting",
instantiate: (di): RequestClearClusterAsDeleting => { instantiate: (di): RequestClearClusterAsDeleting => {
const requestChannel = di.inject(requestFromChannelInjectable); const requestChannel = di.inject(requestFromChannelInjectionToken);
return (clusterId) => requestChannel(clearClusterAsDeletingChannel, clusterId); return (clusterId) => requestChannel(clearClusterAsDeletingChannel, clusterId);
}, },

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../../../../common/cluster-types"; 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"; import { deleteClusterChannel } from "../common/delete-channel";
export type RequestDeleteCluster = (clusterId: ClusterId) => Promise<void>; export type RequestDeleteCluster = (clusterId: ClusterId) => Promise<void>;
@ -12,7 +12,7 @@ export type RequestDeleteCluster = (clusterId: ClusterId) => Promise<void>;
const requestDeleteClusterInjectable = getInjectable({ const requestDeleteClusterInjectable = getInjectable({
id: "request-delete-cluster", id: "request-delete-cluster",
instantiate: (di): RequestDeleteCluster => { instantiate: (di): RequestDeleteCluster => {
const requestChannel = di.inject(requestFromChannelInjectable); const requestChannel = di.inject(requestFromChannelInjectionToken);
return (clusterId) => requestChannel(deleteClusterChannel, clusterId); return (clusterId) => requestChannel(deleteClusterChannel, clusterId);
}, },

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../../../../common/cluster-types"; 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"; import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel";
export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise<void>; export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise<void>;
@ -12,7 +12,7 @@ export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise<void
const requestSetClusterAsDeletingInjectable = getInjectable({ const requestSetClusterAsDeletingInjectable = getInjectable({
id: "request-set-cluster-as-deleting", id: "request-set-cluster-as-deleting",
instantiate: (di): RequestSetClusterAsDeleting => { instantiate: (di): RequestSetClusterAsDeleting => {
const requestChannel = di.inject(requestFromChannelInjectable); const requestChannel = di.inject(requestFromChannelInjectionToken);
return (clusterId) => requestChannel(setClusterAsDeletingChannel, clusterId); return (clusterId) => requestChannel(setClusterAsDeletingChannel, clusterId);
}, },

View File

@ -4,8 +4,7 @@
*/ */
import type { ClusterId, ClusterState } from "../../../../common/cluster-types"; import type { ClusterId, ClusterState } from "../../../../common/cluster-types";
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel, RequestChannel } from "@k8slens/messaging";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
export interface ClusterStateSync { export interface ClusterStateSync {
clusterId: ClusterId; clusterId: ClusterId;

View File

@ -3,18 +3,16 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token"; import type { ClusterStateSync } from "../common/channels";
import { clusterStateSyncChannel } from "../common/channels"; import { clusterStateSyncChannel } from "../common/channels";
export type EmitClusterStateUpdate = MessageChannelHandler<typeof clusterStateSyncChannel>;
const emitClusterStateUpdateInjectable = getInjectable({ const emitClusterStateUpdateInjectable = getInjectable({
id: "emit-cluster-state-update", id: "emit-cluster-state-update",
instantiate: (di): EmitClusterStateUpdate => { instantiate: (di) => {
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
return (message) => sendMessageToChannel(clusterStateSyncChannel, message); return (message: ClusterStateSync) => sendMessageToChannel(clusterStateSyncChannel, message);
}, },
}); });

View File

@ -3,12 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; 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"; import { initialClusterStatesChannel } from "../common/channels";
const handleInitialClusterStateSyncInjectable = getRequestChannelListenerInjectable({ const handleInitialClusterStateSyncInjectable = getRequestChannelListenerInjectable({
id: "handle-initial-cluster-state-sync",
channel: initialClusterStatesChannel, channel: initialClusterStatesChannel,
handler: (di) => { getHandler: (di) => {
const clusterStore = di.inject(clusterStoreInjectable); const clusterStore = di.inject(clusterStoreInjectable);
return () => clusterStore.clustersList.map(cluster => ({ return () => clusterStore.clustersList.map(cluster => ({

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; 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"; import { clusterStateSyncChannel } from "../common/channels";
const clusterStateListenerInjectable = getMessageChannelListenerInjectable({ const clusterStateListenerInjectable = getMessageChannelListenerInjectable({
channel: clusterStateSyncChannel, channel: clusterStateSyncChannel,
id: "main", id: "main",
handler: (di) => { getHandler: (di) => {
const getClusterById = di.inject(getClusterByIdInjectable); const getClusterById = di.inject(getClusterByIdInjectable);
return ({ clusterId, state }) => getClusterById(clusterId)?.setState(state); return ({ clusterId, state }) => getClusterById(clusterId)?.setState(state);

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { RequestChannelHandler } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; import type { RequestChannelHandler } from "@k8slens/messaging";
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; import { requestFromChannelInjectionToken } from "@k8slens/messaging";
import { initialClusterStatesChannel } from "../common/channels"; import { initialClusterStatesChannel } from "../common/channels";
export type RequestInitialClusterStates = RequestChannelHandler<typeof initialClusterStatesChannel>; export type RequestInitialClusterStates = RequestChannelHandler<typeof initialClusterStatesChannel>;
@ -12,7 +12,7 @@ export type RequestInitialClusterStates = RequestChannelHandler<typeof initialCl
const requestInitialClusterStatesInjectable = getInjectable({ const requestInitialClusterStatesInjectable = getInjectable({
id: "request-initial-cluster-states", id: "request-initial-cluster-states",
instantiate: (di): RequestInitialClusterStates => { instantiate: (di): RequestInitialClusterStates => {
const requestFromChannel = di.inject(requestFromChannelInjectable); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
return () => requestFromChannel(initialClusterStatesChannel); return () => requestFromChannel(initialClusterStatesChannel);
}, },

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel } from "@k8slens/messaging";
export interface NavigateForExtensionArgs { export interface NavigateForExtensionArgs {
extId: string; extId: string;

View File

@ -2,15 +2,15 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { 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 extensionLoaderInjectable from "../../../../extensions/extension-loader/extension-loader.injectable";
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension"; import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
import { navigateForExtensionChannel } from "../common/channel"; import { navigateForExtensionChannel } from "../common/channel";
const navigateForExtensionListenerInjectable = getMessageChannelListenerInjectable({ const navigateForExtensionListenerInjectable = getMessageChannelListenerInjectable({
channel: navigateForExtensionChannel, channel: navigateForExtensionChannel,
id: "main", id: "renderer",
handler: (di) => { getHandler: (di) => {
const extensionLoader = di.inject(extensionLoaderInjectable); const extensionLoader = di.inject(extensionLoaderInjectable);
return ({ extId, pageId, params }) => { return ({ extId, pageId, params }) => {

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { asyncComputed } from "@ogre-tools/injectable-react"; import { asyncComputed } from "@ogre-tools/injectable-react";
import { getActiveHelmRepositoriesChannel } from "../../../../../common/helm/get-active-helm-repositories-channel"; 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 showErrorNotificationInjectable from "../../../../../renderer/components/notifications/show-error-notification.injectable";
import helmRepositoriesErrorStateInjectable from "./helm-repositories-error-state.injectable"; import helmRepositoriesErrorStateInjectable from "./helm-repositories-error-state.injectable";
import { runInAction } from "mobx"; import { runInAction } from "mobx";

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { HelmRepo } from "../../../../../../../common/helm/helm-repo"; 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 activeHelmRepositoriesInjectable from "../../active-helm-repositories.injectable";
import showErrorNotificationInjectable from "../../../../../../../renderer/components/notifications/show-error-notification.injectable"; import showErrorNotificationInjectable from "../../../../../../../renderer/components/notifications/show-error-notification.injectable";
import showSuccessNotificationInjectable from "../../../../../../../renderer/components/notifications/show-success-notification.injectable"; import showSuccessNotificationInjectable from "../../../../../../../renderer/components/notifications/show-success-notification.injectable";

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { HelmRepo } from "../../../../../common/helm/helm-repo"; 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 activeHelmRepositoriesInjectable from "./active-helm-repositories.injectable";
import { removeHelmRepositoryChannel } from "../../../../../common/helm/remove-helm-repository-channel"; import { removeHelmRepositoryChannel } from "../../../../../common/helm/remove-helm-repository-channel";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel } from "@k8slens/messaging";
export type ReloadPageChannel = MessageChannel<void>; export type ReloadPageChannel = MessageChannel<void>;

View File

@ -8,6 +8,7 @@ import { reloadPageChannel } from "../common/channel";
import reloadPageChannelListenerInjectable from "./register-listener.injectable"; import reloadPageChannelListenerInjectable from "./register-listener.injectable";
export default getGlobalOverride(reloadPageChannelListenerInjectable, () => ({ export default getGlobalOverride(reloadPageChannelListenerInjectable, () => ({
id: "reload-page-channel-listener",
channel: reloadPageChannel, channel: reloadPageChannel,
handler: () => {}, handler: () => {},
})); }));

View File

@ -2,13 +2,13 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
import { reloadPageChannel } from "../common/channel"; import { reloadPageChannel } from "../common/channel";
const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({ const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "handler", id: "handler",
channel: reloadPageChannel, channel: reloadPageChannel,
handler: () => () => location.reload(), getHandler: () => () => location.reload(),
causesSideEffects: true, causesSideEffects: true,
}); });

View File

@ -4,7 +4,7 @@
*/ */
import type { OpenDialogOptions } from "electron"; 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 = { export type PathPickingResponse = {
canceled: true; canceled: true;

View File

@ -4,12 +4,13 @@
*/ */
import askUserForFilePathsInjectable from "../../../main/ipc/ask-user-for-file-paths.injectable"; 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"; import { openPathPickingDialogChannel } from "../common/channel";
const openPathPickingDialogListener = getRequestChannelListenerInjectable({ const openPathPickingDialogListener = getRequestChannelListenerInjectable({
id: "open-path-picking-dialog",
channel: openPathPickingDialogChannel, channel: openPathPickingDialogChannel,
handler: (di) => di.inject(askUserForFilePathsInjectable), getHandler: (di) => di.inject(askUserForFilePathsInjectable),
}); });
export default openPathPickingDialogListener; export default openPathPickingDialogListener;

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { PathPickOpts } from "../../../renderer/components/path-picker"; 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"; import { openPathPickingDialogChannel } from "../common/channel";
export type OpenPathPickingDialog = (options: PathPickOpts) => Promise<void>; export type OpenPathPickingDialog = (options: PathPickOpts) => Promise<void>;
@ -12,7 +12,7 @@ export type OpenPathPickingDialog = (options: PathPickOpts) => Promise<void>;
const openPathPickingDialogInjectable = getInjectable({ const openPathPickingDialogInjectable = getInjectable({
id: "open-path-picking-dialog", id: "open-path-picking-dialog",
instantiate: (di): OpenPathPickingDialog => { instantiate: (di): OpenPathPickingDialog => {
const requestFromChannel = di.inject(requestFromChannelInjectable); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
return async (options) => { return async (options) => {
const { onPick, onCancel, ...dialogOptions } = options; const { onPick, onCancel, ...dialogOptions } = options;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel } from "@k8slens/messaging";
export const shellSyncFailedChannel: MessageChannel<string> = { export const shellSyncFailedChannel: MessageChannel<string> = {
id: "shell-sync-failed-channel", id: "shell-sync-failed-channel",

View File

@ -3,16 +3,15 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { MessageChannelSender } from "../../../common/utils/channel/message-to-channel-injection-token"; import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
import { shellSyncFailedChannel } from "../common/failure-channel"; import { shellSyncFailedChannel } from "../common/failure-channel";
const emitShellSyncFailedInjectable = getInjectable({ const emitShellSyncFailedInjectable = getInjectable({
id: "emit-shell-sync-failed", id: "emit-shell-sync-failed",
instantiate: (di): MessageChannelSender<typeof shellSyncFailedChannel> => { instantiate: (di) => {
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
return (error) => sendMessageToChannel(shellSyncFailedChannel, error); return (error: string) => sendMessageToChannel(shellSyncFailedChannel, error);
}, },
}); });

View File

@ -2,14 +2,14 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { 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 showErrorNotificationInjectable from "../../../renderer/components/notifications/show-error-notification.injectable";
import { shellSyncFailedChannel } from "../common/failure-channel"; import { shellSyncFailedChannel } from "../common/failure-channel";
const shellSyncFailureListenerInjectable = getMessageChannelListenerInjectable({ const shellSyncFailureListenerInjectable = getMessageChannelListenerInjectable({
id: "notification", id: "notification",
channel: shellSyncFailedChannel, channel: shellSyncFailedChannel,
handler: (di) => { getHandler: (di) => {
const showErrorNotification = di.inject(showErrorNotificationInjectable); const showErrorNotification = di.inject(showErrorNotificationInjectable);
return (errorMessage) => showErrorNotification(`Failed to sync shell environment: ${errorMessage}`); return (errorMessage) => showErrorNotification(`Failed to sync shell environment: ${errorMessage}`);

View File

@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel, RequestChannel } from "@k8slens/messaging";
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
export type SystemThemeType = "dark" | "light"; export type SystemThemeType = "dark" | "light";

View File

@ -3,18 +3,16 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token"; import type { SystemThemeType } from "../common/channels";
import { systemThemeTypeUpdateChannel } from "../common/channels"; import { systemThemeTypeUpdateChannel } from "../common/channels";
export type EmitSystemThemeTypeUpdate = MessageChannelHandler<typeof systemThemeTypeUpdateChannel>;
const emitSystemThemeTypeUpdateInjectable = getInjectable({ const emitSystemThemeTypeUpdateInjectable = getInjectable({
id: "emit-system-theme-type-update", id: "emit-system-theme-type-update",
instantiate: (di): EmitSystemThemeTypeUpdate => { instantiate: (di) => {
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken); const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
return (type) => sendMessageToChannel(systemThemeTypeUpdateChannel, type); return (type: SystemThemeType) => sendMessageToChannel(systemThemeTypeUpdateChannel, type);
}, },
}); });

View File

@ -4,12 +4,13 @@
*/ */
import operatingSystemThemeInjectable from "../../../../main/theme/operating-system-theme.injectable"; 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"; import { initialSystemThemeTypeChannel } from "../common/channels";
const initialSystemThemeTypeHandler = getRequestChannelListenerInjectable({ const initialSystemThemeTypeHandler = getRequestChannelListenerInjectable({
id: "initial-system-theme-type-listener",
channel: initialSystemThemeTypeChannel, channel: initialSystemThemeTypeChannel,
handler: (di) => { getHandler: (di) => {
const operatingSystemTheme = di.inject(operatingSystemThemeInjectable); const operatingSystemTheme = di.inject(operatingSystemThemeInjectable);
return () => operatingSystemTheme.get(); return () => operatingSystemTheme.get();

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { RequestChannelHandler } from "../../../../main/utils/channel/channel-listeners/listener-tokens"; import type { RequestChannelHandler } from "@k8slens/messaging";
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable"; import { requestFromChannelInjectionToken } from "@k8slens/messaging";
import { initialSystemThemeTypeChannel } from "../common/channels"; import { initialSystemThemeTypeChannel } from "../common/channels";
export type RequestInitialSystemThemeType = RequestChannelHandler<typeof initialSystemThemeTypeChannel>; export type RequestInitialSystemThemeType = RequestChannelHandler<typeof initialSystemThemeTypeChannel>;
@ -12,7 +12,7 @@ export type RequestInitialSystemThemeType = RequestChannelHandler<typeof initial
const requestInitialSystemThemeTypeInjectable = getInjectable({ const requestInitialSystemThemeTypeInjectable = getInjectable({
id: "request-initial-system-theme-type", id: "request-initial-system-theme-type",
instantiate: (di): RequestInitialSystemThemeType => { instantiate: (di): RequestInitialSystemThemeType => {
const requestFromChannel = di.inject(requestFromChannelInjectable); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
return () => requestFromChannel(initialSystemThemeTypeChannel); return () => requestFromChannel(initialSystemThemeTypeChannel);
}, },

View File

@ -2,14 +2,14 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
import systemThemeConfigurationInjectable from "../../../../renderer/themes/system-theme.injectable"; import systemThemeConfigurationInjectable from "../../../../renderer/themes/system-theme.injectable";
import { systemThemeTypeUpdateChannel } from "../common/channels"; import { systemThemeTypeUpdateChannel } from "../common/channels";
const systemThemeTypeUpdateListenerInjectable = getMessageChannelListenerInjectable({ const systemThemeTypeUpdateListenerInjectable = getMessageChannelListenerInjectable({
channel: systemThemeTypeUpdateChannel, channel: systemThemeTypeUpdateChannel,
id: "main", id: "main",
handler: (di) => { getHandler: (di) => {
const systemThemeConfiguration = di.inject(systemThemeConfigurationInjectable); const systemThemeConfiguration = di.inject(systemThemeConfigurationInjectable);
return (type) => systemThemeConfiguration.set(type); return (type) => systemThemeConfiguration.set(type);

View File

@ -4,3 +4,8 @@
*/ */
import "@testing-library/jest-dom"; import "@testing-library/jest-dom";
// Note: This is a kludge to prevent "Hooks cannot be defined inside tests" error
// when importing a test util inside a test suite.
import { render } from "@testing-library/react";
void render;

View File

@ -4,11 +4,12 @@
*/ */
import { appPathsChannel } from "../../common/app-paths/app-paths-channel"; import { appPathsChannel } from "../../common/app-paths/app-paths-channel";
import appPathsInjectable from "../../common/app-paths/app-paths.injectable"; 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({ const appPathsRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "app-paths-request-channel-listener",
channel: appPathsChannel, channel: appPathsChannel,
handler: (di) => { getHandler: (di) => {
const appPaths = di.inject(appPathsInjectable); const appPaths = di.inject(appPathsInjectable);
return () => appPaths; return () => appPaths;

View File

@ -3,12 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { buildVersionChannel } from "../../common/vars/build-semantic-version.injectable"; 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"; import buildVersionInjectable from "../vars/build-version/build-version.injectable";
const buildVersionChannelListenerInjectable = getRequestChannelListenerInjectable({ const buildVersionChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "build-version-channel-listener",
channel: buildVersionChannel, channel: buildVersionChannel,
handler: (di) => { getHandler: (di) => {
const buildVersion = di.inject(buildVersionInjectable); const buildVersion = di.inject(buildVersionInjectable);
return () => buildVersion.get(); return () => buildVersion.get();

View File

@ -7,7 +7,7 @@ import { reaction } from "mobx";
import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token"; import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token";
import { catalogInitChannel } from "../../common/ipc/catalog"; import { catalogInitChannel } from "../../common/ipc/catalog";
import { disposer } from "@k8slens/utilities"; import { disposer } from "@k8slens/utilities";
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable"; import { getStartableStoppable } from "@k8slens/startable-stoppable";
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable"; import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable"; import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
import { toJS } from "../../common/utils"; import { toJS } from "../../common/utils";

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { clusterVisibilityChannel } from "../../common/cluster/visibility-channel"; 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"; import visibleClusterInjectable from "./visible-cluster.injectable";
const clusterVisibilityHandlerInjectable = getMessageChannelListenerInjectable({ const clusterVisibilityHandlerInjectable = getMessageChannelListenerInjectable({
channel: clusterVisibilityChannel, channel: clusterVisibilityChannel,
id: "base", id: "base",
handler: (di) => { getHandler: (di) => {
const visibleCluster = di.inject(visibleClusterInjectable); const visibleCluster = di.inject(visibleClusterInjectable);
return (clusterId) => visibleCluster.set(clusterId); return (clusterId) => visibleCluster.set(clusterId);

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getStartableStoppable } from "@k8slens/startable-stoppable";
import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable"; import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable";
import nativeThemeInjectable from "./native-theme.injectable"; import nativeThemeInjectable from "./native-theme.injectable";
import getElectronThemeInjectable from "./get-electron-theme.injectable"; import getElectronThemeInjectable from "./get-electron-theme.injectable";

View File

@ -29,6 +29,8 @@ import {
setLegacyGlobalDiForExtensionApi, setLegacyGlobalDiForExtensionApi,
} from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; 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() { export function getDiForUnitTesting() {
const di = createContainer("main"); const di = createContainer("main");
@ -36,6 +38,11 @@ export function getDiForUnitTesting() {
registerMobX(di); registerMobX(di);
setLegacyGlobalDiForExtensionApi(di, "main"); setLegacyGlobalDiForExtensionApi(di, "main");
runInAction(() => {
registerFeature(di, messagingFeature, messagingTestUtils.messagingFeatureForUnitTesting);
});
di.preventSideEffects(); di.preventSideEffects();
runInAction(() => { runInAction(() => {

View File

@ -3,12 +3,14 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { addHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel"; 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"; import addHelmRepositoryInjectable from "./add-helm-repository.injectable";
const addHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({ const addHelmRepositoryChannelListenerInjectable =
channel: addHelmRepositoryChannel, getRequestChannelListenerInjectable({
handler: (di) => di.inject(addHelmRepositoryInjectable), id: "add-helm-repository-channel-listener",
}); channel: addHelmRepositoryChannel,
getHandler: (di) => di.inject(addHelmRepositoryInjectable),
});
export default addHelmRepositoryChannelListenerInjectable; export default addHelmRepositoryChannelListenerInjectable;

View File

@ -5,17 +5,16 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import execHelmInjectable from "../../exec-helm/exec-helm.injectable"; import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
import loggerInjectable from "../../../../common/logger.injectable"; import loggerInjectable from "../../../../common/logger.injectable";
import type { AddHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel"; import type { HelmRepo } from "../../../../common/helm/helm-repo";
import type { RequestChannelHandler } from "../../../utils/channel/channel-listeners/listener-tokens";
const addHelmRepositoryInjectable = getInjectable({ const addHelmRepositoryInjectable = getInjectable({
id: "add-helm-repository", id: "add-helm-repository",
instantiate: (di): RequestChannelHandler<AddHelmRepositoryChannel> => { instantiate: (di) => {
const execHelm = di.inject(execHelmInjectable); const execHelm = di.inject(execHelmInjectable);
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
return async (repo) => { return async (repo: HelmRepo) => {
const { const {
name, name,
url, url,
@ -59,12 +58,12 @@ const addHelmRepositoryInjectable = getInjectable({
if (result.callWasSuccessful) { if (result.callWasSuccessful) {
return { return {
callWasSuccessful: true, callWasSuccessful: true as const,
}; };
} }
return { return {
callWasSuccessful: false, callWasSuccessful: false as const,
error: result.error.stderr || result.error.message, error: result.error.stderr || result.error.message,
}; };
}; };

View File

@ -3,12 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getActiveHelmRepositoriesChannel } from "../../../../common/helm/get-active-helm-repositories-channel"; 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"; import getActiveHelmRepositoriesInjectable from "./get-active-helm-repositories.injectable";
const getActiveHelmRepositoriesChannelListenerInjectable = getRequestChannelListenerInjectable({ const getActiveHelmRepositoriesChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "get-active-helm-repositories-channel-listener",
channel: getActiveHelmRepositoriesChannel, channel: getActiveHelmRepositoriesChannel,
handler: (di) => di.inject(getActiveHelmRepositoriesInjectable), getHandler: (di) => di.inject(getActiveHelmRepositoriesInjectable),
}); });
export default getActiveHelmRepositoriesChannelListenerInjectable; export default getActiveHelmRepositoriesChannelListenerInjectable;

View File

@ -4,11 +4,12 @@
*/ */
import removeHelmRepositoryInjectable from "./remove-helm-repository.injectable"; import removeHelmRepositoryInjectable from "./remove-helm-repository.injectable";
import { removeHelmRepositoryChannel } from "../../../../common/helm/remove-helm-repository-channel"; 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({ const removeHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({
id: "remove-helm-repository-channel-listener",
channel: removeHelmRepositoryChannel, channel: removeHelmRepositoryChannel,
handler: (di) => di.inject(removeHelmRepositoryInjectable), getHandler: (di) => di.inject(removeHelmRepositoryInjectable),
}); });
export default removeHelmRepositoryChannelListenerInjectable; export default removeHelmRepositoryChannelListenerInjectable;

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.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 type { openPathPickingDialogChannel } from "../../features/path-picking-dialog/common/channel";
import showOpenDialogInjectable from "../electron-app/features/show-open-dialog.injectable"; import showOpenDialogInjectable from "../electron-app/features/show-open-dialog.injectable";

View File

@ -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 getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable";
import { kubectlApplyAllChannel } from "../../common/kube-helpers/channels"; import { kubectlApplyAllChannel } from "../../common/kube-helpers/channels";
import resourceApplierInjectable from "../resource-applier/create-resource-applier.injectable"; 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({ const kubectlApplyAllChannelHandlerInjectable = getRequestChannelListenerInjectable({
id: "kubectl-apply-all-channel-handler-listener",
channel: kubectlApplyAllChannel, channel: kubectlApplyAllChannel,
handler: (di) => { getHandler: (di) => {
const getClusterById = di.inject(getClusterByIdInjectable); const getClusterById = di.inject(getClusterByIdInjectable);
const emitAppEvent = di.inject(emitAppEventInjectable); const emitAppEvent = di.inject(emitAppEventInjectable);

View File

@ -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 getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable";
import { kubectlDeleteAllChannel } from "../../common/kube-helpers/channels"; import { kubectlDeleteAllChannel } from "../../common/kube-helpers/channels";
import resourceApplierInjectable from "../resource-applier/create-resource-applier.injectable"; 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({ const kubectlDeleteAllChannelHandlerInjectable = getRequestChannelListenerInjectable({
id: "kubectl-delete-all-channel-handler-listener",
channel: kubectlDeleteAllChannel, channel: kubectlDeleteAllChannel,
handler: (di) => { getHandler: (di) => {
const emitAppEvent = di.inject(emitAppEventInjectable); const emitAppEvent = di.inject(emitAppEventInjectable);
const getClusterById = di.inject(getClusterByIdInjectable); const getClusterById = di.inject(getClusterByIdInjectable);

View File

@ -3,12 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { lensProxyCertificateChannel } from "../../common/certificate/lens-proxy-certificate-channel"; 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"; import lensProxyCertificateInjectable from "../../common/certificate/lens-proxy-certificate.injectable";
const lensProxyCertificateRequestHandlerInjectable = getRequestChannelListenerInjectable({ const lensProxyCertificateRequestHandlerInjectable = getRequestChannelListenerInjectable({
id: "lens-proxy-certificate-request-handler-listener",
channel: lensProxyCertificateChannel, channel: lensProxyCertificateChannel,
handler: (di) => { getHandler: (di) => {
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable).get(); const lensProxyCertificate = di.inject(lensProxyCertificateInjectable).get();
return () => ({ return () => ({

View File

@ -3,17 +3,17 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { currentClusterMessageChannel } from "../../../../common/cluster/current-cluster-channel"; 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"; import currentClusterFrameClusterIdStateInjectable from "./current-cluster-frame-cluster-id-state.injectable";
const currentVisibileClusterListenerInjectable = getMessageChannelListenerInjectable({ const currentVisibleClusterListenerInjectable = getMessageChannelListenerInjectable({
id: "current-visibile-cluster", id: "current-visible-cluster",
channel: currentClusterMessageChannel, channel: currentClusterMessageChannel,
handler: (di) => { getHandler: (di) => {
const currentClusterFrameState = di.inject(currentClusterFrameClusterIdStateInjectable); const currentClusterFrameState = di.inject(currentClusterFrameClusterIdStateInjectable);
return clusterId => currentClusterFrameState.set(clusterId); return clusterId => currentClusterFrameState.set(clusterId);
}, },
}); });
export default currentVisibileClusterListenerInjectable; export default currentVisibleClusterListenerInjectable;

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { 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 { rootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel";
import { runManyFor } from "@k8slens/run-many"; import { runManyFor } from "@k8slens/run-many";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phases"; import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phases";
@ -10,7 +10,7 @@ import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/phase
const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({ const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "action", id: "action",
channel: rootFrameHasRenderedChannel, channel: rootFrameHasRenderedChannel,
handler: (di) => { getHandler: (di) => {
const runMany = runManyFor(di); const runMany = runManyFor(di);
return runMany(afterRootFrameIsReadyInjectionToken); return runMany(afterRootFrameIsReadyInjectionToken);

Some files were not shown because too many files have changed in this diff Show More