fix(core): update
This commit is contained in:
parent
96c9cf8ee6
commit
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));
|
||||
}
|
||||
});
|
11
package.json
11
package.json
@ -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"
|
||||
|
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.3',
|
||||
description: 'a package made for ipc communication in electron'
|
||||
}
|
||||
|
30
ts/classes.typedelectronbackend.ts
Normal file
30
ts/classes.typedelectronbackend.ts
Normal 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;
|
||||
}
|
||||
}
|
@ -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
8
ts/paths.ts
Normal 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
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.3',
|
||||
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;
|
||||
}
|
||||
}
|
0
ts_web/index.ts
Normal file
0
ts_web/index.ts
Normal file
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,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user