Files
evening_detective_screen/electron/preload.ts
T
2026-10-17 18:14:31 +07:00

18 lines
830 B
TypeScript

import { contextBridge, ipcRenderer } from 'electron'
import type { Command, State } from '../src/types/screen.js'
contextBridge.exposeInMainWorld('screenBridge', {
command: (command: Command) => ipcRenderer.invoke('command', command),
report: (report: unknown) => ipcRenderer.send('report', report),
state: () => ipcRenderer.invoke('state'),
subscribe: (listener: (state: State) => void) => {
const handler = (_event: Electron.IpcRendererEvent, state: State) => listener(state)
ipcRenderer.on('state', handler)
return () => ipcRenderer.removeListener('state', handler)
},
host: () => ipcRenderer.invoke('host'),
show: (id: number) => ipcRenderer.invoke('show', id),
lan: (address: string | null) => ipcRenderer.invoke('lan', address),
approve: (id: string) => ipcRenderer.invoke('approve', id),
})