mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
26 lines
1017 B
TypeScript
26 lines
1017 B
TypeScript
import { ipcMain } from "electron";
|
|
import { IpcPrefix, IpcStore } from "./ipc-store";
|
|
import { Disposers } from "./lens-extension";
|
|
import { LensMainExtension } from "./lens-main-extension";
|
|
|
|
export class MainIpcStore extends IpcStore {
|
|
constructor(extension: LensMainExtension) {
|
|
super(extension);
|
|
extension[Disposers].push(() => MainIpcStore.resetInstance());
|
|
}
|
|
|
|
handleIpc(channel: string, handler: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any): void {
|
|
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
|
|
|
ipcMain.handle(prefixedChannel, handler);
|
|
this.extension[Disposers].push(() => ipcMain.removeHandler(prefixedChannel));
|
|
}
|
|
|
|
listenIpc(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): void {
|
|
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
|
|
|
ipcMain.addListener(prefixedChannel, listener);
|
|
this.extension[Disposers].push(() => ipcMain.removeListener(prefixedChannel, listener));
|
|
}
|
|
}
|