fix(core): update

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

9
assets/preload.js Normal file
View File

@ -0,0 +1,9 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronApi', {
sendMessage: async (channelNameArg, payloadArg) => {
ipcRenderer.send(channelNameArg, payloadArg);
},
receiveMessage: (channelNameArg, func) => {
ipcRenderer.on(channelNameArg, (event, ...args) => func(...args));
}
});

View File

@ -10,7 +10,7 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"build": "(tsbuild --allowimplicitany && tsbuild element --allowimplicitany)",
"buildDocs": "(tsdoc)"
},
"devDependencies": {
@ -21,7 +21,14 @@
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.7"
},
"dependencies": {},
"dependencies": {
"@api.global/typedrequest": "^3.0.2",
"@api.global/typedrequest-interfaces": "^3.0.1",
"@push.rocks/smartpath": "^5.0.11"
},
"peerDependencies": {
"electron": ">=28.0.0-beta.11"
},
"repository": {
"type": "git",
"url": "git+https://gitlab.com/api.global/typedelectron.git"

File diff suppressed because it is too large Load Diff

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
}

View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@api.global/typedelectron',
version: '1.0.3',
description: 'a package made for ipc communication in electron'
}

View File

@ -0,0 +1,29 @@
import * as plugins from './plugins.js';
export class TypedElectronFrontend {
// STATIC
public static async createTypedElectronFrontend() {
return new TypedElectronFrontend();
}
// INSTANCE
public typedrouter = new plugins.typedrequest.TypedRouter();
constructor() {
plugins.electronApi.receiveMessage('typedrequest', (payloadArg) => {
this.typedrouter.routeAndAddResponse(payloadArg);
});
}
createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
methodName: T['method'],
) {
const typedrequest = new plugins.typedrequest.TypedRequest<T>(new plugins.typedrequest.TypedTarget({
typedRouterRef: this.typedrouter,
postMethodWithTypedRouter: async (payloadArg: T) => {
plugins.electronApi.sendMessage('typedrequest', payloadArg);
}
}), methodName);
return typedrequest;
}
}

0
ts_web/index.ts Normal file
View File

15
ts_web/plugins.ts Normal file
View File

@ -0,0 +1,15 @@
// @api.global scope
import * as typedrequest from '@api.global/typedrequest';
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
export {
typedrequest,
typedrequestInterfaces,
}
// electron through preload script
const electronApi = (window as any).electronApi;
export {
electronApi,
}