mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2024-12-28 09:41:09 +01:00
23 lines
636 B
TypeScript
23 lines
636 B
TypeScript
|
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'
|
||
|
|
||
|
const handler = {
|
||
|
invoke(channel: string, value: any) {
|
||
|
ipcRenderer.invoke(channel, value)
|
||
|
},
|
||
|
send(channel: string, value: unknown) {
|
||
|
ipcRenderer.send(channel, value)
|
||
|
},
|
||
|
on(channel: string, callback: (...args: unknown[]) => void) {
|
||
|
const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => callback(...args)
|
||
|
ipcRenderer.on(channel, subscription)
|
||
|
|
||
|
return () => {
|
||
|
ipcRenderer.removeListener(channel, subscription)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
contextBridge.exposeInMainWorld('ipc', handler)
|
||
|
|
||
|
export type IpcHandler = typeof handler
|