Switch to more specific IPC helpers (#2821)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-06-10 10:34:22 -04:00
1 parent a12cb0a16e
commit 280af6391e
18 files changed
+191 -178

No files matched your search

+3 -4
View File
@@ -26,7 +26,7 @@ import fse from "fs-extra";
import { observable, reaction, when, makeObservable } from "mobx";
import os from "os";
import path from "path";
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
import { broadcastMessage, ipcMainHandle, ipcRendererOn, requestMain } from "../common/ipc";
import { Singleton, toJS } from "../common/utils";
import logger from "../main/logger";
import { ExtensionInstallationStateStore } from "../renderer/components/+extensions/extension-install.store";
@@ -34,7 +34,6 @@ import { extensionInstaller } from "./extension-installer";
import { ExtensionsStore } from "./extensions-store";
import { ExtensionLoader } from "./extension-loader";
import type { LensExtensionId, LensExtensionManifest } from "./lens-extension";
import type { PackageJson } from "type-fest";
import semver from "semver";
import { appSemVer } from "../common/vars";
import { isProduction } from "../common/vars";
@@ -144,13 +143,13 @@ export class ExtensionDiscovery extends Singleton {
};
requestMain(ExtensionDiscovery.extensionDiscoveryChannel).then(onMessage);
subscribeToBroadcast(ExtensionDiscovery.extensionDiscoveryChannel, (_event, message: ExtensionDiscoveryChannelMessage) => {
ipcRendererOn(ExtensionDiscovery.extensionDiscoveryChannel, (_event, message: ExtensionDiscoveryChannelMessage) => {
onMessage(message);
});
}
async initMain(): Promise<void> {
handleRequest(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
ipcMainHandle(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
reaction(() => this.toJSON(), () => {
this.broadcast();
+4 -4
View File
@@ -25,7 +25,7 @@ import { isEqual } from "lodash";
import { action, computed, makeObservable, observable, reaction, when } from "mobx";
import path from "path";
import { getHostedCluster } from "../common/cluster-store";
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../common/ipc";
import { Disposer, Singleton, toJS } from "../common/utils";
import logger from "../main/logger";
import type { InstalledExtension } from "./extension-discovery";
@@ -174,11 +174,11 @@ export class ExtensionLoader extends Singleton {
this.isLoaded = true;
this.loadOnMain();
handleRequest(ExtensionLoader.extensionsMainChannel, () => {
ipcMainHandle(ExtensionLoader.extensionsMainChannel, () => {
return Array.from(this.toJSON());
});
subscribeToBroadcast(ExtensionLoader.extensionsRendererChannel, (_event, extensions: [LensExtensionId, InstalledExtension][]) => {
ipcMainOn(ExtensionLoader.extensionsRendererChannel, (event, extensions: [LensExtensionId, InstalledExtension][]) => {
this.syncExtensions(extensions);
});
}
@@ -199,7 +199,7 @@ export class ExtensionLoader extends Singleton {
};
requestMain(ExtensionLoader.extensionsMainChannel).then(extensionListHandler);
subscribeToBroadcast(ExtensionLoader.extensionsMainChannel, (_event, extensions: [LensExtensionId, InstalledExtension][]) => {
ipcRendererOn(ExtensionLoader.extensionsMainChannel, (event, extensions: [LensExtensionId, InstalledExtension][]) => {
extensionListHandler(extensions);
});
}
+2 -1
View File
@@ -24,6 +24,7 @@ import { Disposers } from "../lens-extension";
import type { LensMainExtension } from "../lens-main-extension";
import type { Disposer } from "../../common/utils";
import { once } from "lodash";
import { ipcMainHandle } from "../../common/ipc";
export abstract class IpcMain extends IpcRegistrar {
constructor(extension: LensMainExtension) {
@@ -55,7 +56,7 @@ export abstract class IpcMain extends IpcRegistrar {
handle(channel: string, handler: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any): void {
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
ipcMain.handle(prefixedChannel, handler);
ipcMainHandle(prefixedChannel, handler);
this.extension[Disposers].push(() => ipcMain.removeHandler(prefixedChannel));
}
}