31 lines
917 B
TypeScript
31 lines
917 B
TypeScript
|
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;
|
||
|
}
|
||
|
}
|