1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-01-28 16:20:21 +01:00

23 lines
650 B
TypeScript
Raw Normal View History

2023-11-02 01:20:27 +09:00
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'
const handler = {
invoke(channel: string, value: any) {
2024-09-23 19:19:16 +09:00
return ipcRenderer.invoke(channel, value)
2023-11-02 01:20:27 +09:00
},
send(channel: string, value: unknown) {
2024-09-23 19:19:16 +09:00
return ipcRenderer.send(channel, value)
2023-11-02 01:20:27 +09:00
},
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