mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into enhancement-data-origin-to-status-bar-items
This commit is contained in:
commit
cb1fe51b40
10
package.json
10
package.json
@ -301,7 +301,7 @@
|
||||
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.8",
|
||||
"@sentry/types": "^6.19.7",
|
||||
"@swc/cli": "^0.1.57",
|
||||
"@swc/core": "^1.3.6",
|
||||
"@swc/core": "^1.3.7",
|
||||
"@swc/jest": "^0.2.23",
|
||||
"@testing-library/dom": "^7.31.2",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
@ -374,7 +374,7 @@
|
||||
"css-loader": "^6.7.1",
|
||||
"deepdash": "^5.3.9",
|
||||
"dompurify": "^2.4.0",
|
||||
"electron": "^19.1.2",
|
||||
"electron": "^19.1.3",
|
||||
"electron-builder": "^23.6.0",
|
||||
"electron-notarize": "^0.3.0",
|
||||
"esbuild": "^0.15.10",
|
||||
@ -402,8 +402,8 @@
|
||||
"node-gyp": "^8.3.0",
|
||||
"node-loader": "^2.0.0",
|
||||
"nodemon": "^2.0.20",
|
||||
"playwright": "^1.27.0",
|
||||
"postcss": "^8.4.17",
|
||||
"playwright": "^1.27.1",
|
||||
"postcss": "^8.4.18",
|
||||
"postcss-loader": "^6.2.1",
|
||||
"query-string": "^7.1.1",
|
||||
"randomcolor": "^0.6.2",
|
||||
@ -411,7 +411,7 @@
|
||||
"react-refresh": "^0.14.0",
|
||||
"react-refresh-typescript": "^2.0.7",
|
||||
"react-router-dom": "^5.3.4",
|
||||
"react-select": "^5.4.0",
|
||||
"react-select": "^5.5.0",
|
||||
"react-select-event": "^5.5.1",
|
||||
"react-table": "^7.8.0",
|
||||
"react-window": "^1.8.7",
|
||||
|
||||
@ -1,22 +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 { AppPaths } from "./app-path-injection-token";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||
import { messageChannelInjectionToken } from "../utils/channel/message-channel-injection-token";
|
||||
|
||||
export type AppPathsChannel = RequestChannel<void, AppPaths>;
|
||||
|
||||
const appPathsChannelInjectable = getInjectable({
|
||||
id: "app-paths-channel",
|
||||
|
||||
instantiate: (): AppPathsChannel => ({
|
||||
id: "app-paths",
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default appPathsChannelInjectable;
|
||||
13
src/common/app-paths/app-paths-channel.ts
Normal file
13
src/common/app-paths/app-paths-channel.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { AppPaths } from "./app-path-injection-token";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type AppPathsChannel = RequestChannel<void, AppPaths>;
|
||||
|
||||
export const appPathsChannel: AppPathsChannel = {
|
||||
id: "app-paths",
|
||||
};
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
export type RestartAndInstallUpdateChannel = MessageChannel<void>;
|
||||
|
||||
export const restartAndInstallUpdateChannel: RestartAndInstallUpdateChannel = {
|
||||
id: "restart-and-install-update-channel",
|
||||
};
|
||||
@ -1,21 +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 { MessageChannel } from "../../utils/channel/message-channel-injection-token";
|
||||
import { messageChannelInjectionToken } from "../../utils/channel/message-channel-injection-token";
|
||||
|
||||
export type RestartAndInstallUpdateChannel = MessageChannel;
|
||||
|
||||
const restartAndInstallUpdateChannel = getInjectable({
|
||||
id: "restart-and-install-update-channel",
|
||||
|
||||
instantiate: (): RestartAndInstallUpdateChannel => ({
|
||||
id: "restart-and-install-update-channel",
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default restartAndInstallUpdateChannel;
|
||||
@ -19,7 +19,7 @@ const selectedUpdateChannelInjectable = getInjectable({
|
||||
|
||||
instantiate: (di): SelectedUpdateChannel => {
|
||||
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
|
||||
const state = observable.box<UpdateChannel>();
|
||||
const state = observable.box<UpdateChannel>(undefined, { deep: false });
|
||||
|
||||
return {
|
||||
value: computed(() => state.get() ?? defaultUpdateChannel.get()),
|
||||
|
||||
@ -1,22 +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 { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
|
||||
import type { MessageChannel } from "../utils/channel/message-channel-injection-token";
|
||||
import { messageChannelInjectionToken } from "../utils/channel/message-channel-injection-token";
|
||||
|
||||
export type AppNavigationChannel = MessageChannel<string>;
|
||||
|
||||
const appNavigationChannelInjectable = getInjectable({
|
||||
id: "app-navigation-channel",
|
||||
|
||||
instantiate: (): AppNavigationChannel => ({
|
||||
id: IpcRendererNavigationEvents.NAVIGATE_IN_APP,
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default appNavigationChannelInjectable;
|
||||
12
src/common/front-end-routing/app-navigation-channel.ts
Normal file
12
src/common/front-end-routing/app-navigation-channel.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
|
||||
import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
export type AppNavigationChannel = MessageChannel<string>;
|
||||
|
||||
export const appNavigationChannel: AppNavigationChannel = {
|
||||
id: IpcRendererNavigationEvents.NAVIGATE_IN_APP,
|
||||
};
|
||||
@ -1,22 +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 { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
|
||||
import type { MessageChannel } from "../utils/channel/message-channel-injection-token";
|
||||
import { messageChannelInjectionToken } from "../utils/channel/message-channel-injection-token";
|
||||
|
||||
export type ClusterFrameNavigationChannel = MessageChannel<string>;
|
||||
|
||||
const clusterFrameNavigationChannelInjectable = getInjectable({
|
||||
id: "cluster-frame-navigation-channel",
|
||||
|
||||
instantiate: (): ClusterFrameNavigationChannel => ({
|
||||
id: IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER,
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default clusterFrameNavigationChannelInjectable;
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
|
||||
import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
export type ClusterFrameNavigationChannel = MessageChannel<string>;
|
||||
|
||||
export const clusterFrameNavigationChannel: ClusterFrameNavigationChannel = {
|
||||
id: IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER,
|
||||
};
|
||||
@ -5,22 +5,33 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ExecFileOptions } from "child_process";
|
||||
import { execFile } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
|
||||
export type ExecFile = (filePath: string, args: string[], options: ExecFileOptions) => Promise<string>;
|
||||
export interface ExecFile {
|
||||
(filePath: string, args: string[], options: ExecFileOptions): Promise<AsyncResult<string, { stderr: string; error: Error }>>;
|
||||
}
|
||||
|
||||
const execFileInjectable = getInjectable({
|
||||
id: "exec-file",
|
||||
|
||||
instantiate: (): ExecFile => {
|
||||
const asyncExecFile = promisify(execFile);
|
||||
|
||||
return async (filePath, args, options) => {
|
||||
const result = await asyncExecFile(filePath, args, options);
|
||||
|
||||
return result.stdout;
|
||||
};
|
||||
},
|
||||
instantiate: (): ExecFile => (filePath, args, options) => new Promise((resolve) => {
|
||||
execFile(filePath, args, options, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error,
|
||||
stderr,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
resolve({
|
||||
callWasSuccessful: true,
|
||||
response: stdout,
|
||||
});
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
@ -2,22 +2,12 @@
|
||||
* 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 { HelmRepo } from "./helm-repo";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../utils/channel/request-channel-injection-token";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type AddHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<string>>;
|
||||
|
||||
const addHelmRepositoryChannelInjectable = getInjectable({
|
||||
export const addHelmRepositoryChannel: AddHelmRepositoryChannel = {
|
||||
id: "add-helm-repository-channel",
|
||||
|
||||
instantiate: (): AddHelmRepositoryChannel => ({
|
||||
id: "add-helm-repository-channel",
|
||||
}),
|
||||
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default addHelmRepositoryChannelInjectable;
|
||||
};
|
||||
@ -1,23 +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 { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
import { requestChannelInjectionToken } from "../utils/channel/request-channel-injection-token";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
|
||||
export type GetHelmRepositoriesChannel = RequestChannel<void, AsyncResult<HelmRepo[]>>;
|
||||
|
||||
const getActiveHelmRepositoriesChannelInjectable = getInjectable({
|
||||
id: "get-active-helm-repositories-channel",
|
||||
|
||||
instantiate: (): GetHelmRepositoriesChannel => ({
|
||||
id: "get-helm-active-list-repositories",
|
||||
}),
|
||||
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default getActiveHelmRepositoriesChannelInjectable;
|
||||
13
src/common/helm/get-active-helm-repositories-channel.ts
Normal file
13
src/common/helm/get-active-helm-repositories-channel.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type GetActiveHelmRepositoriesChannel = RequestChannel<void, AsyncResult<HelmRepo[]>>;
|
||||
|
||||
export const getActiveHelmRepositoriesChannel: GetActiveHelmRepositoriesChannel = {
|
||||
id: "get-helm-active-list-repositories",
|
||||
};
|
||||
@ -1,22 +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 { HelmRepo } from "./helm-repo";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../utils/channel/request-channel-injection-token";
|
||||
|
||||
export type RemoveHelmRepositoryChannel = RequestChannel<HelmRepo>;
|
||||
|
||||
const removeHelmRepositoryChannelInjectable = getInjectable({
|
||||
id: "remove-helm-repository-channel",
|
||||
|
||||
instantiate: (): RemoveHelmRepositoryChannel => ({
|
||||
id: "remove-helm-repository-channel",
|
||||
}),
|
||||
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default removeHelmRepositoryChannelInjectable;
|
||||
13
src/common/helm/remove-helm-repository-channel.ts
Normal file
13
src/common/helm/remove-helm-repository-channel.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
|
||||
export type RemoveHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<string, string>>;
|
||||
|
||||
export const removeHelmRepositoryChannel: RemoveHelmRepositoryChannel = {
|
||||
id: "remove-helm-repository-channel",
|
||||
};
|
||||
@ -1,21 +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 { MessageChannel } from "../utils/channel/message-channel-injection-token";
|
||||
import { messageChannelInjectionToken } from "../utils/channel/message-channel-injection-token";
|
||||
|
||||
export type RootFrameRenderedChannel = MessageChannel;
|
||||
|
||||
const rootFrameRenderedChannelInjectable = getInjectable({
|
||||
id: "root-frame-rendered-channel",
|
||||
|
||||
instantiate: (): RootFrameRenderedChannel => ({
|
||||
id: "root-frame-rendered",
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default rootFrameRenderedChannelInjectable;
|
||||
11
src/common/root-frame/root-frame-rendered-channel.ts
Normal file
11
src/common/root-frame/root-frame-rendered-channel.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
export type RootFrameHasRenderedChannel = MessageChannel<void>;
|
||||
|
||||
export const rootFrameHasRenderedChannel: RootFrameHasRenderedChannel = {
|
||||
id: "root-frame-rendered",
|
||||
};
|
||||
13
src/common/user-store/resolved-shell.injectable.ts
Normal file
13
src/common/user-store/resolved-shell.injectable.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 userStoreInjectable from "./user-store.injectable";
|
||||
|
||||
const resolvedShellInjectable = getInjectable({
|
||||
id: "resolved-shell",
|
||||
instantiate: (di) => di.inject(userStoreInjectable).resolvedShell,
|
||||
});
|
||||
|
||||
export default resolvedShellInjectable;
|
||||
@ -4,31 +4,31 @@
|
||||
*/
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MessageToChannel } from "./message-to-channel-injection-token";
|
||||
import { messageToChannelInjectionToken } from "./message-to-channel-injection-token";
|
||||
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 { MessageChannel } from "./message-channel-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-injection-token";
|
||||
import { requestChannelListenerInjectionToken } from "./request-channel-listener-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 "../../test-utils/get-promise-status";
|
||||
import { runInAction } from "mobx";
|
||||
import type { RequestChannelHandler } from "../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import { getRequestChannelListenerInjectable } 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 testMessageChannel: TestMessageChannel;
|
||||
let messageListenerInWindowMock: jest.Mock;
|
||||
let mainDi: DiContainer;
|
||||
let messageToChannel: MessageToChannel;
|
||||
let messageToChannel: SendMessageToChannel;
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -39,24 +39,17 @@ describe("channel", () => {
|
||||
const testChannelListenerInTestWindowInjectable = getInjectable({
|
||||
id: "test-channel-listener-in-test-window",
|
||||
|
||||
instantiate: (di) => ({
|
||||
channel: di.inject(testMessageChannelInjectable),
|
||||
instantiate: () => ({
|
||||
channel: testMessageChannel,
|
||||
handler: messageListenerInWindowMock,
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testMessageChannelInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
builder.beforeWindowStart((windowDi) => {
|
||||
runInAction(() => {
|
||||
windowDi.register(testChannelListenerInTestWindowInjectable);
|
||||
windowDi.register(testMessageChannelInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
@ -64,8 +57,7 @@ describe("channel", () => {
|
||||
|
||||
await builder.startHidden();
|
||||
|
||||
testMessageChannel = mainDi.inject(testMessageChannelInjectable);
|
||||
messageToChannel = mainDi.inject(messageToChannelInjectionToken);
|
||||
messageToChannel = mainDi.inject(sendMessageToChannelInjectionToken);
|
||||
});
|
||||
|
||||
describe("given window is started", () => {
|
||||
@ -109,9 +101,8 @@ describe("channel", () => {
|
||||
});
|
||||
|
||||
describe("messaging from renderer to main, given listener for channel in a main and application has started", () => {
|
||||
let testMessageChannel: TestMessageChannel;
|
||||
let messageListenerInMainMock: jest.Mock;
|
||||
let messageToChannel: MessageToChannel;
|
||||
let messageToChannel: SendMessageToChannel;
|
||||
|
||||
beforeEach(async () => {
|
||||
const applicationBuilder = getApplicationBuilder();
|
||||
@ -121,9 +112,8 @@ describe("channel", () => {
|
||||
const testChannelListenerInMainInjectable = getInjectable({
|
||||
id: "test-channel-listener-in-main",
|
||||
|
||||
instantiate: (di) => ({
|
||||
channel: di.inject(testMessageChannelInjectable),
|
||||
|
||||
instantiate: () => ({
|
||||
channel: testMessageChannel,
|
||||
handler: messageListenerInMainMock,
|
||||
}),
|
||||
|
||||
@ -133,13 +123,6 @@ describe("channel", () => {
|
||||
applicationBuilder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
mainDi.register(testMessageChannelInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
applicationBuilder.beforeWindowStart((windowDi) => {
|
||||
runInAction(() => {
|
||||
windowDi.register(testMessageChannelInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
@ -147,8 +130,7 @@ describe("channel", () => {
|
||||
|
||||
const windowDi = applicationBuilder.applicationWindow.only.di;
|
||||
|
||||
testMessageChannel = windowDi.inject(testMessageChannelInjectable);
|
||||
messageToChannel = windowDi.inject(messageToChannelInjectionToken);
|
||||
messageToChannel = windowDi.inject(sendMessageToChannelInjectionToken);
|
||||
});
|
||||
|
||||
it("when sending message, triggers listener in main", () => {
|
||||
@ -159,8 +141,7 @@ describe("channel", () => {
|
||||
});
|
||||
|
||||
describe("requesting from main in renderer, given listener for channel in a main and application has started", () => {
|
||||
let testRequestChannel: TestRequestChannel;
|
||||
let requestListenerInMainMock: AsyncFnMock<(arg: string) => string>;
|
||||
let requestListenerInMainMock: AsyncFnMock<RequestChannelHandler<TestRequestChannel>>;
|
||||
let requestFromChannel: RequestFromChannel;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -168,28 +149,14 @@ describe("channel", () => {
|
||||
|
||||
requestListenerInMainMock = asyncFn();
|
||||
|
||||
const testChannelListenerInMainInjectable = getInjectable({
|
||||
id: "test-channel-listener-in-main",
|
||||
|
||||
instantiate: (di) => ({
|
||||
channel: di.inject(testRequestChannelInjectable),
|
||||
|
||||
handler: requestListenerInMainMock,
|
||||
}),
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => requestListenerInMainMock,
|
||||
});
|
||||
|
||||
applicationBuilder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
mainDi.register(testRequestChannelInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
applicationBuilder.beforeWindowStart((windowDi) => {
|
||||
runInAction(() => {
|
||||
windowDi.register(testRequestChannelInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
@ -197,8 +164,6 @@ describe("channel", () => {
|
||||
|
||||
const windowDi = applicationBuilder.applicationWindow.only.di;
|
||||
|
||||
testRequestChannel = windowDi.inject(testRequestChannelInjectable);
|
||||
|
||||
requestFromChannel = windowDi.inject(
|
||||
requestFromChannelInjectionToken,
|
||||
);
|
||||
@ -230,21 +195,37 @@ describe("channel", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("when registering multiple handlers for the same channel, throws", async () => {
|
||||
const applicationBuilder = getApplicationBuilder();
|
||||
|
||||
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => () => "some-value",
|
||||
});
|
||||
const testChannelListenerInMain2Injectable = getRequestChannelListenerInjectable({
|
||||
channel: testRequestChannel,
|
||||
handler: () => () => "some-other-value",
|
||||
});
|
||||
|
||||
testChannelListenerInMain2Injectable.id += "2";
|
||||
|
||||
applicationBuilder.beforeApplicationStart((mainDi) => {
|
||||
runInAction(() => {
|
||||
mainDi.register(testChannelListenerInMainInjectable);
|
||||
mainDi.register(testChannelListenerInMain2Injectable);
|
||||
});
|
||||
});
|
||||
|
||||
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 testMessageChannelInjectable = getInjectable({
|
||||
id: "some-message-test-channel",
|
||||
const testMessageChannel: TestMessageChannel = {
|
||||
id: "some-message-channel-id",
|
||||
};
|
||||
|
||||
instantiate: (): TestMessageChannel => ({
|
||||
id: "some-message-channel-id",
|
||||
}),
|
||||
});
|
||||
|
||||
const testRequestChannelInjectable = getInjectable({
|
||||
id: "some-request-test-channel",
|
||||
|
||||
instantiate: (): TestRequestChannel => ({
|
||||
id: "some-request-channel-id",
|
||||
}),
|
||||
});
|
||||
const testRequestChannel: TestRequestChannel = {
|
||||
id: "some-request-channel-id",
|
||||
};
|
||||
|
||||
|
||||
@ -3,14 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { MessageChannel } from "./message-channel-injection-token";
|
||||
import type { MessageChannelListener } from "./message-channel-listener-injection-token";
|
||||
import type { Disposer } from "../disposer";
|
||||
import type { MessageChannel, MessageChannelListener } from "./message-channel-listener-injection-token";
|
||||
|
||||
export type EnlistMessageChannelListener = <
|
||||
TChannel extends MessageChannel<any>,
|
||||
>(listener: MessageChannelListener<TChannel>) => () => void;
|
||||
export type EnlistMessageChannelListener = (listener: MessageChannelListener<MessageChannel<unknown>>) => Disposer;
|
||||
|
||||
export const enlistMessageChannelListenerInjectionToken =
|
||||
getInjectionToken<EnlistMessageChannelListener>({
|
||||
id: "enlist-message-channel-listener",
|
||||
});
|
||||
export const enlistMessageChannelListenerInjectionToken = getInjectionToken<EnlistMessageChannelListener>({
|
||||
id: "enlist-message-channel-listener",
|
||||
});
|
||||
|
||||
@ -1,16 +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 { RequestChannel } from "./request-channel-injection-token";
|
||||
import type { RequestChannelListener } from "./request-channel-listener-injection-token";
|
||||
|
||||
export type EnlistRequestChannelListener = <
|
||||
TChannel extends RequestChannel<any, any>,
|
||||
>(listener: RequestChannelListener<TChannel>) => () => void;
|
||||
|
||||
export const enlistRequestChannelListenerInjectionToken =
|
||||
getInjectionToken<EnlistRequestChannelListener>({
|
||||
id: "enlist-request-channel-listener",
|
||||
});
|
||||
@ -1,32 +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 { disposer } from "../index";
|
||||
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
|
||||
import { requestChannelListenerInjectionToken } from "./request-channel-listener-injection-token";
|
||||
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
|
||||
import { enlistRequestChannelListenerInjectionToken } from "./enlist-request-channel-listener-injection-token";
|
||||
|
||||
const listeningOfChannelsInjectable = getInjectable({
|
||||
id: "listening-of-channels",
|
||||
|
||||
instantiate: (di) => {
|
||||
const enlistMessageChannelListener = di.inject(enlistMessageChannelListenerInjectionToken);
|
||||
const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectionToken);
|
||||
const messageChannelListeners = di.injectMany(messageChannelListenerInjectionToken);
|
||||
const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken);
|
||||
|
||||
return getStartableStoppable("listening-of-channels", () => {
|
||||
const messageChannelDisposers = messageChannelListeners.map(enlistMessageChannelListener);
|
||||
const requestChannelDisposers = requestChannelListeners.map(enlistRequestChannelListener);
|
||||
|
||||
return disposer(...messageChannelDisposers, ...requestChannelDisposers);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
export default listeningOfChannelsInjectable;
|
||||
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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 { disposer } from "../index";
|
||||
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
|
||||
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
|
||||
|
||||
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;
|
||||
@ -1,16 +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 { JsonValue } from "type-fest";
|
||||
|
||||
export interface MessageChannel<Message extends JsonValue | void = void> {
|
||||
id: string;
|
||||
_messageSignature?: Message;
|
||||
}
|
||||
|
||||
export const messageChannelInjectionToken = getInjectionToken<MessageChannel<any>>({
|
||||
id: "message-channel",
|
||||
});
|
||||
@ -2,17 +2,50 @@
|
||||
* 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 { SetRequired } from "type-fest";
|
||||
import type { MessageChannel } from "./message-channel-injection-token";
|
||||
import type { DiContainerForInjection } from "@ogre-tools/injectable";
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
|
||||
export interface MessageChannelListener<TChannel extends MessageChannel<any>> {
|
||||
channel: TChannel;
|
||||
handler: (value: SetRequired<TChannel, "_messageSignature">["_messageSignature"]) => void;
|
||||
export interface MessageChannel<Message> {
|
||||
id: string;
|
||||
_messageSignature?: Message; // only used to mark `Message` as used
|
||||
}
|
||||
|
||||
export const messageChannelListenerInjectionToken = getInjectionToken<MessageChannelListener<MessageChannel<any>>>(
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
@ -3,21 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { SetRequired } from "type-fest";
|
||||
import type { MessageChannel } from "./message-channel-injection-token";
|
||||
import type { MessageChannel } from "./message-channel-listener-injection-token";
|
||||
|
||||
export interface MessageToChannel {
|
||||
<TChannel extends MessageChannel<TMessage>, TMessage extends void>(
|
||||
channel: TChannel,
|
||||
): void;
|
||||
|
||||
<TChannel extends MessageChannel<any>>(
|
||||
channel: TChannel,
|
||||
message: SetRequired<TChannel, "_messageSignature">["_messageSignature"],
|
||||
): void;
|
||||
export interface SendMessageToChannel {
|
||||
(channel: MessageChannel<void>): void;
|
||||
<Message>(channel: MessageChannel<Message>, message: Message): void;
|
||||
}
|
||||
|
||||
export const messageToChannelInjectionToken =
|
||||
getInjectionToken<MessageToChannel>({
|
||||
id: "message-to-message-channel",
|
||||
});
|
||||
export const sendMessageToChannelInjectionToken = getInjectionToken<SendMessageToChannel>({
|
||||
id: "send-message-to-message-channel",
|
||||
});
|
||||
|
||||
@ -1,20 +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 { JsonValue } from "type-fest";
|
||||
|
||||
export interface RequestChannel<
|
||||
Request extends JsonValue | void = void,
|
||||
Response extends JsonValue | void = void,
|
||||
> {
|
||||
id: string;
|
||||
_requestSignature?: Request;
|
||||
_responseSignature?: Response;
|
||||
}
|
||||
|
||||
export const requestChannelInjectionToken = getInjectionToken<RequestChannel<any, any>>({
|
||||
id: "request-channel",
|
||||
});
|
||||
@ -2,24 +2,9 @@
|
||||
* 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 { SetRequired } from "type-fest";
|
||||
import type { RequestChannel } from "./request-channel-injection-token";
|
||||
|
||||
export interface RequestChannelListener<TChannel extends RequestChannel<any, any>> {
|
||||
channel: TChannel;
|
||||
|
||||
handler: (
|
||||
request: SetRequired<TChannel, "_requestSignature">["_requestSignature"]
|
||||
) =>
|
||||
| SetRequired<TChannel, "_responseSignature">["_responseSignature"]
|
||||
| Promise<
|
||||
SetRequired<TChannel, "_responseSignature">["_responseSignature"]
|
||||
>;
|
||||
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"
|
||||
}
|
||||
|
||||
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<any, any>>>(
|
||||
{
|
||||
id: "request-channel-listener",
|
||||
},
|
||||
);
|
||||
|
||||
@ -3,19 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { SetRequired } from "type-fest";
|
||||
import type { RequestChannel } from "./request-channel-injection-token";
|
||||
import type { RequestChannel } from "./request-channel-listener-injection-token";
|
||||
|
||||
export type RequestFromChannel = <
|
||||
TChannel extends RequestChannel<any, any>,
|
||||
>(
|
||||
channel: TChannel,
|
||||
...request: TChannel["_requestSignature"] extends void
|
||||
? []
|
||||
: [SetRequired<TChannel, "_requestSignature">["_requestSignature"]]
|
||||
) => Promise<SetRequired<TChannel, "_responseSignature">["_responseSignature"]>;
|
||||
export interface RequestFromChannel {
|
||||
<Request, Response>(channel: RequestChannel<Request, Response>, request: Request): Promise<Response>;
|
||||
<Response>(channel: RequestChannel<void, Response>): Promise<Response>;
|
||||
}
|
||||
|
||||
export const requestFromChannelInjectionToken =
|
||||
getInjectionToken<RequestFromChannel>({
|
||||
id: "request-from-request-channel",
|
||||
});
|
||||
export const requestFromChannelInjectionToken = getInjectionToken<RequestFromChannel>({
|
||||
id: "request-from-request-channel",
|
||||
});
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { SingleOrMany } from "./types";
|
||||
|
||||
|
||||
|
||||
export interface Disposer {
|
||||
@ -17,9 +19,9 @@ export interface ExtendableDisposer extends Disposer {
|
||||
push(...vals: (Disposer | ExtendableDisposer | Disposable)[]): void;
|
||||
}
|
||||
|
||||
export function disposer(...items: (Disposer | Disposable | undefined | null)[]): ExtendableDisposer {
|
||||
export function disposer(...items: SingleOrMany<Disposer | Disposable | undefined | null>[]): ExtendableDisposer {
|
||||
return Object.assign(() => {
|
||||
for (const item of items) {
|
||||
for (const item of items.flat()) {
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1,21 +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 { RequestChannel } from "../channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../channel/request-channel-injection-token";
|
||||
|
||||
export type ResolveSystemProxyChannel = RequestChannel<string, string>;
|
||||
|
||||
const resolveSystemProxyChannelInjectable = getInjectable({
|
||||
id: "resolve-system-proxy-channel",
|
||||
|
||||
instantiate: (): ResolveSystemProxyChannel => ({
|
||||
id: "resolve-system-proxy-channel",
|
||||
}),
|
||||
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default resolveSystemProxyChannelInjectable;
|
||||
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { RequestChannel } from "../channel/request-channel-listener-injection-token";
|
||||
|
||||
export type ResolveSystemProxyChannel = RequestChannel<string, string>;
|
||||
|
||||
export const resolveSystemProxyChannel: ResolveSystemProxyChannel = {
|
||||
id: "resolve-system-proxy-channel",
|
||||
};
|
||||
15
src/common/utils/sync-box/channel-listener.injectable.ts
Normal file
15
src/common/utils/sync-box/channel-listener.injectable.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { syncBoxChannel } from "./channels";
|
||||
import { getMessageChannelListenerInjectable } from "../channel/message-channel-listener-injection-token";
|
||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
||||
|
||||
const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "init",
|
||||
channel: syncBoxChannel,
|
||||
handler: (di) => ({ id, value }) => di.inject(syncBoxStateInjectable, id).set(value),
|
||||
});
|
||||
|
||||
export default syncBoxChannelListenerInjectable;
|
||||
21
src/common/utils/sync-box/channels.ts
Normal file
21
src/common/utils/sync-box/channels.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { MessageChannel } from "../channel/message-channel-listener-injection-token";
|
||||
import type { RequestChannel } from "../channel/request-channel-listener-injection-token";
|
||||
|
||||
export type SyncBoxChannel = MessageChannel<{ id: string; value: any }>;
|
||||
|
||||
export const syncBoxChannel: SyncBoxChannel = {
|
||||
id: "sync-box-channel",
|
||||
};
|
||||
|
||||
export type SyncBoxInitialValueChannel = RequestChannel<
|
||||
void,
|
||||
{ id: string; value: any }[]
|
||||
>;
|
||||
|
||||
export const syncBoxInitialValueChannel: SyncBoxInitialValueChannel = {
|
||||
id: "sync-box-initial-value-channel",
|
||||
};
|
||||
@ -5,17 +5,17 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
||||
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
||||
import { syncBoxChannel } from "./channels";
|
||||
import { sendMessageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
||||
import type { SyncBox } from "./sync-box-injection-token";
|
||||
import { toJS } from "../toJS";
|
||||
|
||||
const createSyncBoxInjectable = getInjectable({
|
||||
id: "create-sync-box",
|
||||
|
||||
instantiate: (di) => {
|
||||
const syncBoxChannel = di.inject(syncBoxChannelInjectable);
|
||||
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||
const messageToChannel = di.inject(sendMessageToChannelInjectionToken);
|
||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||
|
||||
return <Value>(id: string, initialValue: Value): SyncBox<Value> => {
|
||||
@ -26,7 +26,7 @@ const createSyncBoxInjectable = getInjectable({
|
||||
return {
|
||||
id,
|
||||
|
||||
value: computed(() => state.get()),
|
||||
value: computed(() => toJS(state.get())),
|
||||
|
||||
set: (value) => {
|
||||
state.set(value);
|
||||
|
||||
19
src/common/utils/sync-box/handler.injectable.ts
Normal file
19
src/common/utils/sync-box/handler.injectable.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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;
|
||||
@ -1,35 +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 { SyncBoxChannel } from "./sync-box-channel.injectable";
|
||||
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
||||
import type { MessageChannelListener } from "../channel/message-channel-listener-injection-token";
|
||||
import { messageChannelListenerInjectionToken } from "../channel/message-channel-listener-injection-token";
|
||||
|
||||
const syncBoxChannelListenerInjectable = getInjectable({
|
||||
id: "sync-box-channel-listener",
|
||||
|
||||
instantiate: (di): MessageChannelListener<SyncBoxChannel> => {
|
||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||
const channel = di.inject(syncBoxChannelInjectable);
|
||||
|
||||
return {
|
||||
channel,
|
||||
|
||||
handler: ({ id, value }) => {
|
||||
const target = getSyncBoxState(id);
|
||||
|
||||
if (target) {
|
||||
target.set(value);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default syncBoxChannelListenerInjectable;
|
||||
@ -1,21 +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 { MessageChannel } from "../channel/message-channel-injection-token";
|
||||
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
|
||||
|
||||
export type SyncBoxChannel = MessageChannel<{ id: string; value: any }>;
|
||||
|
||||
const syncBoxChannelInjectable = getInjectable({
|
||||
id: "sync-box-channel",
|
||||
|
||||
instantiate: (): SyncBoxChannel => ({
|
||||
id: "sync-box-channel",
|
||||
}),
|
||||
|
||||
injectionToken: messageChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default syncBoxChannelInjectable;
|
||||
@ -1,24 +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 { RequestChannel } from "../channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../channel/request-channel-injection-token";
|
||||
|
||||
export type SyncBoxInitialValueChannel = RequestChannel<
|
||||
void,
|
||||
{ id: string; value: any }[]
|
||||
>;
|
||||
|
||||
const syncBoxInitialValueChannelInjectable = getInjectable({
|
||||
id: "sync-box-initial-value-channel",
|
||||
|
||||
instantiate: (): SyncBoxInitialValueChannel => ({
|
||||
id: "sync-box-initial-value-channel",
|
||||
}),
|
||||
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default syncBoxInitialValueChannelInjectable;
|
||||
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { defaultTo } from "lodash/fp";
|
||||
import { withErrorSuppression } from "./with-error-suppression/with-error-suppression";
|
||||
|
||||
export const tentativeParseJson = (toBeParsed: any) => pipeline(
|
||||
toBeParsed,
|
||||
withErrorSuppression(JSON.parse),
|
||||
defaultTo(toBeParsed),
|
||||
);
|
||||
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { defaultTo } from "lodash/fp";
|
||||
import { withErrorSuppression } from "./with-error-suppression/with-error-suppression";
|
||||
|
||||
export const tentativeStringifyJson = (toBeParsed: any) => pipeline(
|
||||
toBeParsed,
|
||||
withErrorSuppression(JSON.stringify),
|
||||
defaultTo(toBeParsed),
|
||||
);
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { SemVer } from "semver";
|
||||
import type { InitializableState } from "../initializable-state/create";
|
||||
import { createInitializableState } from "../initializable-state/create";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export const buildVersionInjectionToken = getInjectionToken<InitializableState<string>>({
|
||||
id: "build-version-token",
|
||||
|
||||
@ -222,7 +222,7 @@ describe("selection of update stability", () => {
|
||||
it('given user changes update channel to "alpha", when user would close the application, installs the update for being stable enough', () => {
|
||||
selectedUpdateChannel.setValue(updateChannels.alpha.id);
|
||||
|
||||
expect(setUpdateOnQuitMock).toHaveBeenLastCalledWith(false);
|
||||
expect(setUpdateOnQuitMock).toHaveBeenLastCalledWith(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,20 +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 { ClusterId } from "../../../../common/cluster-types";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../../../../common/utils/channel/request-channel-injection-token";
|
||||
|
||||
export type ClearClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
|
||||
|
||||
const clearClusterAsDeletingChannelInjectable = getInjectable({
|
||||
id: "clear-cluster-as-deleting-channel",
|
||||
instantiate: (): ClearClusterAsDeletingChannel => ({
|
||||
id: "clear-cluster-as-deleting",
|
||||
}),
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default clearClusterAsDeletingChannelInjectable;
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type ClearClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
|
||||
|
||||
export const clearClusterAsDeletingChannel: ClearClusterAsDeletingChannel = {
|
||||
id: "clear-cluster-as-deleting",
|
||||
};
|
||||
@ -1,20 +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 { ClusterId } from "../../../../common/cluster-types";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../../../../common/utils/channel/request-channel-injection-token";
|
||||
|
||||
export type DeleteClusterChannel = RequestChannel<ClusterId, void>;
|
||||
|
||||
const deleteClusterChannelInjectable = getInjectable({
|
||||
id: "delete-cluster-channel",
|
||||
instantiate: (): DeleteClusterChannel => ({
|
||||
id: "delete-cluster",
|
||||
}),
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default deleteClusterChannelInjectable;
|
||||
12
src/features/cluster/delete-dialog/common/delete-channel.ts
Normal file
12
src/features/cluster/delete-dialog/common/delete-channel.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type DeleteClusterChannel = RequestChannel<ClusterId, void>;
|
||||
|
||||
export const deleteClusterChannel: DeleteClusterChannel = {
|
||||
id: "delete-cluster",
|
||||
};
|
||||
@ -1,20 +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 { ClusterId } from "../../../../common/cluster-types";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-injection-token";
|
||||
import { requestChannelInjectionToken } from "../../../../common/utils/channel/request-channel-injection-token";
|
||||
|
||||
export type SetClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
|
||||
|
||||
const setClusterAsDeletingChannelInjectable = getInjectable({
|
||||
id: "set-cluster-as-deleting-channel",
|
||||
instantiate: (): SetClusterAsDeletingChannel => ({
|
||||
id: "set-cluster-as-deleting",
|
||||
}),
|
||||
injectionToken: requestChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default setClusterAsDeletingChannelInjectable;
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type SetClusterAsDeletingChannel = RequestChannel<ClusterId, void>;
|
||||
|
||||
export const setClusterAsDeletingChannel: SetClusterAsDeletingChannel = {
|
||||
id: "set-cluster-as-deleting",
|
||||
};
|
||||
@ -1,23 +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 { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
|
||||
import clearClusterAsDeletingChannelInjectable from "../common/clear-as-deleting-channel.injectable";
|
||||
|
||||
const clearClusterAsDeletingChannelHandlerInjectable = getInjectable({
|
||||
id: "clear-cluster-as-deleting-channel-handler",
|
||||
instantiate: (di) => {
|
||||
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
|
||||
|
||||
return {
|
||||
channel: di.inject(clearClusterAsDeletingChannelInjectable),
|
||||
handler: (clusterId) => clustersThatAreBeingDeleted.delete(clusterId),
|
||||
};
|
||||
},
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default clearClusterAsDeletingChannelHandlerInjectable;
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
|
||||
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel";
|
||||
|
||||
const clearClusterAsDeletingChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: clearClusterAsDeletingChannel,
|
||||
handler: (di) => {
|
||||
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
|
||||
|
||||
return (clusterId) => {
|
||||
clustersThatAreBeingDeleted.delete(clusterId);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default clearClusterAsDeletingChannelListenerInjectable;
|
||||
@ -1,56 +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 appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
|
||||
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
|
||||
import deleteFileInjectable from "../../../../common/fs/delete-file.injectable";
|
||||
import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
|
||||
import { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import deleteClusterChannelInjectable from "../common/delete-channel.injectable";
|
||||
|
||||
const deleteClusterChannelHandlerInjectable = getInjectable({
|
||||
id: "delete-cluster-channel-handler",
|
||||
instantiate: (di) => {
|
||||
const appEventBus = di.inject(appEventBusInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const directoryForLensLocalStorage = di.inject(directoryForLensLocalStorageInjectable);
|
||||
const deleteFile = di.inject(deleteFileInjectable);
|
||||
|
||||
return {
|
||||
channel: di.inject(deleteClusterChannelInjectable),
|
||||
handler: async (clusterId) =>{
|
||||
appEventBus.emit({ name: "cluster", action: "remove" });
|
||||
|
||||
const cluster = clusterStore.getById(clusterId);
|
||||
|
||||
if (!cluster) {
|
||||
return;
|
||||
}
|
||||
|
||||
cluster.disconnect();
|
||||
clusterFrames.delete(cluster.id);
|
||||
|
||||
// Remove from the cluster store as well, this should clear any old settings
|
||||
clusterStore.clusters.delete(cluster.id);
|
||||
|
||||
try {
|
||||
// remove the local storage file
|
||||
const localStorageFilePath = joinPaths(directoryForLensLocalStorage, `${cluster.id}.json`);
|
||||
|
||||
await deleteFile(localStorageFilePath);
|
||||
} catch {
|
||||
// ignore error
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default deleteClusterChannelHandlerInjectable;
|
||||
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
|
||||
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
|
||||
import deleteFileInjectable from "../../../../common/fs/delete-file.injectable";
|
||||
import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
|
||||
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import { deleteClusterChannel } from "../common/delete-channel";
|
||||
|
||||
const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: deleteClusterChannel,
|
||||
handler: (di) => {
|
||||
const appEventBus = di.inject(appEventBusInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const directoryForLensLocalStorage = di.inject(directoryForLensLocalStorageInjectable);
|
||||
const deleteFile = di.inject(deleteFileInjectable);
|
||||
|
||||
return async (clusterId) => {
|
||||
appEventBus.emit({ name: "cluster", action: "remove" });
|
||||
|
||||
const cluster = clusterStore.getById(clusterId);
|
||||
|
||||
if (!cluster) {
|
||||
return;
|
||||
}
|
||||
|
||||
cluster.disconnect();
|
||||
clusterFrames.delete(cluster.id);
|
||||
|
||||
// Remove from the cluster store as well, this should clear any old settings
|
||||
clusterStore.clusters.delete(cluster.id);
|
||||
|
||||
try {
|
||||
// remove the local storage file
|
||||
const localStorageFilePath = joinPaths(directoryForLensLocalStorage, `${cluster.id}.json`);
|
||||
|
||||
await deleteFile(localStorageFilePath);
|
||||
} catch {
|
||||
// ignore error
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default deleteClusterChannelListenerInjectable;
|
||||
@ -1,23 +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 { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
|
||||
import setClusterAsDeletingChannelInjectable from "../common/set-as-deleting-channel.injectable";
|
||||
|
||||
const setClusterAsDeletingChannelHandlerInjectable = getInjectable({
|
||||
id: "set-cluster-as-deleting-channel-handler",
|
||||
instantiate: (di) => {
|
||||
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
|
||||
|
||||
return {
|
||||
channel: di.inject(setClusterAsDeletingChannelInjectable),
|
||||
handler: (clusterId) => clustersThatAreBeingDeleted.add(clusterId),
|
||||
};
|
||||
},
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default setClusterAsDeletingChannelHandlerInjectable;
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import clustersThatAreBeingDeletedInjectable from "../../../../main/cluster/are-being-deleted.injectable";
|
||||
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel";
|
||||
|
||||
const setClusterAsDeletingChannelHandlerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: setClusterAsDeletingChannel,
|
||||
handler: (di) => {
|
||||
const clustersThatAreBeingDeleted = di.inject(clustersThatAreBeingDeletedInjectable);
|
||||
|
||||
return (clusterId) => {
|
||||
clustersThatAreBeingDeleted.add(clusterId);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default setClusterAsDeletingChannelHandlerInjectable;
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
|
||||
import clearClusterAsDeletingChannelInjectable from "../common/clear-as-deleting-channel.injectable";
|
||||
import { clearClusterAsDeletingChannel } from "../common/clear-as-deleting-channel";
|
||||
|
||||
export type RequestClearClusterAsDeleting = (clusterId: ClusterId) => Promise<void>;
|
||||
|
||||
@ -13,7 +13,6 @@ const requestClearClusterAsDeletingInjectable = getInjectable({
|
||||
id: "request-clear-cluster-as-deleting",
|
||||
instantiate: (di): RequestClearClusterAsDeleting => {
|
||||
const requestChannel = di.inject(requestFromChannelInjectable);
|
||||
const clearClusterAsDeletingChannel = di.inject(clearClusterAsDeletingChannelInjectable);
|
||||
|
||||
return (clusterId) => requestChannel(clearClusterAsDeletingChannel, clusterId);
|
||||
},
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
|
||||
import deleteClusterChannelInjectable from "../common/delete-channel.injectable";
|
||||
import { deleteClusterChannel } from "../common/delete-channel";
|
||||
|
||||
export type RequestDeleteCluster = (clusterId: ClusterId) => Promise<void>;
|
||||
|
||||
@ -13,7 +13,6 @@ const requestDeleteClusterInjectable = getInjectable({
|
||||
id: "request-delete-cluster",
|
||||
instantiate: (di): RequestDeleteCluster => {
|
||||
const requestChannel = di.inject(requestFromChannelInjectable);
|
||||
const deleteClusterChannel = di.inject(deleteClusterChannelInjectable);
|
||||
|
||||
return (clusterId) => requestChannel(deleteClusterChannel, clusterId);
|
||||
},
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
|
||||
import setClusterAsDeletingChannelInjectable from "../common/set-as-deleting-channel.injectable";
|
||||
import { setClusterAsDeletingChannel } from "../common/set-as-deleting-channel";
|
||||
|
||||
export type RequestSetClusterAsDeleting = (clusterId: ClusterId) => Promise<void>;
|
||||
|
||||
@ -13,7 +13,6 @@ const requestSetClusterAsDeletingInjectable = getInjectable({
|
||||
id: "request-set-cluster-as-deleting",
|
||||
instantiate: (di): RequestSetClusterAsDeleting => {
|
||||
const requestChannel = di.inject(requestFromChannelInjectable);
|
||||
const setClusterAsDeletingChannel = di.inject(setClusterAsDeletingChannelInjectable);
|
||||
|
||||
return (clusterId) => requestChannel(setClusterAsDeletingChannel, clusterId);
|
||||
},
|
||||
|
||||
@ -1759,7 +1759,7 @@ exports[`add helm repository from list in preferences when navigating to prefere
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="Select__menu-portal css-yj2v5g"
|
||||
class="Select__menu-portal css-1no2yl0-MenuPortal"
|
||||
>
|
||||
<div
|
||||
class="theme-lens selection-of-active-public-helm-repository-options Select__menu css-26l3qy-menu"
|
||||
@ -4819,7 +4819,7 @@ exports[`add helm repository from list in preferences when navigating to prefere
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="Select__menu-portal css-yj2v5g"
|
||||
class="Select__menu-portal css-1no2yl0-MenuPortal"
|
||||
>
|
||||
<div
|
||||
class="theme-lens selection-of-active-public-helm-repository-options Select__menu css-26l3qy-menu"
|
||||
|
||||
@ -8,6 +8,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import execFileInjectable from "../../common/fs/exec-file.injectable";
|
||||
import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectable";
|
||||
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
@ -24,9 +25,7 @@ describe("add custom helm repository in preferences", () => {
|
||||
let showSuccessNotificationMock: jest.Mock;
|
||||
let showErrorNotificationMock: jest.Mock;
|
||||
let rendered: RenderResult;
|
||||
let execFileMock: AsyncFnMock<
|
||||
ReturnType<typeof execFileInjectable["instantiate"]>
|
||||
>;
|
||||
let execFileMock: AsyncFnMock<ExecFile>;
|
||||
let getActiveHelmRepositoriesMock: AsyncFnMock<() => Promise<AsyncResult<HelmRepo[]>>>;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -184,9 +183,13 @@ describe("add custom helm repository in preferences", () => {
|
||||
|
||||
describe("when activation rejects", () => {
|
||||
beforeEach(async () => {
|
||||
await execFileMock.reject(
|
||||
"Some error",
|
||||
);
|
||||
await execFileMock.resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error: new Error("Some error"),
|
||||
stderr: "",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
@ -219,8 +222,10 @@ describe("add custom helm repository in preferences", () => {
|
||||
"some-helm-binary-path",
|
||||
["repo", "add", "some-custom-repository", "http://some.url"],
|
||||
],
|
||||
|
||||
"",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import execFileInjectable from "../../common/fs/exec-file.injectable";
|
||||
import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectable";
|
||||
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
@ -21,9 +22,7 @@ describe("add helm repository from list in preferences", () => {
|
||||
let showSuccessNotificationMock: jest.Mock;
|
||||
let showErrorNotificationMock: jest.Mock;
|
||||
let rendered: RenderResult;
|
||||
let execFileMock: AsyncFnMock<
|
||||
ReturnType<typeof execFileInjectable["instantiate"]>
|
||||
>;
|
||||
let execFileMock: AsyncFnMock<ExecFile>;
|
||||
let getActiveHelmRepositoriesMock: AsyncFnMock<() => Promise<AsyncResult<HelmRepo[]>>>;
|
||||
let callForPublicHelmRepositoriesMock: AsyncFnMock<() => Promise<HelmRepo[]>>;
|
||||
|
||||
@ -129,9 +128,13 @@ describe("add helm repository from list in preferences", () => {
|
||||
|
||||
describe("when adding rejects", () => {
|
||||
beforeEach(async () => {
|
||||
await execFileMock.reject(
|
||||
"Some error",
|
||||
);
|
||||
await execFileMock.resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error: new Error("Some error"),
|
||||
stderr: "",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
@ -164,8 +167,10 @@ describe("add helm repository from list in preferences", () => {
|
||||
"some-helm-binary-path",
|
||||
["repo", "add", "Some to be added repository", "some-other-url"],
|
||||
],
|
||||
|
||||
"",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -243,8 +248,10 @@ describe("add helm repository from list in preferences", () => {
|
||||
"some-helm-binary-path",
|
||||
["repo", "remove", "Some already active repository"],
|
||||
],
|
||||
|
||||
"",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@ -3071,7 +3071,7 @@ exports[`installing helm chart from new tab given tab for installing chart was n
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Select__menu-portal css-yj2v5g"
|
||||
class="Select__menu-portal css-1no2yl0-MenuPortal"
|
||||
>
|
||||
<div
|
||||
class="theme-outlined install-chart-version-select-for-some-first-tab-id-options Select__menu css-26l3qy-menu"
|
||||
@ -7984,7 +7984,7 @@ exports[`installing helm chart from new tab given tab for installing chart was n
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Select__menu-portal css-yj2v5g"
|
||||
class="Select__menu-portal css-1no2yl0-MenuPortal"
|
||||
>
|
||||
<div
|
||||
class="NamespaceSelectMenu theme-outlined install-chart-namespace-select-for-some-first-tab-id-options Select__menu css-26l3qy-menu"
|
||||
|
||||
@ -83,7 +83,13 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
describe("when getting configuration rejects", () => {
|
||||
beforeEach(async () => {
|
||||
await execFileMock.reject("some-error");
|
||||
await execFileMock.resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error: new Error("some error"),
|
||||
stderr: "some-error",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("shows error notification", () => {
|
||||
@ -115,7 +121,10 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
await execFileMock.resolveSpecific(
|
||||
["some-helm-binary-path", ["env"]],
|
||||
"HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -154,7 +163,10 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
await execFileMock.resolveSpecific(
|
||||
["some-helm-binary-path", ["env"]],
|
||||
"HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -193,11 +205,13 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
await execFileMock.resolveSpecific(
|
||||
["some-helm-binary-path", ["env"]],
|
||||
|
||||
[
|
||||
"HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
|
||||
"HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
|
||||
].join("\n"),
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: [
|
||||
"HELM_REPOSITORY_CONFIG=some-helm-repository-config-file.yaml",
|
||||
"HELM_REPOSITORY_CACHE=some-helm-repository-cache-path",
|
||||
].join("\n"),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -219,7 +233,13 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
describe("when updating repositories reject with any other error", () => {
|
||||
beforeEach(async () => {
|
||||
await execFileMock.reject("Some error");
|
||||
await execFileMock.resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error: new Error("Some error"),
|
||||
stderr: "Some error",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("shows error notification", () => {
|
||||
@ -249,9 +269,13 @@ describe("listing active helm repositories in preferences", () => {
|
||||
beforeEach(async () => {
|
||||
execFileMock.mockClear();
|
||||
|
||||
await execFileMock.reject(
|
||||
"Error: no repositories found. You must add one before updating",
|
||||
);
|
||||
await execFileMock.resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error: new Error("no repositories found. You must add one before updating"),
|
||||
stderr: "no repositories found. You must add one before updating",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
@ -274,7 +298,13 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
describe("when adding default repository reject", () => {
|
||||
beforeEach(async () => {
|
||||
await execFileMock.reject("Some error");
|
||||
await execFileMock.resolve({
|
||||
callWasSuccessful: false,
|
||||
error: {
|
||||
error: new Error("Some error"),
|
||||
stderr: "Some error",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("shows error notification", () => {
|
||||
@ -307,7 +337,6 @@ describe("listing active helm repositories in preferences", () => {
|
||||
await execFileMock.resolveSpecific(
|
||||
[
|
||||
"some-helm-binary-path",
|
||||
|
||||
[
|
||||
"repo",
|
||||
"add",
|
||||
@ -315,8 +344,10 @@ describe("listing active helm repositories in preferences", () => {
|
||||
"https://charts.bitnami.com/bitnami",
|
||||
],
|
||||
],
|
||||
|
||||
"",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -380,7 +411,10 @@ describe("listing active helm repositories in preferences", () => {
|
||||
|
||||
await execFileMock.resolveSpecific(
|
||||
["some-helm-binary-path", ["repo", "update"]],
|
||||
"",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import execFileInjectable from "../../common/fs/exec-file.injectable";
|
||||
import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectable";
|
||||
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
@ -19,9 +20,7 @@ describe("remove helm repository from list of active repositories in preferences
|
||||
let builder: ApplicationBuilder;
|
||||
let rendered: RenderResult;
|
||||
let getActiveHelmRepositoriesMock: AsyncFnMock<() => Promise<AsyncResult<HelmRepo[]>>>;
|
||||
let execFileMock: AsyncFnMock<
|
||||
ReturnType<typeof execFileInjectable["instantiate"]>
|
||||
>;
|
||||
let execFileMock: AsyncFnMock<ExecFile>;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
@ -101,8 +100,10 @@ describe("remove helm repository from list of active repositories in preferences
|
||||
"some-helm-binary-path",
|
||||
["repo", "remove", "some-active-repository"],
|
||||
],
|
||||
|
||||
"",
|
||||
{
|
||||
callWasSuccessful: true,
|
||||
response: "",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
12
src/features/navigation/reload-page/common/channel.ts
Normal file
12
src/features/navigation/reload-page/common/channel.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { MessageChannel } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
export type ReloadPageChannel = MessageChannel<void>;
|
||||
|
||||
export const reloadPageChannel: ReloadPageChannel = {
|
||||
id: "reload-page-channel",
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
|
||||
import { reloadPageChannel } from "../common/channel";
|
||||
import reloadPageChannelListenerInjectable from "./register-listener.injectable";
|
||||
|
||||
export default getGlobalOverride(reloadPageChannelListenerInjectable, () => ({
|
||||
channel: reloadPageChannel,
|
||||
handler: () => {},
|
||||
}));
|
||||
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { reloadPageChannel } from "../common/channel";
|
||||
|
||||
const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "handler",
|
||||
channel: reloadPageChannel,
|
||||
handler: () => () => location.reload(),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default reloadPageChannelListenerInjectable;
|
||||
@ -7,14 +7,14 @@ import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars";
|
||||
|
||||
describe("clearKubeconfigEnvVars tests", () => {
|
||||
it("should not touch non kubeconfig keys", () => {
|
||||
expect(clearKubeconfigEnvVars({ a: 1 })).toStrictEqual({ a: 1 });
|
||||
expect(clearKubeconfigEnvVars({ a: "22" })).toStrictEqual({ a: "22" });
|
||||
});
|
||||
|
||||
it("should remove a single kubeconfig key", () => {
|
||||
expect(clearKubeconfigEnvVars({ a: 1, kubeconfig: "1" })).toStrictEqual({ a: 1 });
|
||||
expect(clearKubeconfigEnvVars({ a: "22", kubeconfig: "1" })).toStrictEqual({ a: "22" });
|
||||
});
|
||||
|
||||
it("should remove a two kubeconfig key", () => {
|
||||
expect(clearKubeconfigEnvVars({ a: 1, kubeconfig: "1", kUbeconfig: "1" })).toStrictEqual({ a: 1 });
|
||||
expect(clearKubeconfigEnvVars({ a: "22", kubeconfig: "1", kUbeconfig: "1" })).toStrictEqual({ a: "22" });
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,26 +2,17 @@
|
||||
* 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 { RequestChannelListener } from "../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import { requestChannelListenerInjectionToken } from "../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import type { AppPathsChannel } from "../../common/app-paths/app-paths-channel.injectable";
|
||||
import appPathsChannelInjectable from "../../common/app-paths/app-paths-channel.injectable";
|
||||
import { appPathsChannel } from "../../common/app-paths/app-paths-channel";
|
||||
import appPathsInjectable from "../../common/app-paths/app-paths.injectable";
|
||||
import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens";
|
||||
|
||||
const appPathsRequestChannelListenerInjectable = getInjectable({
|
||||
id: "app-paths-request-channel-listener",
|
||||
|
||||
instantiate: (di): RequestChannelListener<AppPathsChannel> => {
|
||||
const channel = di.inject(appPathsChannelInjectable);
|
||||
const appPathsRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: appPathsChannel,
|
||||
handler: (di) => {
|
||||
const appPaths = di.inject(appPathsInjectable);
|
||||
|
||||
return {
|
||||
channel,
|
||||
handler: () => appPaths,
|
||||
};
|
||||
return () => appPaths;
|
||||
},
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default appPathsRequestChannelListenerInjectable;
|
||||
|
||||
@ -2,25 +2,14 @@
|
||||
* 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 restartAndInstallUpdateChannel from "../../../common/application-update/restart-and-install-update-channel/restart-and-install-update-channel.injectable";
|
||||
import { messageChannelListenerInjectionToken } from "../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { restartAndInstallUpdateChannel } from "../../../common/application-update/restart-and-install-update-channel";
|
||||
import { getMessageChannelListenerInjectable } from "../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
|
||||
|
||||
const restartAndInstallUpdateListenerInjectable = getInjectable({
|
||||
id: "restart-and-install-update-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const quitAndInstall = di.inject(quitAndInstallUpdateInjectable);
|
||||
const channel = di.inject(restartAndInstallUpdateChannel);
|
||||
|
||||
return {
|
||||
channel,
|
||||
handler: quitAndInstall,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "restart",
|
||||
channel: restartAndInstallUpdateChannel,
|
||||
handler: (di) => di.inject(quitAndInstallUpdateInjectable),
|
||||
});
|
||||
|
||||
export default restartAndInstallUpdateListenerInjectable;
|
||||
|
||||
@ -7,7 +7,7 @@ import { autorun } from "mobx";
|
||||
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
||||
import setUpdateOnQuitInjectable from "../../electron-app/features/set-update-on-quit.injectable";
|
||||
import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
import type { UpdateChannel } from "../../../common/application-update/update-channels";
|
||||
import type { ReleaseChannel, UpdateChannel } from "../../../common/application-update/update-channels";
|
||||
import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable";
|
||||
|
||||
const watchIfUpdateShouldHappenOnQuitInjectable = getInjectable({
|
||||
@ -20,33 +20,26 @@ const watchIfUpdateShouldHappenOnQuitInjectable = getInjectable({
|
||||
|
||||
return getStartableStoppable("watch-if-update-should-happen-on-quit", () =>
|
||||
autorun(() => {
|
||||
const sufficientlyStableUpdateChannels =
|
||||
getSufficientlyStableUpdateChannels(selectedUpdateChannel.value.get());
|
||||
const sufficientlyStableUpdateChannels = getSufficientlyStableUpdateChannels(selectedUpdateChannel.value.get());
|
||||
const updateIsDiscoveredFromChannel = discoveredVersionState.value.get()?.updateChannel;
|
||||
|
||||
const discoveredVersion = discoveredVersionState.value.get();
|
||||
|
||||
const updateIsDiscoveredFromChannel = discoveredVersion?.updateChannel;
|
||||
|
||||
const updateOnQuit = updateIsDiscoveredFromChannel
|
||||
? sufficientlyStableUpdateChannels.includes(
|
||||
updateIsDiscoveredFromChannel,
|
||||
)
|
||||
: false;
|
||||
|
||||
setUpdateOnQuit(updateOnQuit);
|
||||
setUpdateOnQuit((
|
||||
updateIsDiscoveredFromChannel
|
||||
? sufficientlyStableUpdateChannels.includes(updateIsDiscoveredFromChannel.id)
|
||||
: false
|
||||
));
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const getSufficientlyStableUpdateChannels = (updateChannel: UpdateChannel): UpdateChannel[] => {
|
||||
const getSufficientlyStableUpdateChannels = (updateChannel: UpdateChannel): ReleaseChannel[] => {
|
||||
if (!updateChannel.moreStableUpdateChannel) {
|
||||
return [updateChannel];
|
||||
return [updateChannel.id];
|
||||
}
|
||||
|
||||
return [
|
||||
updateChannel,
|
||||
|
||||
updateChannel.id,
|
||||
...getSufficientlyStableUpdateChannels(updateChannel.moreStableUpdateChannel),
|
||||
];
|
||||
};
|
||||
|
||||
@ -2,22 +2,17 @@
|
||||
* 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 { requestChannelListenerInjectionToken } from "../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import { buildVersionChannel } from "../../common/vars/build-semantic-version.injectable";
|
||||
import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens";
|
||||
import buildVersionInjectable from "../vars/build-version/build-version.injectable";
|
||||
|
||||
const setupBuildVersionRequestChannelInjectable = getInjectable({
|
||||
id: "setup-build-version-request-channel",
|
||||
instantiate: (di) => {
|
||||
const buildVersionChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: buildVersionChannel,
|
||||
handler: (di) => {
|
||||
const buildVersion = di.inject(buildVersionInjectable);
|
||||
|
||||
return {
|
||||
channel: buildVersionChannel,
|
||||
handler: () => buildVersion.get(),
|
||||
};
|
||||
return () => buildVersion.get();
|
||||
},
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default setupBuildVersionRequestChannelInjectable;
|
||||
export default buildVersionChannelListenerInjectable;
|
||||
|
||||
@ -6,9 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execFileInjectable from "../../../common/fs/exec-file.injectable";
|
||||
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import { getErrorMessage } from "../../../common/utils/get-error-message";
|
||||
|
||||
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string>>;
|
||||
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, string>>;
|
||||
|
||||
const execHelmInjectable = getInjectable({
|
||||
id: "exec-helm",
|
||||
@ -18,15 +17,18 @@ const execHelmInjectable = getInjectable({
|
||||
const helmBinaryPath = di.inject(helmBinaryPathInjectable);
|
||||
|
||||
return async (args) => {
|
||||
try {
|
||||
const response = await execFile(helmBinaryPath, args, {
|
||||
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
|
||||
});
|
||||
const response = await execFile(helmBinaryPath, args, {
|
||||
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
|
||||
});
|
||||
|
||||
return { callWasSuccessful: true, response };
|
||||
} catch (error) {
|
||||
return { callWasSuccessful: false, error: getErrorMessage(error) };
|
||||
if (response.callWasSuccessful) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: response.error.stderr || response.error.error.message,
|
||||
};
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@ -2,25 +2,13 @@
|
||||
* 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 addHelmRepositoryChannelInjectable from "../../../../common/helm/add-helm-repository-channel.injectable";
|
||||
import { addHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel";
|
||||
import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens";
|
||||
import addHelmRepositoryInjectable from "./add-helm-repository.injectable";
|
||||
import { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
const addHelmRepositoryChannelListenerInjectable = getInjectable({
|
||||
id: "add-helm-repository-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const addHelmRepository = di.inject(addHelmRepositoryInjectable);
|
||||
const channel = di.inject(addHelmRepositoryChannelInjectable);
|
||||
|
||||
return {
|
||||
channel,
|
||||
handler: addHelmRepository,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const addHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: addHelmRepositoryChannel,
|
||||
handler: (di) => di.inject(addHelmRepositoryInjectable),
|
||||
});
|
||||
|
||||
export default addHelmRepositoryChannelListenerInjectable;
|
||||
|
||||
@ -2,25 +2,13 @@
|
||||
* 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 { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import getActiveHelmRepositoriesChannelInjectable from "../../../../common/helm/get-active-helm-repositories-channel.injectable";
|
||||
import { getActiveHelmRepositoriesChannel } from "../../../../common/helm/get-active-helm-repositories-channel";
|
||||
import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens";
|
||||
import getActiveHelmRepositoriesInjectable from "./get-active-helm-repositories.injectable";
|
||||
|
||||
const getActiveHelmRepositoriesChannelListenerInjectable = getInjectable({
|
||||
id: "get-active-helm-repositories-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const getActiveHelmRepositories = di.inject(getActiveHelmRepositoriesInjectable);
|
||||
|
||||
return {
|
||||
channel: di.inject(getActiveHelmRepositoriesChannelInjectable),
|
||||
|
||||
handler: getActiveHelmRepositories,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const getActiveHelmRepositoriesChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: getActiveHelmRepositoriesChannel,
|
||||
handler: (di) => di.inject(getActiveHelmRepositoriesInjectable),
|
||||
});
|
||||
|
||||
export default getActiveHelmRepositoriesChannelListenerInjectable;
|
||||
|
||||
@ -2,25 +2,13 @@
|
||||
* 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 { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import removeHelmRepositoryInjectable from "./remove-helm-repository.injectable";
|
||||
import removeHelmRepositoryChannelInjectable from "../../../../common/helm/remove-helm-repository-channel.injectable";
|
||||
import { removeHelmRepositoryChannel } from "../../../../common/helm/remove-helm-repository-channel";
|
||||
import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens";
|
||||
|
||||
const removeHelmRepositoryChannelListenerInjectable = getInjectable({
|
||||
id: "remove-helm-repository-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const removeHelmRepository = di.inject(removeHelmRepositoryInjectable);
|
||||
const channel = di.inject(removeHelmRepositoryChannelInjectable);
|
||||
|
||||
return {
|
||||
channel,
|
||||
handler: removeHelmRepository,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const removeHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: removeHelmRepositoryChannel,
|
||||
handler: (di) => di.inject(removeHelmRepositoryInjectable),
|
||||
});
|
||||
|
||||
export default removeHelmRepositoryChannelListenerInjectable;
|
||||
|
||||
@ -36,11 +36,8 @@ export class LocalShellSession extends ShellSession {
|
||||
}
|
||||
|
||||
public async open() {
|
||||
let env = await this.getCachedShellEnv();
|
||||
|
||||
// extensions can modify the env
|
||||
env = this.dependencies.modifyTerminalShellEnv(this.cluster.id, env);
|
||||
|
||||
const env = this.dependencies.modifyTerminalShellEnv(this.cluster.id, await this.getCachedShellEnv());
|
||||
const shell = env.PTYSHELL;
|
||||
|
||||
if (!shell) {
|
||||
|
||||
@ -17,6 +17,11 @@ import type WebSocket from "ws";
|
||||
import getDirnameOfPathInjectable from "../../../common/path/get-dirname.injectable";
|
||||
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
||||
import getBasenameOfPathInjectable from "../../../common/path/get-basename.injectable";
|
||||
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
|
||||
import spawnPtyInjectable from "../spawn-pty.injectable";
|
||||
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable";
|
||||
import appNameInjectable from "../../../common/vars/app-name.injectable";
|
||||
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
||||
|
||||
export interface OpenLocalShellSessionArgs {
|
||||
websocket: WebSocket;
|
||||
@ -34,13 +39,18 @@ const openLocalShellSessionInjectable = getInjectable({
|
||||
const dependencies: LocalShellSessionDependencies = {
|
||||
directoryForBinaries: di.inject(directoryForBinariesInjectable),
|
||||
isMac: di.inject(isMacInjectable),
|
||||
modifyTerminalShellEnv: di.inject(modifyTerminalShellEnvInjectable),
|
||||
isWindows: di.inject(isWindowsInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
userStore: di.inject(userStoreInjectable),
|
||||
resolvedShell: di.inject(resolvedShellInjectable),
|
||||
appName: di.inject(appNameInjectable),
|
||||
buildVersion: di.inject(buildVersionInjectable),
|
||||
modifyTerminalShellEnv: di.inject(modifyTerminalShellEnvInjectable),
|
||||
getDirnameOfPath: di.inject(getDirnameOfPathInjectable),
|
||||
joinPaths: di.inject(joinPathsInjectable),
|
||||
getBasenameOfPath: di.inject(getBasenameOfPathInjectable),
|
||||
computeShellEnvironment: di.inject(computeShellEnvironmentInjectable),
|
||||
spawnPty: di.inject(spawnPtyInjectable),
|
||||
};
|
||||
|
||||
return (args) => {
|
||||
|
||||
90
src/main/shell-session/local-shell-session/techincal.test.ts
Normal file
90
src/main/shell-session/local-shell-session/techincal.test.ts
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* 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 { WebSocket } from "ws";
|
||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import platformInjectable from "../../../common/vars/platform.injectable";
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
|
||||
import type { Kubectl } from "../../kubectl/kubectl";
|
||||
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
||||
import type { OpenShellSession } from "../create-shell-session.injectable";
|
||||
import type { SpawnPty } from "../spawn-pty.injectable";
|
||||
import spawnPtyInjectable from "../spawn-pty.injectable";
|
||||
import openLocalShellSessionInjectable from "./open.injectable";
|
||||
|
||||
describe("technical unit tests for local shell sessions", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({
|
||||
doGeneralOverrides: true,
|
||||
});
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
di.override(buildVersionInjectable, () => ({
|
||||
get: () => "1.1.1",
|
||||
}));
|
||||
});
|
||||
|
||||
describe("when on windows", () => {
|
||||
let openLocalShellSession: OpenShellSession;
|
||||
let spawnPtyMock: jest.MockedFunction<SpawnPty>;
|
||||
|
||||
beforeEach(() => {
|
||||
di.override(platformInjectable, () => "win32");
|
||||
|
||||
spawnPtyMock = jest.fn();
|
||||
di.override(spawnPtyInjectable, () => spawnPtyMock);
|
||||
|
||||
di.override(createKubectlInjectable, () => () => ({
|
||||
binDir: async () => "/some-kubectl-binary-dir",
|
||||
getBundledPath: () => "/some-bundled-kubectl-path",
|
||||
}) as Partial<Kubectl> as Kubectl);
|
||||
|
||||
openLocalShellSession = di.inject(openLocalShellSessionInjectable);
|
||||
});
|
||||
|
||||
describe("when opening a local shell session", () => {
|
||||
it("should pass through all environment variables to shell", async () => {
|
||||
process.env.MY_TEST_ENV_VAR = "true";
|
||||
|
||||
spawnPtyMock.mockImplementationOnce((file, args, options) => {
|
||||
expect(options.env).toMatchObject({
|
||||
MY_TEST_ENV_VAR: "true",
|
||||
});
|
||||
|
||||
return {
|
||||
cols: 80,
|
||||
rows: 40,
|
||||
pid: 12343,
|
||||
handleFlowControl: false,
|
||||
kill: jest.fn(),
|
||||
onData: jest.fn(),
|
||||
onExit: jest.fn(),
|
||||
pause: jest.fn(),
|
||||
process: "my-pty",
|
||||
resize: jest.fn(),
|
||||
resume: jest.fn(),
|
||||
write: jest.fn(),
|
||||
on: jest.fn(),
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
await openLocalShellSession({
|
||||
cluster: {
|
||||
getProxyKubeconfigPath: async () => "/some-proxy-kubeconfig",
|
||||
preferences: {},
|
||||
} as Partial<Cluster> as Cluster,
|
||||
tabId: "my-tab-id",
|
||||
websocket: new WebSocket(null),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -12,6 +12,11 @@ import isMacInjectable from "../../../common/vars/is-mac.injectable";
|
||||
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import createKubeJsonApiForClusterInjectable from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable";
|
||||
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
|
||||
import spawnPtyInjectable from "../spawn-pty.injectable";
|
||||
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable";
|
||||
import appNameInjectable from "../../../common/vars/app-name.injectable";
|
||||
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
||||
|
||||
export interface NodeShellSessionArgs {
|
||||
websocket: WebSocket;
|
||||
@ -28,7 +33,12 @@ const openNodeShellSessionInjectable = getInjectable({
|
||||
isMac: di.inject(isMacInjectable),
|
||||
isWindows: di.inject(isWindowsInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
resolvedShell: di.inject(resolvedShellInjectable),
|
||||
appName: di.inject(appNameInjectable),
|
||||
buildVersion: di.inject(buildVersionInjectable),
|
||||
createKubeJsonApiForCluster: di.inject(createKubeJsonApiForClusterInjectable),
|
||||
computeShellEnvironment: di.inject(computeShellEnvironmentInjectable),
|
||||
spawnPty: di.inject(spawnPtyInjectable),
|
||||
};
|
||||
const kubectl = createKubectl(params.cluster.version);
|
||||
const session = new NodeShellSession(dependencies, { kubectl, ...params });
|
||||
|
||||
@ -6,18 +6,18 @@
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import type { Kubectl } from "../kubectl/kubectl";
|
||||
import type WebSocket from "ws";
|
||||
import { shellEnv } from "../utils/shell-env";
|
||||
import { app } from "electron";
|
||||
import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars";
|
||||
import path from "path";
|
||||
import os, { userInfo } from "os";
|
||||
import { UserStore } from "../../common/user-store";
|
||||
import * as pty from "node-pty";
|
||||
import type * as pty from "node-pty";
|
||||
import { appEventBus } from "../../common/app-event-bus/event-bus";
|
||||
import { stat } from "fs/promises";
|
||||
import { getOrInsertWith } from "../../common/utils";
|
||||
import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { ComputeShellEnvironment } from "../utils/shell-env/compute-shell-environment.injectable";
|
||||
import type { SpawnPty } from "./spawn-pty.injectable";
|
||||
import type { InitializableState } from "../../common/initializable-state/create";
|
||||
|
||||
export class ShellOpenError extends Error {
|
||||
constructor(message: string, options?: ErrorOptions) {
|
||||
@ -107,6 +107,11 @@ export interface ShellSessionDependencies {
|
||||
readonly isWindows: boolean;
|
||||
readonly isMac: boolean;
|
||||
readonly logger: Logger;
|
||||
readonly resolvedShell: string | undefined;
|
||||
readonly appName: string;
|
||||
readonly buildVersion: InitializableState<string>;
|
||||
computeShellEnvironment: ComputeShellEnvironment;
|
||||
spawnPty: SpawnPty;
|
||||
}
|
||||
|
||||
export interface ShellSessionArgs {
|
||||
@ -148,14 +153,14 @@ export abstract class ShellSession {
|
||||
|
||||
protected abstract get cwd(): string | undefined;
|
||||
|
||||
protected ensureShellProcess(shell: string, args: string[], env: Record<string, string | undefined>, cwd: string): { shellProcess: pty.IPty; resume: boolean } {
|
||||
protected ensureShellProcess(shell: string, args: string[], env: Partial<Record<string, string>>, cwd: string): { shellProcess: pty.IPty; resume: boolean } {
|
||||
const resume = ShellSession.processes.has(this.terminalId);
|
||||
const shellProcess = getOrInsertWith(ShellSession.processes, this.terminalId, () => (
|
||||
pty.spawn(shell, args, {
|
||||
this.dependencies.spawnPty(shell, args, {
|
||||
rows: 30,
|
||||
cols: 80,
|
||||
cwd,
|
||||
env: env as Record<string, string>,
|
||||
env,
|
||||
name: "xterm-256color",
|
||||
// TODO: Something else is broken here so we need to force the use of winPty on windows
|
||||
useConpty: false,
|
||||
@ -331,19 +336,27 @@ export abstract class ShellSession {
|
||||
}
|
||||
|
||||
protected async getShellEnv() {
|
||||
const shell = UserStore.getInstance().resolvedShell;
|
||||
const env = clearKubeconfigEnvVars(JSON.parse(JSON.stringify(await shellEnv(shell || userInfo().shell))));
|
||||
const pathStr = [await this.kubectlBinDirP, ...this.getPathEntries(), process.env.PATH].join(path.delimiter);
|
||||
const shell = this.dependencies.resolvedShell || userInfo().shell;
|
||||
const result = await this.dependencies.computeShellEnvironment(shell);
|
||||
const rawEnv = (() => {
|
||||
if (result.callWasSuccessful) {
|
||||
return result.response ?? process.env;
|
||||
}
|
||||
|
||||
return process.env;
|
||||
})();
|
||||
|
||||
const env = clearKubeconfigEnvVars(JSON.parse(JSON.stringify(rawEnv)));
|
||||
const pathStr = [await this.kubectlBinDirP, ...this.getPathEntries(), env.PATH].join(path.delimiter);
|
||||
|
||||
delete env.DEBUG; // don't pass DEBUG into shells
|
||||
|
||||
if (this.dependencies.isWindows) {
|
||||
env.SystemRoot = process.env.SystemRoot;
|
||||
env.PTYSHELL = shell || "powershell.exe";
|
||||
env.PATH = pathStr;
|
||||
env.LENS_SESSION = "true";
|
||||
env.WSLENV = [
|
||||
process.env.WSLENV,
|
||||
env.WSLENV,
|
||||
"KUBECONFIG/up:LENS_SESSION/u",
|
||||
]
|
||||
.filter(Boolean)
|
||||
@ -363,8 +376,8 @@ export abstract class ShellSession {
|
||||
|
||||
env.PTYPID = process.pid.toString();
|
||||
env.KUBECONFIG = await this.kubeconfigPathP;
|
||||
env.TERM_PROGRAM = app.getName();
|
||||
env.TERM_PROGRAM_VERSION = app.getVersion();
|
||||
env.TERM_PROGRAM = this.dependencies.appName;
|
||||
env.TERM_PROGRAM_VERSION = this.dependencies.buildVersion.get();
|
||||
|
||||
if (this.cluster.preferences.httpsProxy) {
|
||||
env.HTTPS_PROXY = this.cluster.preferences.httpsProxy;
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||
import spawnPtyInjectable from "./spawn-pty.injectable";
|
||||
|
||||
export default getGlobalOverride(spawnPtyInjectable, () => () => {
|
||||
throw new Error("Tried to spawn a PTY without an override");
|
||||
});
|
||||
21
src/main/shell-session/spawn-pty.injectable.ts
Normal file
21
src/main/shell-session/spawn-pty.injectable.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 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 { IPty, IPtyForkOptions, IWindowsPtyForkOptions } from "node-pty";
|
||||
import { spawn } from "node-pty";
|
||||
|
||||
export type WindowsSpawnPtyOptions = Omit<IWindowsPtyForkOptions, "env"> & { env?: Partial<Record<string, string>> };
|
||||
export type UnixSpawnPtyOptions = Omit<IPtyForkOptions, "env"> & { env?: Partial<Record<string, string>> };
|
||||
export type SpawnPtyOptions = UnixSpawnPtyOptions | WindowsSpawnPtyOptions;
|
||||
|
||||
export type SpawnPty = (file: string, args: string[], options: SpawnPtyOptions) => IPty;
|
||||
|
||||
const spawnPtyInjectable = getInjectable({
|
||||
id: "spawn-pty",
|
||||
instantiate: () => spawn as SpawnPty,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default spawnPtyInjectable;
|
||||
@ -6,7 +6,6 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import applicationWindowStateInjectable from "./application-window-state.injectable";
|
||||
import { BrowserWindow } from "electron";
|
||||
import sendToChannelInElectronBrowserWindowInjectable from "./send-to-channel-in-electron-browser-window.injectable";
|
||||
import type { ElectronWindow } from "./create-lens-window.injectable";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
import openLinkInBrowserInjectable from "../../../../common/utils/open-link-in-browser.injectable";
|
||||
@ -45,7 +44,6 @@ const createElectronWindowInjectable = getInjectable({
|
||||
|
||||
instantiate: (di): CreateElectronWindow => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const sendToChannelInLensWindow = di.inject(sendToChannelInElectronBrowserWindowInjectable);
|
||||
const openLinkInBrowser = di.inject(openLinkInBrowserInjectable);
|
||||
|
||||
return (configuration) => {
|
||||
@ -140,7 +138,17 @@ const createElectronWindowInjectable = getInjectable({
|
||||
|
||||
show: () => browserWindow.show(),
|
||||
close: () => browserWindow.close(),
|
||||
send: (args) => sendToChannelInLensWindow(configuration.id, browserWindow, args),
|
||||
send: ({ channel, data, frameInfo }) => {
|
||||
if (frameInfo) {
|
||||
browserWindow.webContents.sendToFrame(
|
||||
[frameInfo.processId, frameInfo.frameId],
|
||||
channel,
|
||||
data,
|
||||
);
|
||||
} else {
|
||||
browserWindow.webContents.send(channel, data);
|
||||
}
|
||||
},
|
||||
|
||||
reload: () => {
|
||||
const wc = browserWindow.webContents;
|
||||
|
||||
@ -20,7 +20,7 @@ export interface ElectronWindow {
|
||||
export interface SendToViewArgs {
|
||||
channel: string;
|
||||
frameInfo?: ClusterFrameInfo;
|
||||
data?: unknown[];
|
||||
data?: unknown;
|
||||
}
|
||||
|
||||
export interface LensWindow {
|
||||
|
||||
@ -1,33 +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 { BrowserWindow } from "electron";
|
||||
import type { SendToViewArgs } from "./create-lens-window.injectable";
|
||||
|
||||
const sendToChannelInElectronBrowserWindowInjectable = getInjectable({
|
||||
id: "send-to-channel-in-electron-browser-window",
|
||||
|
||||
instantiate:
|
||||
() =>
|
||||
(
|
||||
windowId: string,
|
||||
browserWindow: BrowserWindow,
|
||||
{ channel, frameInfo, data = [] }: SendToViewArgs,
|
||||
) => {
|
||||
if (frameInfo) {
|
||||
browserWindow.webContents.sendToFrame(
|
||||
[frameInfo.processId, frameInfo.frameId],
|
||||
channel,
|
||||
...data,
|
||||
);
|
||||
} else {
|
||||
browserWindow.webContents.send(channel, ...data);
|
||||
}
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default sendToChannelInElectronBrowserWindowInjectable;
|
||||
@ -37,7 +37,7 @@ const navigateInjectable = getInjectable({
|
||||
applicationWindow.send({
|
||||
channel,
|
||||
frameInfo,
|
||||
data: [url],
|
||||
data: url,
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { IpcRendererNavigationEvents } from "../../../renderer/navigation/events";
|
||||
import currentClusterFrameInjectable from "./current-cluster-frame/current-cluster-frame.injectable";
|
||||
import getCurrentApplicationWindowInjectable from "./application-window/get-current-application-window.injectable";
|
||||
import { reloadPageChannel } from "../../../features/navigation/reload-page/common/channel";
|
||||
|
||||
const reloadCurrentApplicationWindowInjectable = getInjectable({
|
||||
id: "reload-current-application-window",
|
||||
@ -25,7 +25,7 @@ const reloadCurrentApplicationWindowInjectable = getInjectable({
|
||||
|
||||
if (frameInfo) {
|
||||
lensWindow.send({
|
||||
channel: IpcRendererNavigationEvents.RELOAD_PAGE,
|
||||
channel: reloadPageChannel.id,
|
||||
frameInfo,
|
||||
});
|
||||
} else {
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { rootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel";
|
||||
import { runManyFor } from "../../../../common/runnable/run-many-for";
|
||||
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/after-root-frame-is-ready-injection-token";
|
||||
|
||||
const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "action",
|
||||
channel: rootFrameHasRenderedChannel,
|
||||
handler: (di) => {
|
||||
const runMany = runManyFor(di);
|
||||
|
||||
return runMany(afterRootFrameIsReadyInjectionToken);
|
||||
},
|
||||
});
|
||||
|
||||
export default rootFrameRenderedChannelListenerInjectable;
|
||||
@ -1,35 +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 rootFrameRenderedChannelInjectable from "../../../../common/root-frame-rendered-channel/root-frame-rendered-channel.injectable";
|
||||
import { runManyFor } from "../../../../common/runnable/run-many-for";
|
||||
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/after-root-frame-is-ready-injection-token";
|
||||
import { messageChannelListenerInjectionToken } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
const rootFrameRenderedChannelListenerInjectable = getInjectable({
|
||||
id: "root-frame-rendered-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const channel = di.inject(rootFrameRenderedChannelInjectable);
|
||||
|
||||
const runMany = runManyFor(di);
|
||||
|
||||
const runRunnablesAfterRootFrameIsReady = runMany(
|
||||
afterRootFrameIsReadyInjectionToken,
|
||||
);
|
||||
|
||||
return {
|
||||
channel,
|
||||
|
||||
handler: async () => {
|
||||
await runRunnablesAfterRootFrameIsReady();
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default rootFrameRenderedChannelListenerInjectable;
|
||||
@ -5,11 +5,11 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import { onLoadOfApplicationInjectionToken } from "../runnable-tokens/on-load-of-application-injection-token";
|
||||
import { shellEnv } from "../../utils/shell-env";
|
||||
import os from "os";
|
||||
import { unionPATHs } from "../../../common/utils/union-env-path";
|
||||
import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable";
|
||||
import electronAppInjectable from "../../electron-app/electron-app.injectable";
|
||||
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
|
||||
|
||||
const setupShellInjectable = getInjectable({
|
||||
id: "setup-shell",
|
||||
@ -18,13 +18,24 @@ const setupShellInjectable = getInjectable({
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const isSnapPackage = di.inject(isSnapPackageInjectable);
|
||||
const electronApp = di.inject(electronAppInjectable);
|
||||
const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-shell",
|
||||
run: async () => {
|
||||
run: async (): Promise<void> => {
|
||||
logger.info("🐚 Syncing shell environment");
|
||||
|
||||
const env = await shellEnv(os.userInfo().shell);
|
||||
const result = await computeShellEnvironment(os.userInfo().shell);
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
return void logger.error(`[SHELL-SYNC]: ${result.error}`);
|
||||
}
|
||||
|
||||
const env = result.response;
|
||||
|
||||
if (!env) {
|
||||
return void logger.debug("[SHELL-SYNC]: nothing to do, env not special in shells");
|
||||
}
|
||||
|
||||
if (!env.LANG) {
|
||||
// the LANG env var expects an underscore instead of electron's dash
|
||||
|
||||
@ -6,8 +6,6 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { IpcMainEvent } from "electron";
|
||||
import ipcMainInjectable from "../ipc-main/ipc-main.injectable";
|
||||
import { enlistMessageChannelListenerInjectionToken } from "../../../../common/utils/channel/enlist-message-channel-listener-injection-token";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { tentativeParseJson } from "../../../../common/utils/tentative-parse-json";
|
||||
|
||||
const enlistMessageChannelListenerInjectable = getInjectable({
|
||||
id: "enlist-message-channel-listener-for-main",
|
||||
@ -17,11 +15,7 @@ const enlistMessageChannelListenerInjectable = getInjectable({
|
||||
|
||||
return ({ channel, handler }) => {
|
||||
const nativeOnCallback = (_: IpcMainEvent, message: unknown) => {
|
||||
pipeline(
|
||||
message,
|
||||
tentativeParseJson,
|
||||
handler,
|
||||
);
|
||||
handler(message);
|
||||
};
|
||||
|
||||
ipcMain.on(channel.id, nativeOnCallback);
|
||||
|
||||
@ -88,8 +88,8 @@ describe("enlist message channel listener in main", () => {
|
||||
expect(handlerMock).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it("given stringified object as message, when message arrives, calls the handler with the message", () => {
|
||||
onMock.mock.calls[0][1]({} as IpcMainEvent, JSON.stringify({ some: "object" }));
|
||||
it("given object as message, when message arrives, calls the handler with the message", () => {
|
||||
onMock.mock.calls[0][1]({} as IpcMainEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" });
|
||||
});
|
||||
|
||||
@ -5,20 +5,20 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { IpcMainInvokeEvent } from "electron";
|
||||
import ipcMainInjectable from "../ipc-main/ipc-main.injectable";
|
||||
import { enlistRequestChannelListenerInjectionToken } from "../../../../common/utils/channel/enlist-request-channel-listener-injection-token";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { tentativeParseJson } from "../../../../common/utils/tentative-parse-json";
|
||||
import { tentativeStringifyJson } from "../../../../common/utils/tentative-stringify-json";
|
||||
import type { Disposer } from "../../../../common/utils";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import type { RequestChannelListener } from "./listener-tokens";
|
||||
|
||||
export type EnlistRequestChannelListener = <TChannel extends RequestChannel<unknown, unknown>>(listener: RequestChannelListener<TChannel>) => Disposer;
|
||||
|
||||
const enlistRequestChannelListenerInjectable = getInjectable({
|
||||
id: "enlist-request-channel-listener-for-main",
|
||||
|
||||
instantiate: (di) => {
|
||||
instantiate: (di): EnlistRequestChannelListener => {
|
||||
const ipcMain = di.inject(ipcMainInjectable);
|
||||
|
||||
return ({ channel, handler }) => {
|
||||
const nativeHandleCallback = (_: IpcMainInvokeEvent, request: unknown) =>
|
||||
pipeline(request, tentativeParseJson, handler, tentativeStringifyJson);
|
||||
const nativeHandleCallback = (_: IpcMainInvokeEvent, request: unknown) => handler(request);
|
||||
|
||||
ipcMain.handle(channel.id, nativeHandleCallback);
|
||||
|
||||
@ -27,8 +27,6 @@ const enlistRequestChannelListenerInjectable = getInjectable({
|
||||
};
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: enlistRequestChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default enlistRequestChannelListenerInjectable;
|
||||
|
||||
@ -5,11 +5,19 @@
|
||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||
import ipcMainInjectable from "../ipc-main/ipc-main.injectable";
|
||||
import type { IpcMain, IpcMainInvokeEvent } from "electron";
|
||||
import type { EnlistRequestChannelListener } from "../../../../common/utils/channel/enlist-request-channel-listener-injection-token";
|
||||
import { enlistRequestChannelListenerInjectionToken } from "../../../../common/utils/channel/enlist-request-channel-listener-injection-token";
|
||||
import { getPromiseStatus } from "../../../../common/test-utils/get-promise-status";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import type { EnlistRequestChannelListener } from "./enlist-request-channel-listener.injectable";
|
||||
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
|
||||
import type { RequestChannelHandler } from "./listener-tokens";
|
||||
|
||||
type TestRequestChannel = RequestChannel<unknown, unknown>;
|
||||
|
||||
const testRequestChannel: TestRequestChannel = {
|
||||
id: "some-channel-id",
|
||||
};
|
||||
|
||||
describe("enlist request channel listener in main", () => {
|
||||
let enlistRequestChannelListener: EnlistRequestChannelListener;
|
||||
@ -30,20 +38,18 @@ describe("enlist request channel listener in main", () => {
|
||||
|
||||
di.override(ipcMainInjectable, () => ipcMainStub);
|
||||
|
||||
enlistRequestChannelListener = di.inject(
|
||||
enlistRequestChannelListenerInjectionToken,
|
||||
);
|
||||
enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectable);
|
||||
});
|
||||
|
||||
describe("when called", () => {
|
||||
let handlerMock: AsyncFnMock<(message: any) => any>;
|
||||
let handlerMock: AsyncFnMock<RequestChannelHandler<TestRequestChannel>>;
|
||||
let disposer: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
handlerMock = asyncFn();
|
||||
|
||||
disposer = enlistRequestChannelListener({
|
||||
channel: { id: "some-channel-id" },
|
||||
channel: testRequestChannel,
|
||||
handler: handlerMock,
|
||||
});
|
||||
});
|
||||
@ -91,7 +97,7 @@ describe("enlist request channel listener in main", () => {
|
||||
it("resolves with the response", async () => {
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe('"some-response"');
|
||||
expect(actual).toBe("some-response");
|
||||
});
|
||||
|
||||
it("when disposing the listener, de-registers the listener", () => {
|
||||
@ -106,7 +112,7 @@ describe("enlist request channel listener in main", () => {
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe("42");
|
||||
expect(actual).toBe(42);
|
||||
});
|
||||
|
||||
it("given boolean as response, when handler resolves with response, listener resolves with stringified response", async () => {
|
||||
@ -114,15 +120,15 @@ describe("enlist request channel listener in main", () => {
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe("true");
|
||||
expect(actual).toBe(true);
|
||||
});
|
||||
|
||||
it("given object as response, when handler resolves with response, listener resolves with stringified response", async () => {
|
||||
it("given object as response, when handler resolves with response, listener resolves with response", async () => {
|
||||
await handlerMock.resolve({ some: "object" });
|
||||
|
||||
const actual = await actualPromise;
|
||||
|
||||
expect(actual).toBe(JSON.stringify({ some: "object" }));
|
||||
expect(actual).toEqual({ some: "object" });
|
||||
});
|
||||
});
|
||||
|
||||
@ -138,8 +144,8 @@ describe("enlist request channel listener in main", () => {
|
||||
expect(handlerMock).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it("given stringified object as request, when request arrives, calls the handler with the request", () => {
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, JSON.stringify({ some: "object" }));
|
||||
it("given object as request, when request arrives, calls the handler with the request", () => {
|
||||
handleMock.mock.calls[0][1]({} as IpcMainInvokeEvent, { some: "object" });
|
||||
|
||||
expect(handlerMock).toHaveBeenCalledWith({ some: "object" });
|
||||
});
|
||||
|
||||
46
src/main/utils/channel/channel-listeners/listener-tokens.ts
Normal file
46
src/main/utils/channel/channel-listeners/listener-tokens.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type RequestChannelHandler<Channel> = Channel extends RequestChannel<infer Request, infer Response>
|
||||
? (req: Request) => Promise<Response> | Response
|
||||
: never;
|
||||
|
||||
export interface RequestChannelListener<Channel> {
|
||||
channel: Channel;
|
||||
handler: RequestChannelHandler<Channel>;
|
||||
}
|
||||
|
||||
|
||||
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<unknown, unknown>>>( {
|
||||
id: "request-channel-listener",
|
||||
});
|
||||
|
||||
export interface GetRequestChannelListenerInjectableInfo<
|
||||
Channel extends RequestChannel<Request, Response>,
|
||||
Request,
|
||||
Response,
|
||||
> {
|
||||
channel: Channel;
|
||||
handler: (di: DiContainerForInjection) => RequestChannelHandler<Channel>;
|
||||
}
|
||||
|
||||
export function getRequestChannelListenerInjectable<
|
||||
Channel extends RequestChannel<Request, Response>,
|
||||
Request,
|
||||
Response,
|
||||
>(info: GetRequestChannelListenerInjectableInfo<Channel, Request, Response>) {
|
||||
return getInjectable({
|
||||
id: `${info.channel.id}-listener`,
|
||||
instantiate: (di) => ({
|
||||
channel: info.channel,
|
||||
handler: info.handler(di),
|
||||
}),
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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 { disposer } from "../../../../common/utils";
|
||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
|
||||
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
|
||||
import { requestChannelListenerInjectionToken } from "./listener-tokens";
|
||||
|
||||
const listeningOnRequestChannelsInjectable = getInjectable({
|
||||
id: "listening-on-request-channels",
|
||||
instantiate: (di) => {
|
||||
const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectable);
|
||||
const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken);
|
||||
|
||||
return getStartableStoppable("listening-on-request-channels", () => {
|
||||
const seenChannels = new Set<RequestChannel<unknown, unknown>>();
|
||||
|
||||
for (const listener of requestChannelListeners) {
|
||||
if (seenChannels.has(listener.channel)) {
|
||||
throw new Error(`Tried to register a multiple channel handlers for "${listener.channel.id}", only one handler is supported for a request channel.`);
|
||||
}
|
||||
|
||||
seenChannels.add(listener.channel);
|
||||
}
|
||||
|
||||
return disposer(requestChannelListeners.map(enlistRequestChannelListener));
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default listeningOnRequestChannelsInjectable;
|
||||
@ -1,26 +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 { onLoadOfApplicationInjectionToken } from "../../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||
import listeningOfChannelsInjectable from "../../../../common/utils/channel/listening-of-channels.injectable";
|
||||
|
||||
const startListeningOfChannelsInjectable = getInjectable({
|
||||
id: "start-listening-of-channels-main",
|
||||
|
||||
instantiate: (di) => {
|
||||
const listeningOfChannels = di.inject(listeningOfChannelsInjectable);
|
||||
|
||||
return {
|
||||
id: "start-listening-of-channels-main",
|
||||
run: async () => {
|
||||
await listeningOfChannels.start();
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
export default startListeningOfChannelsInjectable;
|
||||
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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 { onLoadOfApplicationInjectionToken } from "../../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||
import listeningOnMessageChannelsInjectable from "../../../../common/utils/channel/listening-on-message-channels.injectable";
|
||||
import listeningOnRequestChannelsInjectable from "./listening-on-request-channels.injectable";
|
||||
|
||||
const startListeningOnChannelsInjectable = getInjectable({
|
||||
id: "start-listening-on-channels-main",
|
||||
|
||||
instantiate: (di) => {
|
||||
const listeningOnMessageChannels = di.inject(listeningOnMessageChannelsInjectable);
|
||||
const listeningOnRequestChannels = di.inject(listeningOnRequestChannelsInjectable);
|
||||
|
||||
return {
|
||||
id: "start-listening-on-channels-main",
|
||||
run: async () => {
|
||||
await listeningOnMessageChannels.start();
|
||||
await listeningOnRequestChannels.start();
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
export default startListeningOnChannelsInjectable;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user