Fix auto cleanup of Extension's IPC classes (#3505)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-07-23 15:14:11 -04:00
1 parent de6560b427
commit 1437f8a945
3 files changed
+27 -7

No files matched your search

+9 -2
View File
@@ -28,7 +28,9 @@ import { once } from "lodash";
export abstract class IpcRenderer extends IpcRegistrar {
constructor(extension: LensRendererExtension) {
super(extension);
extension[Disposers].push(() => IpcRenderer.resetInstance());
// Call the static method on the bottom child class.
extension[Disposers].push(() => (this.constructor as typeof IpcRenderer).resetInstance());
}
/**
@@ -41,8 +43,13 @@ export abstract class IpcRenderer extends IpcRegistrar {
*/
listen(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => any): Disposer {
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
const cleanup = once(() => ipcRenderer.removeListener(prefixedChannel, listener));
const cleanup = once(() => {
console.info(`[IPC-RENDERER]: removing extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version } });
return ipcRenderer.removeListener(prefixedChannel, listener);
});
console.info(`[IPC-RENDERER]: adding extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version } });
ipcRenderer.addListener(prefixedChannel, listener);
this.extension[Disposers].push(cleanup);