Files
evening_detective_screen/electron/preload.ts
T
2026-10-18 01:38:02 +07:00

25 lines
1.3 KiB
TypeScript

import type { OnlineIntent } from '../src/types/online.js'
import { contextBridge, ipcRenderer } from 'electron'
import type { Command, Report, SceneReport, State } from '../src/types/screen.js'
contextBridge.exposeInMainWorld('screenBridge', {
planStatus: () => ipcRenderer.invoke('plan-status'),
onlineState: () => ipcRenderer.invoke('online-state'),
onlineAction: (intent: OnlineIntent) => ipcRenderer.invoke('online-action', intent),
closeOutput: () => ipcRenderer.invoke('close-output'),
command: (command: Command) => ipcRenderer.invoke('command', command),
report: (report: Report) => ipcRenderer.send('report', report),
reportScene: (report: SceneReport) => ipcRenderer.send('scene-report', report),
preview: () => ipcRenderer.invoke('preview'),
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),
packages: () => ipcRenderer.invoke('packages'),
selectPackage: (key: string | null) => ipcRenderer.invoke('select-package', key),
})