bitwarden-estensione-browser/apps/desktop/src/platform/utils/from-ipc-messaging.ts

16 lines
589 B
TypeScript

import { fromEventPattern, share } from "rxjs";
import { Message } from "@bitwarden/common/platform/messaging";
import { tagAsExternal } from "@bitwarden/common/platform/messaging/internal";
/**
* Creates an observable that when subscribed to will listen to messaging events through IPC.
* @returns An observable stream of messages.
*/
export const fromIpcMessaging = () => {
return fromEventPattern<Message<object>>(
(handler) => ipc.platform.onMessage.addListener(handler),
(handler) => ipc.platform.onMessage.removeListener(handler),
).pipe(tagAsExternal, share());
};