34 lines
991 B
TypeScript
34 lines
991 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 }); // TODO: check how to pass on eventArg
|
|
});
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|