mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert seting cluster frame to be IPC injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1058113e90
commit
fe86b79adb
@ -3,12 +3,17 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { clusterFrameMap } from "./cluster-frames";
|
import { observable } from "mobx";
|
||||||
|
import type { ClusterId } from "./cluster-types";
|
||||||
|
|
||||||
|
export interface ClusterFrameInfo {
|
||||||
|
frameId: number;
|
||||||
|
processId: number;
|
||||||
|
}
|
||||||
|
|
||||||
const clusterFramesInjectable = getInjectable({
|
const clusterFramesInjectable = getInjectable({
|
||||||
id: "cluster-frames",
|
id: "cluster-frames",
|
||||||
instantiate: () => clusterFrameMap,
|
instantiate: () => observable.map<ClusterId, ClusterFrameInfo>(),
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default clusterFramesInjectable;
|
export default clusterFramesInjectable;
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { observable } from "mobx";
|
|
||||||
|
|
||||||
export interface ClusterFrameInfo {
|
|
||||||
frameId: number;
|
|
||||||
processId: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const clusterFrameMap = observable.map<string, ClusterFrameInfo>();
|
|
||||||
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const clusterActivateHandler = "cluster:activate";
|
export const clusterActivateHandler = "cluster:activate";
|
||||||
export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
|
||||||
export const clusterVisibilityHandler = "cluster:visibility";
|
export const clusterVisibilityHandler = "cluster:visibility";
|
||||||
export const clusterDisconnectHandler = "cluster:disconnect";
|
export const clusterDisconnectHandler = "cluster:disconnect";
|
||||||
export const clusterStates = "cluster:states";
|
export const clusterStates = "cluster:states";
|
||||||
|
|||||||
@ -9,13 +9,12 @@
|
|||||||
|
|
||||||
import { ipcMain, ipcRenderer, webContents } from "electron";
|
import { ipcMain, ipcRenderer, webContents } from "electron";
|
||||||
import { toJS } from "../utils/toJS";
|
import { toJS } from "../utils/toJS";
|
||||||
import type { ClusterFrameInfo } from "../cluster-frames";
|
|
||||||
import { clusterFrameMap } from "../cluster-frames";
|
|
||||||
import type { Disposer } from "../utils";
|
import type { Disposer } from "../utils";
|
||||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||||
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
|
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
|
||||||
import loggerInjectable from "../logger.injectable";
|
import loggerInjectable from "../logger.injectable";
|
||||||
import ipcMainInjectionToken from "./ipc-main-injection-token";
|
import ipcMainInjectionToken from "./ipc-main-injection-token";
|
||||||
|
import clusterFramesInjectable from "../cluster-frames.injectable";
|
||||||
|
|
||||||
export const broadcastMainChannel = "ipc:broadcast-main";
|
export const broadcastMainChannel = "ipc:broadcast-main";
|
||||||
|
|
||||||
@ -29,10 +28,6 @@ export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMai
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSubFrames(): ClusterFrameInfo[] {
|
|
||||||
return Array.from(clusterFrameMap.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function broadcastMessage(channel: string, ...args: any[]): Promise<void> {
|
export async function broadcastMessage(channel: string, ...args: any[]): Promise<void> {
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
return ipcRenderer.invoke(broadcastMainChannel, channel, ...args.map(sanitizePayload));
|
return ipcRenderer.invoke(broadcastMainChannel, channel, ...args.map(sanitizePayload));
|
||||||
@ -44,12 +39,13 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
|||||||
|
|
||||||
const di = getLegacyGlobalDiForExtensionApi();
|
const di = getLegacyGlobalDiForExtensionApi();
|
||||||
const logger = di.inject(loggerInjectable);
|
const logger = di.inject(loggerInjectable);
|
||||||
|
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||||
|
|
||||||
ipcMain.listeners(channel).forEach((func) => func({
|
ipcMain.listeners(channel).forEach((func) => func({
|
||||||
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
|
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
|
||||||
}, ...args));
|
}, ...args));
|
||||||
|
|
||||||
const subFrames = getSubFrames();
|
const subFrames = [...clusterFrames.values()];
|
||||||
const views = webContents.getAllWebContents();
|
const views = webContents.getAllWebContents();
|
||||||
|
|
||||||
if (!views || !Array.isArray(views) || views.length === 0) return;
|
if (!views || !Array.isArray(views) || views.length === 0) return;
|
||||||
|
|||||||
@ -10,6 +10,10 @@ export interface RequestFromChannel {
|
|||||||
<Response>(channel: RequestChannel<void, Response>): Promise<Response>;
|
<Response>(channel: RequestChannel<void, Response>): Promise<Response>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ChannelRequester<Channel> = Channel extends RequestChannel<infer Req, infer Res>
|
||||||
|
? (req: Req) => Promise<Res>
|
||||||
|
: never;
|
||||||
|
|
||||||
export const requestFromChannelInjectionToken = getInjectionToken<RequestFromChannel>({
|
export const requestFromChannelInjectionToken = getInjectionToken<RequestFromChannel>({
|
||||||
id: "request-from-request-channel",
|
id: "request-from-request-channel",
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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 { ClusterId } from "../../../../common/cluster-types";
|
||||||
|
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||||
|
|
||||||
|
export const setClusterFrameIdChannel: RequestChannel<ClusterId, void> = {
|
||||||
|
id: "set-cluster-frame-id",
|
||||||
|
};
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
|
||||||
|
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||||
|
import pushCatalogToRendererInjectable from "../../../../main/catalog-sync-to-renderer/push-catalog-to-renderer.injectable";
|
||||||
|
import { getRawRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||||
|
import { setClusterFrameIdChannel } from "../common/channel";
|
||||||
|
|
||||||
|
const handleSetClusterFrameIdInjectable = getRawRequestChannelListenerInjectable({
|
||||||
|
channel: setClusterFrameIdChannel,
|
||||||
|
handler: (di) => {
|
||||||
|
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||||
|
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||||
|
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
|
||||||
|
|
||||||
|
return (event, clusterId) => {
|
||||||
|
const cluster = getClusterById(clusterId);
|
||||||
|
|
||||||
|
if (cluster) {
|
||||||
|
clusterFrames.set(cluster.id, { frameId: event.frameId, processId: event.processId });
|
||||||
|
pushCatalogToRenderer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default handleSetClusterFrameIdInjectable;
|
||||||
@ -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 { ChannelRequester } from "../../../../common/utils/channel/request-from-channel-injection-token";
|
||||||
|
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
|
||||||
|
import { setClusterFrameIdChannel } from "../common/channel";
|
||||||
|
|
||||||
|
export type RequestSetClusterFrameId = ChannelRequester<typeof setClusterFrameIdChannel>;
|
||||||
|
|
||||||
|
const requestSetClusterFrameIdInjectable = getInjectable({
|
||||||
|
id: "request-set-cluster-frame-id",
|
||||||
|
instantiate: (di): RequestSetClusterFrameId => {
|
||||||
|
const requestFromChannel = di.inject(requestFromChannelInjectable);
|
||||||
|
|
||||||
|
return (clusterId) => requestFromChannel(setClusterFrameIdChannel, clusterId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default requestSetClusterFrameIdInjectable;
|
||||||
@ -4,40 +4,33 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { setupIpcMainHandlers } from "./setup-ipc-main-handlers";
|
import { setupIpcMainHandlers } from "./setup-ipc-main-handlers";
|
||||||
import loggerInjectable from "../../../../common/logger.injectable";
|
|
||||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||||
import { onLoadOfApplicationInjectionToken } from "../../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
import { onLoadOfApplicationInjectionToken } from "../../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||||
import applicationMenuItemCompositeInjectable from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
|
import applicationMenuItemCompositeInjectable from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
|
||||||
import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable";
|
import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable";
|
||||||
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||||
import pushCatalogToRendererInjectable from "../../../catalog-sync-to-renderer/push-catalog-to-renderer.injectable";
|
import clusterFramesInjectable from "../../../../common/cluster-frames.injectable";
|
||||||
|
import prefixedLoggerInjectable from "../../../../common/logger/prefixed-logger.injectable";
|
||||||
|
|
||||||
const setupIpcMainHandlersInjectable = getInjectable({
|
const setupIpcMainHandlersInjectable = getInjectable({
|
||||||
id: "setup-ipc-main-handlers",
|
id: "setup-ipc-main-handlers",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => ({
|
||||||
const logger = di.inject(loggerInjectable);
|
id: "setup-ipc-main-handlers",
|
||||||
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
|
run: () => {
|
||||||
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
|
const logger = di.inject(prefixedLoggerInjectable, "APP-MAIN");
|
||||||
const clusterStore = di.inject(clusterStoreInjectable);
|
|
||||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
|
||||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
|
||||||
|
|
||||||
return {
|
logger.debug("initializing ipc main handlers");
|
||||||
id: "setup-ipc-main-handlers",
|
|
||||||
run: () => {
|
|
||||||
logger.debug("[APP-MAIN] initializing ipc main handlers");
|
|
||||||
|
|
||||||
setupIpcMainHandlers({
|
setupIpcMainHandlers({
|
||||||
applicationMenuItemComposite,
|
applicationMenuItemComposite: di.inject(applicationMenuItemCompositeInjectable),
|
||||||
pushCatalogToRenderer,
|
clusterStore: di.inject(clusterStoreInjectable),
|
||||||
clusterStore,
|
emitAppEvent: di.inject(emitAppEventInjectable),
|
||||||
emitAppEvent,
|
getClusterById: di.inject(getClusterByIdInjectable),
|
||||||
getClusterById,
|
clusterFrameMap: di.inject(clusterFramesInjectable),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
}),
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: onLoadOfApplicationInjectionToken,
|
injectionToken: onLoadOfApplicationInjectionToken,
|
||||||
causesSideEffects: true,
|
causesSideEffects: true,
|
||||||
|
|||||||
@ -2,14 +2,12 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import type { IpcMainInvokeEvent } from "electron";
|
|
||||||
import { BrowserWindow, Menu } from "electron";
|
import { BrowserWindow, Menu } from "electron";
|
||||||
import { clusterFrameMap } from "../../../../common/cluster-frames";
|
import { clusterActivateHandler, clusterDisconnectHandler, clusterStates } from "../../../../common/ipc/cluster";
|
||||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterDisconnectHandler, clusterStates } from "../../../../common/ipc/cluster";
|
|
||||||
import type { ClusterId } from "../../../../common/cluster-types";
|
import type { ClusterId } from "../../../../common/cluster-types";
|
||||||
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
||||||
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue, ObservableMap } from "mobx";
|
||||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
|
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
|
||||||
import { handleWindowAction, onLocationChange } from "../../../ipc/window";
|
import { handleWindowAction, onLocationChange } from "../../../ipc/window";
|
||||||
import type { ApplicationMenuItemTypes } from "../../../../features/application-menu/main/menu-items/application-menu-item-injection-token";
|
import type { ApplicationMenuItemTypes } from "../../../../features/application-menu/main/menu-items/application-menu-item-injection-token";
|
||||||
@ -18,12 +16,13 @@ import { getApplicationMenuTemplate } from "../../../../features/application-men
|
|||||||
import type { MenuItemRoot } from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
|
import type { MenuItemRoot } from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
|
||||||
import type { EmitAppEvent } from "../../../../common/app-event-bus/emit-event.injectable";
|
import type { EmitAppEvent } from "../../../../common/app-event-bus/emit-event.injectable";
|
||||||
import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable";
|
import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable";
|
||||||
|
import type { ClusterFrameInfo } from "../../../../common/cluster-frames.injectable";
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
applicationMenuItemComposite: IComputedValue<Composite<ApplicationMenuItemTypes | MenuItemRoot>>;
|
applicationMenuItemComposite: IComputedValue<Composite<ApplicationMenuItemTypes | MenuItemRoot>>;
|
||||||
clusterStore: ClusterStore;
|
clusterStore: ClusterStore;
|
||||||
emitAppEvent: EmitAppEvent;
|
emitAppEvent: EmitAppEvent;
|
||||||
getClusterById: GetClusterById;
|
getClusterById: GetClusterById;
|
||||||
pushCatalogToRenderer: () => void;
|
clusterFrameMap: ObservableMap<ClusterId, ClusterFrameInfo>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setupIpcMainHandlers = ({
|
export const setupIpcMainHandlers = ({
|
||||||
@ -31,22 +30,13 @@ export const setupIpcMainHandlers = ({
|
|||||||
clusterStore,
|
clusterStore,
|
||||||
emitAppEvent,
|
emitAppEvent,
|
||||||
getClusterById,
|
getClusterById,
|
||||||
pushCatalogToRenderer,
|
clusterFrameMap,
|
||||||
}: Dependencies) => {
|
}: Dependencies) => {
|
||||||
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
||||||
return getClusterById(clusterId)
|
return getClusterById(clusterId)
|
||||||
?.activate(force);
|
?.activate(force);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMainHandle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
|
||||||
const cluster = getClusterById(clusterId);
|
|
||||||
|
|
||||||
if (cluster) {
|
|
||||||
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
|
|
||||||
pushCatalogToRenderer();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainHandle(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
ipcMainHandle(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
||||||
emitAppEvent({ name: "cluster", action: "stop" });
|
emitAppEvent({ name: "cluster", action: "stop" });
|
||||||
const cluster = getClusterById(clusterId);
|
const cluster = getClusterById(clusterId);
|
||||||
|
|||||||
@ -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 type { Disposer } from "../../../../common/utils";
|
||||||
|
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||||
|
import type { RawRequestChannelListener } from "./listener-tokens";
|
||||||
|
import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token";
|
||||||
|
|
||||||
|
export type EnlistRawRequestChannelListener = <TChannel extends RequestChannel<unknown, unknown>>(listener: RawRequestChannelListener<TChannel>) => Disposer;
|
||||||
|
|
||||||
|
const enlistRawRequestChannelListenerInjectable = getInjectable({
|
||||||
|
id: "enlist-raw-request-channel-listener-for-main",
|
||||||
|
|
||||||
|
instantiate: (di): EnlistRawRequestChannelListener => {
|
||||||
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
|
|
||||||
|
return ({ channel, handler }) => {
|
||||||
|
ipcMain.handle(channel.id, handler);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
ipcMain.off(channel.id, handler);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default enlistRawRequestChannelListenerInjectable;
|
||||||
@ -5,22 +5,36 @@
|
|||||||
|
|
||||||
import type { DiContainerForInjection } from "@ogre-tools/injectable";
|
import type { DiContainerForInjection } from "@ogre-tools/injectable";
|
||||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
import type { IpcMainInvokeEvent } from "electron";
|
||||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||||
|
|
||||||
export type RequestChannelHandler<Channel> = Channel extends RequestChannel<infer Request, infer Response>
|
export type RequestChannelHandler<Channel> = Channel extends RequestChannel<infer Request, infer Response>
|
||||||
? (req: Request) => Promise<Response> | Response
|
? (req: Request) => Promise<Response> | Response
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
|
export type RawRequestChannelHandler<Channel> = Channel extends RequestChannel<infer Request, infer Response>
|
||||||
|
? (event: IpcMainInvokeEvent, req: Request) => Promise<Response> | Response
|
||||||
|
: never;
|
||||||
|
|
||||||
export interface RequestChannelListener<Channel> {
|
export interface RequestChannelListener<Channel> {
|
||||||
channel: Channel;
|
channel: Channel;
|
||||||
handler: RequestChannelHandler<Channel>;
|
handler: RequestChannelHandler<Channel>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RawRequestChannelListener<Channel> {
|
||||||
|
channel: Channel;
|
||||||
|
handler: RawRequestChannelHandler<Channel>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<unknown, unknown>>>( {
|
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<unknown, unknown>>>( {
|
||||||
id: "request-channel-listener",
|
id: "request-channel-listener",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const rawRequestChannelListenerInjectionToken = getInjectionToken<RawRequestChannelListener<RequestChannel<unknown, unknown>>>( {
|
||||||
|
id: "raw-request-channel-listener",
|
||||||
|
});
|
||||||
|
|
||||||
export interface GetRequestChannelListenerInjectableInfo<
|
export interface GetRequestChannelListenerInjectableInfo<
|
||||||
Channel extends RequestChannel<Request, Response>,
|
Channel extends RequestChannel<Request, Response>,
|
||||||
Request,
|
Request,
|
||||||
@ -44,3 +58,27 @@ export function getRequestChannelListenerInjectable<
|
|||||||
injectionToken: requestChannelListenerInjectionToken,
|
injectionToken: requestChannelListenerInjectionToken,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GeRawtRequestChannelListenerInjectableInfo<
|
||||||
|
Channel extends RequestChannel<Request, Response>,
|
||||||
|
Request,
|
||||||
|
Response,
|
||||||
|
> {
|
||||||
|
channel: Channel;
|
||||||
|
handler: (di: DiContainerForInjection) => RawRequestChannelHandler<Channel>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRawRequestChannelListenerInjectable<
|
||||||
|
Channel extends RequestChannel<Request, Response>,
|
||||||
|
Request,
|
||||||
|
Response,
|
||||||
|
>(info: GeRawtRequestChannelListenerInjectableInfo<Channel, Request, Response>) {
|
||||||
|
return getInjectable({
|
||||||
|
id: `${info.channel.id}-listener`,
|
||||||
|
instantiate: (di) => ({
|
||||||
|
channel: info.channel,
|
||||||
|
handler: info.handler(di),
|
||||||
|
}),
|
||||||
|
injectionToken: rawRequestChannelListenerInjectionToken,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@ -6,19 +6,22 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import { disposer } from "../../../../common/utils";
|
import { disposer } from "../../../../common/utils";
|
||||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||||
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
|
||||||
|
import enlistRawRequestChannelListenerInjectable from "./enlist-raw-request-channel-listener.injectable";
|
||||||
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
|
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
|
||||||
import { requestChannelListenerInjectionToken } from "./listener-tokens";
|
import { rawRequestChannelListenerInjectionToken, requestChannelListenerInjectionToken } from "./listener-tokens";
|
||||||
|
|
||||||
const listeningOnRequestChannelsInjectable = getInjectable({
|
const listeningOnRequestChannelsInjectable = getInjectable({
|
||||||
id: "listening-on-request-channels",
|
id: "listening-on-request-channels",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectable);
|
const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectable);
|
||||||
|
const enlistRawRequestChannelListener = di.inject(enlistRawRequestChannelListenerInjectable);
|
||||||
const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken);
|
const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken);
|
||||||
|
const rawRequestChannelListeners = di.injectMany(rawRequestChannelListenerInjectionToken);
|
||||||
|
|
||||||
return getStartableStoppable("listening-on-request-channels", () => {
|
return getStartableStoppable("listening-on-request-channels", () => {
|
||||||
const seenChannels = new Set<RequestChannel<unknown, unknown>>();
|
const seenChannels = new Set<RequestChannel<unknown, unknown>>();
|
||||||
|
|
||||||
for (const listener of requestChannelListeners) {
|
for (const listener of [...requestChannelListeners, ...rawRequestChannelListeners]) {
|
||||||
if (seenChannels.has(listener.channel)) {
|
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.`);
|
throw new Error(`Tried to register a multiple channel handlers for "${listener.channel.id}", only one handler is supported for a request channel.`);
|
||||||
}
|
}
|
||||||
@ -26,7 +29,10 @@ const listeningOnRequestChannelsInjectable = getInjectable({
|
|||||||
seenChannels.add(listener.channel);
|
seenChannels.add(listener.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return disposer(requestChannelListeners.map(enlistRequestChannelListener));
|
return disposer(
|
||||||
|
requestChannelListeners.map(enlistRequestChannelListener),
|
||||||
|
rawRequestChannelListeners.map(enlistRawRequestChannelListener),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import showErrorNotificationInjectable from "../../components/notifications/show
|
|||||||
import autoInitExtensionsInjectable from "../../../features/extensions/loader/common/auto-init-extensions.injectable";
|
import autoInitExtensionsInjectable from "../../../features/extensions/loader/common/auto-init-extensions.injectable";
|
||||||
import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.injectable";
|
import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.injectable";
|
||||||
import { when } from "mobx";
|
import { when } from "mobx";
|
||||||
import { requestSetClusterFrameId } from "../../ipc";
|
import requestSetClusterFrameIdInjectable from "../../../features/cluster/frame-id/renderer/request-set-frame-id.injectable";
|
||||||
|
|
||||||
const initClusterFrameInjectable = getInjectable({
|
const initClusterFrameInjectable = getInjectable({
|
||||||
id: "init-cluster-frame",
|
id: "init-cluster-frame",
|
||||||
@ -28,6 +28,7 @@ const initClusterFrameInjectable = getInjectable({
|
|||||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||||
const logger = di.inject(prefixedLoggerInjectable, "CLUSTER-FRAME");
|
const logger = di.inject(prefixedLoggerInjectable, "CLUSTER-FRAME");
|
||||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||||
|
const requestSetClusterFrameId = di.inject(requestSetClusterFrameIdInjectable);
|
||||||
|
|
||||||
return async (unmountRoot: () => void) => {
|
return async (unmountRoot: () => void) => {
|
||||||
// TODO: Make catalogEntityRegistry already initialized when passed as dependency
|
// TODO: Make catalogEntityRegistry already initialized when passed as dependency
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { clusterActivateHandler, clusterDisconnectHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/ipc/cluster";
|
import { clusterActivateHandler, clusterDisconnectHandler, clusterStates } from "../../common/ipc/cluster";
|
||||||
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
||||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
||||||
import { toJS } from "../utils";
|
import { toJS } from "../utils";
|
||||||
@ -39,10 +39,6 @@ export function requestWindowAction(type: WindowAction): Promise<void> {
|
|||||||
return requestMain(windowActionHandleChannel, type);
|
return requestMain(windowActionHandleChannel, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestSetClusterFrameId(clusterId: ClusterId): Promise<void> {
|
|
||||||
return requestMain(clusterSetFrameIdHandler, clusterId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function requestClusterActivation(clusterId: ClusterId, force?: boolean): Promise<void> {
|
export function requestClusterActivation(clusterId: ClusterId, force?: boolean): Promise<void> {
|
||||||
return requestMain(clusterActivateHandler, clusterId, force);
|
return requestMain(clusterActivateHandler, clusterId, force);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user