typedelectron/ts/classes.typedelectronbackend.ts

31 lines
917 B
TypeScript
Raw Normal View History

2023-12-06 01:16:36 +00:00
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<T extends plugins.typedrequestInterfaces.ITypedRequest>(
methodName: T['method'],
windowArg: plugins.electron.BrowserWindow,
) {
const typedrequest = new plugins.typedrequest.TypedRequest<T>(new plugins.typedrequest.TypedTarget({
typedRouterRef: this.typedrouter,
postMethodWithTypedRouter: async (payloadArg: T) => {
windowArg.webContents.send('typedrequest', payloadArg);
}
}), methodName);
return typedrequest;
}
}