mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce abstraction for publishing and subscribing between processes
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
f838a4eab5
commit
439d74adae
10 files changed
+477
No files matched your search
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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 { publishToChannelInjectionToken } from "../../common/communication-between-processes/publish-to-channel-injection-token";
|
||||
import ipcRendererInjectable from "../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
const publishToChannelInjectable = getInjectable({
|
||||
id: "publish-to-channel",
|
||||
|
||||
instantiate: (di) => {
|
||||
const ipcRenderer = di.inject(ipcRendererInjectable);
|
||||
|
||||
return (channel, message) => {
|
||||
ipcRenderer.send(channel.name, message);
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: publishToChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default publishToChannelInjectable;
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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 { subscribeToChannelInjectionToken } from "../../common/communication-between-processes/subscribe-to-channel-injection-token";
|
||||
import type { Channel } from "../../common/ipc-channel/channel";
|
||||
import ipcRendererInjectable from "../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
const subscribeToChannelInjectable = getInjectable({
|
||||
id: "subscribe-to-channel",
|
||||
|
||||
instantiate: (di) => {
|
||||
const ipcRenderer = di.inject(ipcRendererInjectable);
|
||||
|
||||
return <TChannel extends Channel<TMessage>, TMessage>(channel: TChannel, callback: (message: TChannel["_template"]) => void) => {
|
||||
ipcRenderer.on(channel.name, (nonUsedNativeEvent, message: unknown) => {
|
||||
const channelMessage = message as TChannel["_template"];
|
||||
|
||||
return callback(channelMessage);
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: subscribeToChannelInjectionToken,
|
||||
});
|
||||
|
||||
export default subscribeToChannelInjectable;
|
||||
Reference in new issue
Block a user