Consolidate code for sending messages between processes to a window

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-05-20 14:10:14 +03:00
1 parent eb1a2488b1
commit 3d2c940a7c
4 files changed
+5 -5

No files matched your search

@@ -60,9 +60,9 @@ const createLensWindowInjectable = getInjectable({
browserWindow?.close(); browserWindow?.close();
browserWindow = undefined; browserWindow = undefined;
}, },
send: async (args: SendToViewArgs) => { send: (args: SendToViewArgs) => {
if (!browserWindow) { if (!browserWindow) {
browserWindow = await createElectronWindow(); throw new Error(`Tried to send message to window "${configuration.id}" but the window was closed`);
} }
return browserWindow.send(args); return browserWindow.send(args);
@@ -14,7 +14,7 @@ export interface SendToViewArgs {
export interface LensWindow { export interface LensWindow {
show: () => Promise<void>; show: () => Promise<void>;
close: () => void; close: () => void;
send: (args: SendToViewArgs) => Promise<void>; send: (args: SendToViewArgs) => void;
visible: boolean; visible: boolean;
} }
@@ -36,7 +36,7 @@ const navigateForExtensionInjectable = getInjectable({
(frameInfo) => frameInfo.frameId === frameId, (frameInfo) => frameInfo.frameId === frameId,
); );
await applicationWindow.send({ applicationWindow.send({
channel: "extension:navigate", channel: "extension:navigate",
frameInfo, frameInfo,
data: [extId, pageId, params], data: [extId, pageId, params],
@@ -29,7 +29,7 @@ const navigateInjectable = getInjectable({
? IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER ? IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER
: IpcRendererNavigationEvents.NAVIGATE_IN_APP; : IpcRendererNavigationEvents.NAVIGATE_IN_APP;
await applicationWindow.send({ applicationWindow.send({
channel, channel,
frameInfo, frameInfo,
data: [url], data: [url],