10 Commits

Author SHA1 Message Date
ab5c3fc8f2 1.0.7 2023-12-06 03:05:05 +01:00
61e463b66f fix(core): update 2023-12-06 03:05:05 +01:00
487ab07f0e 1.0.6 2023-12-06 02:39:00 +01:00
a1882ce241 fix(core): update 2023-12-06 02:39:00 +01:00
75a59b1650 1.0.5 2023-12-06 02:23:05 +01:00
c3e4ae18c8 fix(core): update 2023-12-06 02:23:04 +01:00
84a2476a0b 1.0.4 2023-12-06 02:21:16 +01:00
f40c390507 fix(core): update 2023-12-06 02:21:16 +01:00
c41a329087 1.0.3 2023-12-06 02:16:37 +01:00
007f25fcca fix(core): update 2023-12-06 02:16:36 +01:00
13 changed files with 428 additions and 120 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

@ -1,16 +1,20 @@
{
"name": "@api.global/typedelectron",
"version": "1.0.2",
"version": "1.0.7",
"private": false,
"description": "a package made for ipc communication in electron",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"exports": {
"./ts": "./dist_ts/index.js",
"./ts_web": "./dist_ts_web/index.js"
},
"type": "module",
"author": "Task Venture Capital GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"build": "(tsbuild --allowimplicitany && tsbuild element --allowimplicitany)",
"buildDocs": "(tsdoc)"
},
"devDependencies": {
@ -21,7 +25,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"

389
pnpm-lock.yaml generated

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.7',
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;
}

9
ts/paths.ts Normal file
View File

@ -0,0 +1,9 @@
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.7',
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,
}