Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/archergu/einf
A simple electron main process framework
https://github.com/archergu/einf
decorator electron framework ipc metadata
Last synced: about 1 month ago
JSON representation
A simple electron main process framework
- Host: GitHub
- URL: https://github.com/archergu/einf
- Owner: ArcherGu
- License: mit
- Created: 2022-08-16T01:10:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T12:17:46.000Z (3 months ago)
- Last Synced: 2024-10-29T14:47:00.544Z (3 months ago)
- Topics: decorator, electron, framework, ipc, metadata
- Language: TypeScript
- Homepage:
- Size: 1.64 MB
- Stars: 24
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A simple electron main process framework.## Description
Einf is a simple electron main process framework, which provides some decorators and automatic dependency injection to help you simplify the main process code.
## Features
- 💉 Support dependency injection powered by Typescript decorators.
- 🪟 Support custom items injection and window object injection.
- 🔗 Automatic ipc channel binding to reduce duplication of code.
- 📦 Tiny size, the whole framework is less than 10kb.
- 💡 Simple to use, you can use it as a base framework to build your own framework.
## Installation
```shell
npm i einf
# Or Yarn
yarn add einf
# Or PNPM
pnpm add einf
```## Usage
1. Entry point of your electron application like `index.ts`:
```ts
import { BrowserWindow, app } from 'electron'
import { createEinf } from 'einf'
import { AppController } from './app.controller'async function bootstrap() {
const window = new BrowserWindow()
window.loadURL('https://github.com')await createEinf({
// window to create
window,
// controllers will be automatically initialized
controllers: [AppController],
// custom items to inject
injects: [{
name: 'IS_DEV',
inject: !app.isPackaged,
}],
})
}bootstrap()
```2. Provide at least one controller to start the application, `app.controller.ts`:
```ts
import type { BrowserWindow } from 'electron'
import { app } from 'electron'
import { Controller, Inject, IpcHandle, IpcSend, Window } from 'einf'
import { AppService } from './app.service'@Controller()
export class AppController {
constructor(
private appService: AppService,
@Inject('IS_DEV') private isDev: boolean,
@Window() private win: BrowserWindow,
) {}@IpcSend('reply-msg')
public replyMsg(msg: string) {
return msg
}@IpcHandle('send-msg')
public sendMsg(msg: string) {
console.log(msg)
return 'Get msg'
}@IpcHandle('exit')
public exit() {
app.quit()
}
}
```3. You can also inject service via `@Injectable` decorator, `app.service.ts`:
```ts
import { Injectable } from 'einf'@Injectable()
export class AppService {
public createMsg(msg: string): string {
return `"${msg}" is created by app service`
}
}
```4. Typescript configuration:
Ensure that `experimentalDecorators` and `emitDecoratorMetadata` are enabled in your TypeScript configuration (such as in `tsconfig.json`).
If not, you may encounter an error stating `Unable to resolve signature of class decorator when called as an expression`.```json
{
"compilerOptions": {
// ... other options
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
```## License
MIT License © 2022 [Archer Gu](https://github.com/archergu)