import * as plugins from './plugins.js'; export class TypedElectronBackend { // STATIC public static async createTypedElectronBackend() { return new TypedElectronBackend(); } // INSTANCE public typedrouter = new plugins.typedrequest.TypedRouter(); constructor() { plugins.electron.ipcMain.on('typedrequest', (eventArg, payloadArg) => { this.typedrouter.routeAndAddResponse(payloadArg); }); } createTypedRequest( methodName: T['method'], windowArg: plugins.electron.BrowserWindow, ) { const typedrequest = new plugins.typedrequest.TypedRequest(new plugins.typedrequest.TypedTarget({ typedRouterRef: this.typedrouter, postMethodWithTypedRouter: async (payloadArg: T) => { windowArg.webContents.send('typedrequest', payloadArg); } }), methodName); return typedrequest; } }