Files
orca/src/preload/api/emulator-bridge.ts
T
Neil 401664298f fix(preload): make a dropped bridge key a compile error
The split silently dropped jira.searchUsers and
runtimeEnvironments.retryControlConnection. Neither failed typecheck: the bridge
modules carried no satisfies annotation and the composed api object was
unannotated, so a missing key was only a runtime TypeError in the renderer.

Annotates each module against PreloadApi, the type window.api is already
declared as, so the contract supplies the shape rather than a parallel copy.
Deleting jira.searchUsers now fails with TS2741 naming the key.

Turning this on surfaced 106 places where a bridge locally annotated
Promise<unknown> or unknown[] over a contract that declares concrete types --
the bridge was erasing types the renderer relied on. Those annotations are gone.

Also exposes app.awaitBeforeUnloadCheckpoint, which was declared and called but
never actually on the bridge, so the lazy-chunk recovery reload optional-chained
to a no-op and navigated without joining the checkpoint. The missing key was
caught by the new annotation rather than by hand.
2026-09-01 18:24:49 -07:00

100 lines
3.5 KiB
TypeScript

import { ipcRenderer } from 'electron'
import type { PreloadApi } from '../api-types'
export const emulatorApi = {
startFrameStream: (args: {
streamUrl: string
streamKey?: string
}): Promise<{
streamId: string
}> => ipcRenderer.invoke('emulator:frameStreamStart', args),
stopFrameStream: (args: { streamId: string }): Promise<void> =>
ipcRenderer.invoke('emulator:frameStreamStop', args),
onFrameStreamFrame: (
callback: (data: { streamId: string; bytes: ArrayBuffer }) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: { streamId: string; bytes: ArrayBuffer }
) => callback(data)
ipcRenderer.on('emulator:frameStreamFrame', listener)
return () => ipcRenderer.removeListener('emulator:frameStreamFrame', listener)
},
onFrameStreamError: (
callback: (data: { streamId: string; message: string }) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: { streamId: string; message: string }
) => callback(data)
ipcRenderer.on('emulator:frameStreamError', listener)
return () => ipcRenderer.removeListener('emulator:frameStreamError', listener)
},
startVideoStream: (args: { deviceId: string; streamId: string }): Promise<{ streamId: string }> =>
ipcRenderer.invoke('emulator:videoStreamStart', args),
stopVideoStream: (args: { streamId: string }): Promise<void> =>
ipcRenderer.invoke('emulator:videoStreamStop', args),
onVideoStreamMeta: (
callback: (data: {
streamId: string
deviceId: string
meta: { codecId: string; width: number; height: number }
}) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: {
streamId: string
deviceId: string
meta: { codecId: string; width: number; height: number }
}
) => callback(data)
ipcRenderer.on('emulator:videoStreamMeta', listener)
return () => ipcRenderer.removeListener('emulator:videoStreamMeta', listener)
},
onVideoStreamFrame: (
callback: (data: {
streamId: string
deviceId: string
config: boolean
keyFrame: boolean
bytes: ArrayBuffer
}) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: {
streamId: string
deviceId: string
config: boolean
keyFrame: boolean
bytes: ArrayBuffer
}
) => callback(data)
ipcRenderer.on('emulator:videoStreamFrame', listener)
return () => ipcRenderer.removeListener('emulator:videoStreamFrame', listener)
},
onPaneFocus: (callback: (data: { worktreeId: string }) => void): (() => void) => {
const listener = (_event: Electron.IpcRendererEvent, data: { worktreeId: string }) =>
callback(data)
ipcRenderer.on('emulator:pane-focus', listener)
return () => ipcRenderer.removeListener('emulator:pane-focus', listener)
},
onAutoAttach: (
callback: (data: {
worktreeId: string
info: { deviceUdid: string; streamUrl: string; wsUrl: string; axUrl?: string }
}) => void
): (() => void) => {
const listener = (
_event: Electron.IpcRendererEvent,
data: {
worktreeId: string
info: { deviceUdid: string; streamUrl: string; wsUrl: string; axUrl?: string }
}
) => callback(data)
ipcRenderer.on('ui:emulatorAutoAttach', listener)
return () => ipcRenderer.removeListener('ui:emulatorAutoAttach', listener)
}
} satisfies PreloadApi['emulator']