mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce ipcMainInjectionToken (#6950)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
40918cf582
commit
cf27605a21
12
src/common/ipc/ipc-main-injection-token.ts
Normal file
12
src/common/ipc/ipc-main-injection-token.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 { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
import type { IpcMain } from "electron";
|
||||||
|
|
||||||
|
const ipcMainInjectionToken = getInjectionToken<IpcMain>({
|
||||||
|
id: "ipc-main-injection-token",
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ipcMainInjectionToken;
|
||||||
@ -12,17 +12,17 @@ import { toJS } from "../utils/toJS";
|
|||||||
import type { ClusterFrameInfo } from "../cluster-frames";
|
import type { ClusterFrameInfo } from "../cluster-frames";
|
||||||
import { clusterFrameMap } from "../cluster-frames";
|
import { clusterFrameMap } from "../cluster-frames";
|
||||||
import type { Disposer } from "../utils";
|
import type { Disposer } from "../utils";
|
||||||
import ipcMainInjectable from "../../main/utils/channel/ipc-main/ipc-main.injectable";
|
|
||||||
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";
|
||||||
|
|
||||||
export const broadcastMainChannel = "ipc:broadcast-main";
|
export const broadcastMainChannel = "ipc:broadcast-main";
|
||||||
|
|
||||||
export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) {
|
export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) {
|
||||||
const di = getLegacyGlobalDiForExtensionApi();
|
const di = getLegacyGlobalDiForExtensionApi();
|
||||||
|
|
||||||
const ipcMain = di.inject(ipcMainInjectable);
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
|
|
||||||
ipcMain.handle(channel, async (event, ...args) => {
|
ipcMain.handle(channel, async (event, ...args) => {
|
||||||
return sanitizePayload(await listener(event, ...args));
|
return sanitizePayload(await listener(event, ...args));
|
||||||
@ -90,7 +90,7 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
|||||||
export function ipcMainOn(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): Disposer {
|
export function ipcMainOn(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): Disposer {
|
||||||
const di = getLegacyGlobalDiForExtensionApi();
|
const di = getLegacyGlobalDiForExtensionApi();
|
||||||
|
|
||||||
const ipcMain = di.inject(ipcMainInjectable);
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
|
|
||||||
ipcMain.on(channel, listener);
|
ipcMain.on(channel, listener);
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
|
import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token";
|
||||||
import { catalogInitChannel } from "../../common/ipc/catalog";
|
import { catalogInitChannel } from "../../common/ipc/catalog";
|
||||||
import { disposer, toJS } from "../../common/utils";
|
import { disposer, toJS } from "../../common/utils";
|
||||||
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable";
|
||||||
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
|
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
|
||||||
import ipcMainInjectable from "../utils/channel/ipc-main/ipc-main.injectable";
|
|
||||||
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
|
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
|
||||||
|
|
||||||
const catalogSyncToRendererInjectable = getInjectable({
|
const catalogSyncToRendererInjectable = getInjectable({
|
||||||
@ -16,7 +16,7 @@ const catalogSyncToRendererInjectable = getInjectable({
|
|||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||||
const ipcMain = di.inject(ipcMainInjectable);
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
const catalogSyncBroadcaster = di.inject(catalogSyncBroadcasterInjectable);
|
const catalogSyncBroadcaster = di.inject(catalogSyncBroadcasterInjectable);
|
||||||
|
|
||||||
return getStartableStoppable(
|
return getStartableStoppable(
|
||||||
|
|||||||
@ -3,15 +3,15 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token";
|
||||||
import { bundledExtensionsLoaded } from "../../../../common/ipc/extension-handling";
|
import { bundledExtensionsLoaded } from "../../../../common/ipc/extension-handling";
|
||||||
import { delay } from "../../../../common/utils";
|
import { delay } from "../../../../common/utils";
|
||||||
import ipcMainInjectable from "../../../utils/channel/ipc-main/ipc-main.injectable";
|
|
||||||
|
|
||||||
const waitUntilBundledExtensionsAreLoadedInjectable = getInjectable({
|
const waitUntilBundledExtensionsAreLoadedInjectable = getInjectable({
|
||||||
id: "wait-until-bundled-extensions-are-loaded",
|
id: "wait-until-bundled-extensions-are-loaded",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const ipcMain = di.inject(ipcMainInjectable);
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
const viewHasLoaded = new Promise<void>((resolve) => {
|
const viewHasLoaded = new Promise<void>((resolve) => {
|
||||||
|
|||||||
@ -4,14 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { IpcMainEvent } from "electron";
|
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 { enlistMessageChannelListenerInjectionToken } from "../../../../common/utils/channel/enlist-message-channel-listener-injection-token";
|
||||||
|
import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token";
|
||||||
|
|
||||||
const enlistMessageChannelListenerInjectable = getInjectable({
|
const enlistMessageChannelListenerInjectable = getInjectable({
|
||||||
id: "enlist-message-channel-listener-for-main",
|
id: "enlist-message-channel-listener-for-main",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const ipcMain = di.inject(ipcMainInjectable);
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
|
|
||||||
return ({ channel, handler }) => {
|
return ({ channel, handler }) => {
|
||||||
const nativeOnCallback = (_: IpcMainEvent, message: unknown) => {
|
const nativeOnCallback = (_: IpcMainEvent, message: unknown) => {
|
||||||
|
|||||||
@ -4,10 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { IpcMainInvokeEvent } from "electron";
|
import type { IpcMainInvokeEvent } from "electron";
|
||||||
import ipcMainInjectable from "../ipc-main/ipc-main.injectable";
|
|
||||||
import type { Disposer } from "../../../../common/utils";
|
import type { 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 type { RequestChannelListener } from "./listener-tokens";
|
import type { RequestChannelListener } from "./listener-tokens";
|
||||||
|
import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token";
|
||||||
|
|
||||||
export type EnlistRequestChannelListener = <TChannel extends RequestChannel<unknown, unknown>>(listener: RequestChannelListener<TChannel>) => Disposer;
|
export type EnlistRequestChannelListener = <TChannel extends RequestChannel<unknown, unknown>>(listener: RequestChannelListener<TChannel>) => Disposer;
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ const enlistRequestChannelListenerInjectable = getInjectable({
|
|||||||
id: "enlist-request-channel-listener-for-main",
|
id: "enlist-request-channel-listener-for-main",
|
||||||
|
|
||||||
instantiate: (di): EnlistRequestChannelListener => {
|
instantiate: (di): EnlistRequestChannelListener => {
|
||||||
const ipcMain = di.inject(ipcMainInjectable);
|
const ipcMain = di.inject(ipcMainInjectionToken);
|
||||||
|
|
||||||
return ({ channel, handler }) => {
|
return ({ channel, handler }) => {
|
||||||
const nativeHandleCallback = (_: IpcMainInvokeEvent, request: unknown) => handler(request);
|
const nativeHandleCallback = (_: IpcMainInvokeEvent, request: unknown) => handler(request);
|
||||||
|
|||||||
@ -4,11 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
|
import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token";
|
||||||
|
|
||||||
const ipcMainInjectable = getInjectable({
|
const ipcMainInjectable = getInjectable({
|
||||||
id: "ipc-main",
|
id: "ipc-main",
|
||||||
instantiate: () => ipcMain,
|
instantiate: () => ipcMain,
|
||||||
causesSideEffects: true,
|
causesSideEffects: true,
|
||||||
|
injectionToken: ipcMainInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default ipcMainInjectable;
|
export default ipcMainInjectable;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user