mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-09 03:25:09 +00:00
System to handle IPC communication
This commit is contained in:
32
src/electron/shared/IPCHandler.ts
Normal file
32
src/electron/shared/IPCHandler.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import TestHandler from '../ipc/TestHandler.ipc'
|
||||
import { TestInput } from './interfaces/test.interface'
|
||||
|
||||
/**
|
||||
* To add a new IPC listener:
|
||||
* 1.) Write input/output interfaces
|
||||
* 2.) Add the event to IPCEvents
|
||||
* 3.) Write a class that implements IPCHandler
|
||||
* 4.) Add the class to getIPCHandlers
|
||||
*/
|
||||
|
||||
export function getIPCHandlers(): IPCHandler<keyof IPCEvents>[] {
|
||||
return [
|
||||
new TestHandler()
|
||||
]
|
||||
}
|
||||
|
||||
export type IPCEvents = {
|
||||
['test-event-A']: {
|
||||
input: TestInput
|
||||
output: string
|
||||
}
|
||||
['test-event-B']: {
|
||||
input: number
|
||||
output: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface IPCHandler<E extends keyof IPCEvents> {
|
||||
event: E
|
||||
handler(data: IPCEvents[E]['input']): Promise<IPCEvents[E]['output']> | IPCEvents[E]['output']
|
||||
}
|
||||
4
src/electron/shared/interfaces/test.interface.ts
Normal file
4
src/electron/shared/interfaces/test.interface.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface TestInput {
|
||||
value1: string
|
||||
value2: number
|
||||
}
|
||||
Reference in New Issue
Block a user