mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert request catalog entity reg state to injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
a1592ce2a5
commit
b0e2660dfa
@ -7,8 +7,3 @@
|
|||||||
* This is used to activate a specific entity in the renderer main frame
|
* This is used to activate a specific entity in the renderer main frame
|
||||||
*/
|
*/
|
||||||
export const catalogEntityRunListener = "catalog-entity:run";
|
export const catalogEntityRunListener = "catalog-entity:run";
|
||||||
|
|
||||||
/**
|
|
||||||
* This can be sent from renderer to main to initialize a broadcast of ITEMS
|
|
||||||
*/
|
|
||||||
export const catalogInitChannel = "catalog:init";
|
|
||||||
|
|||||||
@ -9,3 +9,7 @@ import type { MessageChannel } from "../../../../common/utils/channel/message-ch
|
|||||||
export const currentCatalogEntityRegistryStateChannel: MessageChannel<(CatalogEntityData & CatalogEntityKindData)[]> = {
|
export const currentCatalogEntityRegistryStateChannel: MessageChannel<(CatalogEntityData & CatalogEntityKindData)[]> = {
|
||||||
id: "current-catalog-entity-registry-state",
|
id: "current-catalog-entity-registry-state",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const requestCatalogEntityRegistryStateToBeSentChannel: MessageChannel<void> = {
|
||||||
|
id: "request-catalog-entity-registry-state-to-be-sent",
|
||||||
|
};
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { toJS } from "../../../../common/utils";
|
||||||
|
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||||
|
import catalogEntityRegistryInjectable from "../../../../main/catalog/entity-registry.injectable";
|
||||||
|
import { requestCatalogEntityRegistryStateToBeSentChannel } from "../common/channel";
|
||||||
|
import broadcastCurrentCatalogEntityRegistryStateInjectable from "./broadcast.injectable";
|
||||||
|
|
||||||
|
const requestForCurrentCatalogEntityStateToBeSentListenerInjectable = getMessageChannelListenerInjectable({
|
||||||
|
id: "main",
|
||||||
|
channel: requestCatalogEntityRegistryStateToBeSentChannel,
|
||||||
|
handler: (di) => {
|
||||||
|
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||||
|
const broadcastCurrentCatalogEntityRegistryState = di.inject(broadcastCurrentCatalogEntityRegistryStateInjectable);
|
||||||
|
|
||||||
|
return () => broadcastCurrentCatalogEntityRegistryState(toJS(catalogEntityRegistry.items));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default requestForCurrentCatalogEntityStateToBeSentListenerInjectable;
|
||||||
@ -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 { sendMessageToChannelInjectionToken } from "../../../../common/utils/channel/message-to-channel-injection-token";
|
||||||
|
import { beforeFrameStartsSecondInjectionToken } from "../../../../renderer/before-frame-starts/tokens";
|
||||||
|
import { requestCatalogEntityRegistryStateToBeSentChannel } from "../common/channel";
|
||||||
|
import startListeningOfChannelsInjectable from "../../../../renderer/utils/channel/channel-listeners/start-listening-of-channels.injectable";
|
||||||
|
|
||||||
|
const requestCatalogEntityRegistryStateToBeSentInjectable = getInjectable({
|
||||||
|
id: "request-catalog-entity-registry-state-to-be-sent",
|
||||||
|
instantiate: (di) => ({
|
||||||
|
id: "request-catalog-entity-registry-state-to-be-sent",
|
||||||
|
run: () => {
|
||||||
|
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
|
||||||
|
|
||||||
|
sendMessageToChannel(requestCatalogEntityRegistryStateToBeSentChannel);
|
||||||
|
},
|
||||||
|
runAfter: di.inject(startListeningOfChannelsInjectable),
|
||||||
|
}),
|
||||||
|
injectionToken: beforeFrameStartsSecondInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default requestCatalogEntityRegistryStateToBeSentInjectable;
|
||||||
@ -4,9 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
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 { toJS } from "../../common/utils";
|
||||||
import { catalogInitChannel } from "../../common/ipc/catalog";
|
|
||||||
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 broadcastCurrentCatalogEntityRegistryStateInjectable from "../../features/catalog/entities-sync/main/broadcast.injectable";
|
import broadcastCurrentCatalogEntityRegistryStateInjectable from "../../features/catalog/entities-sync/main/broadcast.injectable";
|
||||||
@ -16,25 +14,15 @@ const catalogSyncToRendererInjectable = getInjectable({
|
|||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||||
const ipcMain = di.inject(ipcMainInjectionToken);
|
|
||||||
const broadcastCurrentCatalogEntityRegistryState = di.inject(broadcastCurrentCatalogEntityRegistryStateInjectable);
|
const broadcastCurrentCatalogEntityRegistryState = di.inject(broadcastCurrentCatalogEntityRegistryStateInjectable);
|
||||||
|
|
||||||
return getStartableStoppable(
|
return getStartableStoppable(
|
||||||
"catalog-sync",
|
"catalog-sync",
|
||||||
() => {
|
() => reaction(() => toJS(catalogEntityRegistry.items), (items) => {
|
||||||
const initChannelHandler = () => broadcastCurrentCatalogEntityRegistryState(toJS(catalogEntityRegistry.items));
|
broadcastCurrentCatalogEntityRegistryState(items);
|
||||||
|
}, {
|
||||||
ipcMain.on(catalogInitChannel, initChannelHandler);
|
fireImmediately: true,
|
||||||
|
}),
|
||||||
return disposer(
|
|
||||||
() => ipcMain.off(catalogInitChannel, initChannelHandler),
|
|
||||||
reaction(() => toJS(catalogEntityRegistry.items), (items) => {
|
|
||||||
broadcastCurrentCatalogEntityRegistryState(items);
|
|
||||||
}, {
|
|
||||||
fireImmediately: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,8 +11,7 @@ import { iter } from "../../../utils";
|
|||||||
import type { Disposer } from "../../../utils";
|
import type { Disposer } from "../../../utils";
|
||||||
import { once } from "lodash";
|
import { once } from "lodash";
|
||||||
import { CatalogRunEvent } from "../../../../common/catalog/catalog-run-event";
|
import { CatalogRunEvent } from "../../../../common/catalog/catalog-run-event";
|
||||||
import { ipcRenderer } from "electron";
|
import { catalogEntityRunListener } from "../../../../common/ipc/catalog";
|
||||||
import { catalogInitChannel, catalogEntityRunListener } from "../../../../common/ipc/catalog";
|
|
||||||
import { isMainFrame } from "process";
|
import { isMainFrame } from "process";
|
||||||
import type { Navigate } from "../../../navigation/navigate.injectable";
|
import type { Navigate } from "../../../navigation/navigate.injectable";
|
||||||
import type { Logger } from "../../../../common/logger";
|
import type { Logger } from "../../../../common/logger";
|
||||||
@ -83,9 +82,6 @@ export class CatalogEntityRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// Make sure that we get items ASAP and not the next time one of them changes
|
|
||||||
ipcRenderer.send(catalogInitChannel);
|
|
||||||
|
|
||||||
if (isMainFrame) {
|
if (isMainFrame) {
|
||||||
ipcRendererOn(catalogEntityRunListener, (event, id: string) => {
|
ipcRendererOn(catalogEntityRunListener, (event, id: string) => {
|
||||||
const entity = this.getById(id);
|
const entity = this.getById(id);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user