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

34 lines
1.7 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', {
selectAudioOutput: (id: string) => ipcRenderer.invoke('select-audio-output', id),
prepareAudioOutput: () => ipcRenderer.invoke('prepare-audio-output'),
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),
openMaterialsFolder: (key: string) => ipcRenderer.invoke('open-materials-folder', key),
})
if (new URLSearchParams(location.search).has('audio-devices')) {
navigator.mediaDevices.addEventListener('devicechange', () => {
ipcRenderer.send('audio-devices-changed')
})
}