1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-27 17:26:42 +01:00
Whalebird-desktop-client-ma.../main/preload.ts
2024-09-23 19:19:16 +09:00

23 lines
650 B
TypeScript

import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'
const handler = {
invoke(channel: string, value: any) {
return ipcRenderer.invoke(channel, value)
},
send(channel: string, value: unknown) {
return 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