fix(core): update

This commit is contained in:
2023-12-06 02:16:36 +01:00
parent 96c9cf8ee6
commit 007f25fcca
13 changed files with 422 additions and 119 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedelectron',
version: '1.0.2',
version: '1.0.3',
description: 'a package made for ipc communication in electron'
}

View File

@@ -0,0 +1,30 @@
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;
}
}

View File

@@ -1,3 +1,6 @@
import * as plugins from './typedelectron.plugins.js';
export * from './classes.typedelectronbackend.js';
export let demoExport = 'Hi there! :) This is an exported string';
import * as paths from './paths.js';
export const getPreloadScriptPath = () => {
return paths.preloadScriptPath;
}

8
ts/paths.ts Normal file
View File

@@ -0,0 +1,8 @@
import * as plugins from './plugins.js';
export const packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url)
);
export const assetsDir = plugins.path.join(packageDir, 'assets');
export const preloadScriptPath = plugins.path.join(assetsDir, 'preload.js');

29
ts/plugins.ts Normal file
View File

@@ -0,0 +1,29 @@
// node native
import * as path from 'path';
export {
path,
}
// @push.rocks scope
import * as smartpath from '@push.rocks/smartpath';
export {
smartpath,
}
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
export {
typedrequest,
typedrequestInterfaces,
}
// third party
import * as electron from 'electron';
export {
electron,
}

View File

@@ -1,4 +0,0 @@
const removeme = {};
export {
removeme
}