Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
45473bb2af | |||
24f38fdc72 | |||
bb5aa2561f | |||
816cd102a2 | |||
8ab5b6f4b7 | |||
dcff23e71d | |||
ab5c3fc8f2 | |||
61e463b66f | |||
487ab07f0e | |||
a1882ce241 | |||
75a59b1650 | |||
c3e4ae18c8 | |||
84a2476a0b | |||
f40c390507 | |||
c41a329087 | |||
007f25fcca |
9
assets/preload.js
Normal file
9
assets/preload.js
Normal 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));
|
||||
},
|
||||
});
|
17
package.json
17
package.json
@ -1,16 +1,20 @@
|
||||
{
|
||||
"name": "@api.global/typedelectron",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.10",
|
||||
"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
389
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedelectron',
|
||||
version: '1.0.2',
|
||||
version: '1.0.10',
|
||||
description: 'a package made for ipc communication in electron'
|
||||
}
|
||||
|
34
ts/classes.typedelectronbackend.ts
Normal file
34
ts/classes.typedelectronbackend.ts
Normal file
@ -0,0 +1,34 @@
|
||||
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', async (eventArg, payloadArg) => {
|
||||
const updatedPayload = await this.typedrouter.routeAndAddResponse({ ...payloadArg }); // TODO: check how to pass on eventArg
|
||||
eventArg.sender.send('typedrequest', updatedPayload);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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
9
ts/paths.ts
Normal 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
29
ts/plugins.ts
Normal 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,
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
const removeme = {};
|
||||
export {
|
||||
removeme
|
||||
}
|
8
ts_web/00_commitinfo_data.ts
Normal file
8
ts_web/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedelectron',
|
||||
version: '1.0.10',
|
||||
description: 'a package made for ipc communication in electron'
|
||||
}
|
29
ts_web/classes.typedelectronfrontend.ts
Normal file
29
ts_web/classes.typedelectronfrontend.ts
Normal 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;
|
||||
}
|
||||
}
|
1
ts_web/index.ts
Normal file
1
ts_web/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './classes.typedelectronfrontend.js';
|
15
ts_web/plugins.ts
Normal file
15
ts_web/plugins.ts
Normal 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,
|
||||
}
|
Reference in New Issue
Block a user