INNER CODE UNIT · TypeScript
isOperationResult
SimonAKing/scrcpy-gui · src/main/main.ts:117
function isOperationResult(value: unknown): value is OperationResult<unknown> {
return Boolean(value && typeof value === 'object' && 'ok' in value && typeof value.ok === 'boolean')
}
const handle: typeof ipcMain.handle = (channel, listener) => {
ipcMain.handle(channel, async (event, ...args) => {
assertTrustedIpcSender(event)
const requestId = randomUUID()
const audit = !channel.startsWith('events:')
try {
const result = await listener(event, ...args)
const operation = isOperationResult(result) ? result : undefined
const failed = operation?.ok === false
if (audit) eventStore.publish({
level: failed ? 'warn' : 'debug', domain: domainForChannel(channel), action: channel,
requestId,
stage: operation?.error?.stage || 'ipc',
message: operation?.error?.message || `${channel} completed.`,