update documentation

This commit is contained in:
Philipp Kunz 2024-04-14 18:58:16 +02:00
parent 45473bb2af
commit 705a66c938
4 changed files with 134 additions and 28 deletions

View File

@ -2,17 +2,29 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"githost": "code.foss.global",
"gitscope": "api.global",
"gitrepo": "typedelectron",
"description": "a package made for ipc communication in electron",
"description": "A package designed for Electron IPC (Inter-Process Communication) with strong TypeScript support.",
"npmPackagename": "@api.global/typedelectron",
"license": "MIT",
"projectDomain": "api.global"
"projectDomain": "api.global",
"keywords": [
"Electron",
"IPC",
"TypeScript",
"communication",
"typed request",
"backend",
"preload script"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -2,7 +2,7 @@
"name": "@api.global/typedelectron",
"version": "1.0.10",
"private": false,
"description": "a package made for ipc communication in electron",
"description": "A package designed for Electron IPC (Inter-Process Communication) with strong TypeScript support.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"exports": {
@ -55,5 +55,14 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"keywords": [
"Electron",
"IPC",
"TypeScript",
"communication",
"typed request",
"backend",
"preload script"
]
}
}

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

130
readme.md
View File

@ -1,31 +1,115 @@
# @api.global/typedelectron
a package made for ipc communication in electron
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@api.global/typedelectron)
* [gitlab.com (source)](https://gitlab.com/api.global/typedelectron)
* [github.com (source mirror)](https://github.com/api.global/typedelectron)
* [docs (typedoc)](https://api.global.gitlab.io/typedelectron/)
## Install
## Status for master
To start using @api.global/typedelectron in your Electron project, first, you need to add it to your project dependencies using npm:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/api.global/typedelectron/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/api.global/typedelectron/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@api.global/typedelectron)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/api.global/typedelectron)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@api.global/typedelectron)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@api.global/typedelectron)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@api.global/typedelectron)](https://lossless.cloud)
```bash
npm install @api.global/typedelectron --save
```
This command will install the package and add it to your `package.json` file.
## Usage
Use TypeScript for best in class intellisense
For further information read the linked docs at the top of this readme.
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
@api.global/typedelectron is a TypeScript package designed to facilitate IPC (Inter-Process Communication) in Electron applications, leveraging the power of typed requests for enhanced developer experience and code reliability. Below, we provide an exhaustive guide to integrating and utilizing this package in your Electron project, ensuring that your main process and renderer processes communicate seamlessly and efficiently.
### Setting Up Your Project
Before diving into the usage of @api.global/typedelectron, ensure your Electron project is set up to support TypeScript and ESM (ECMAScript Modules) syntax. Your `tsconfig.json` should include settings that target ESNext modules, and your Electron version must meet the peer dependency requirement (>=28.0.0-beta.11).
### Initialization in the Main Process
To leverage @api.global/typedelectron for handling IPC in the main process of your Electron application, start by importing and initializing the `TypedElectronBackend` class. This class provides the functionalities needed to receive and respond to typed requests from renderer processes.
```typescript
import { app, BrowserWindow } from 'electron';
import { TypedElectronBackend } from '@api.global/typedelectron';
app.on('ready', async () => {
const mainWindow = new BrowserWindow({
// BrowserWindow options here
webPreferences: {
preload: YOUR_PRELOAD_SCRIPT,
contextIsolation: true,
},
});
// Initialize TypedElectronBackend
const typedElectronBackend = await TypedElectronBackend.createTypedElectronBackend();
// Load your HTML file
mainWindow.loadFile('path/to/your/index.html');
});
```
In the example above, replace `YOUR_PRELOAD_SCRIPT` with the path to your preload script, which should also import and use the `getPreloadScriptPath` provided by the package to ensure typed messages are properly set up.
### Handling Typed Requests
The core advantage of @api.global/typedelectron is its ability to process typed requests, making IPC more robust and easier to manage. Let's define a typed request interface:
```typescript
// Define in a shared location accessible by both main and renderer processes
export interface IMyTypedRequest {
requestType: 'MY_REQUEST';
payload: {
someData: string;
};
}
```
In the main process, use the `typedElectronBackend` instance to register handlers for specific request types:
```typescript
typedElectronBackend.typedrouter.onTyped<IMyTypedRequest>('MY_REQUEST', async (request) => {
console.log(request.payload.someData);
return {
response: 'Processed your request',
};
});
```
This setup allows the main process to listen for `MY_REQUEST` types and respond accordingly.
### Sending Requests from the Renderer Process
Now, let's send a typed request from the Renderer process. Ensure your preload script sets up the context bridge properly, and then use the provided `TypedRequest` class:
```typescript
import { TypedRequest } from '@api.global/typedelectron';
const myTypedRequest = new TypedRequest<IMyTypedRequest>('MY_REQUEST');
myTypedRequest.send({
someData: 'Hello from Renderer',
}).then((response) => {
console.log(response); // Process response
});
```
In this example, the renderer process sends a request of type `MY_REQUEST` with some data, and then processes the response received from the main process.
### Conclusion
By following the steps and patterns outlined above, you can leverage @api.global/typedelectron to enhance the communication layer of your Electron applications. Typed requests help ensure that the data exchanged between your main and renderer processes is predictable and well-structured, ultimately leading to more reliable and maintainable code.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.