Files
orca/src/main/window/mobile-markdown-request-relay.ts
T
Jinwoo HongandOrca 7944293815 Improve mobile terminal streaming performance (#1700)
* Improve mobile terminal streaming performance

Co-authored-by: Orca <help@stably.ai>

* Add mobile clear terminal action

Co-authored-by: Orca <help@stably.ai>

* Fix terminal connection test mock

Co-authored-by: Orca <help@stably.ai>

* WIP: mobile markdown tabs before rebase

Co-authored-by: Orca <help@stably.ai>

* Add mobile markdown editing

Co-authored-by: Orca <help@stably.ai>

* Harden mobile tab and markdown sync

Co-authored-by: Orca <help@stably.ai>

* Fix mobile terminal reconnect loading race

Co-authored-by: Orca <help@stably.ai>

* Polish mobile terminal keyboard behavior

Co-authored-by: Orca <help@stably.ai>

* Simplify mobile markdown editor chrome

Co-authored-by: Orca <help@stably.ai>

* Move mobile markdown actions to top

Co-authored-by: Orca <help@stably.ai>

* Use app modals for markdown discard

Co-authored-by: Orca <help@stably.ai>

* Dismiss keyboard before markdown confirmations

Co-authored-by: Orca <help@stably.ai>

* Add mobile file explorer

Co-authored-by: Orca <help@stably.ai>

* Fix mobile file explorer type narrowing

Co-authored-by: Orca <help@stably.ai>

* Fix mobile files navigation param

Co-authored-by: Orca <help@stably.ai>

* Show mobile files connection wait state

Co-authored-by: Orca <help@stably.ai>

* Preview text files on mobile

Co-authored-by: Orca <help@stably.ai>

* Simplify mobile file previews

Co-authored-by: Orca <help@stably.ai>

* Clarify unavailable mobile file types

Co-authored-by: Orca <help@stably.ai>

* Fix mobile subscription and preview review issues

Co-authored-by: Orca <help@stably.ai>

* Keep fallback terminals visible on mobile

Co-authored-by: Orca <help@stably.ai>

* Keep mobile terminal tap active

Co-authored-by: Orca <help@stably.ai>

* Preserve mobile terminal fallback order

Co-authored-by: Orca <help@stably.ai>

* Fix mobile session tab authority

Co-authored-by: Orca <help@stably.ai>

* Run mobile tests in mobile CI lane

Co-authored-by: Orca <help@stably.ai>

* Bump mobile app version to 0.0.7

Co-authored-by: Orca <help@stably.ai>

* Allow main window IPC wiring size

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-05-12 14:38:12 -07:00

55 lines
1.7 KiB
TypeScript

import { randomUUID } from 'node:crypto'
import { ipcMain } from 'electron'
import type { BrowserWindow } from 'electron'
import type {
RuntimeMarkdownReadTabResult,
RuntimeMarkdownSaveTabResult,
RuntimeMobileMarkdownRequest,
RuntimeMobileMarkdownResponse
} from '../../shared/mobile-markdown-document'
const MOBILE_MARKDOWN_RENDERER_TIMEOUT_MS = 20_000
type RendererMobileMarkdownRequest = RuntimeMobileMarkdownRequest extends infer Request
? Request extends { id: string }
? Omit<Request, 'id'>
: never
: never
export async function requestMobileMarkdownFromRenderer(
mainWindow: BrowserWindow,
request: RendererMobileMarkdownRequest
): Promise<RuntimeMarkdownReadTabResult | RuntimeMarkdownSaveTabResult> {
if (mainWindow.isDestroyed()) {
throw new Error('renderer_unavailable')
}
const id = randomUUID()
return await new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
ipcMain.removeListener('ui:mobileMarkdownResponse', onResponse)
reject(new Error('renderer_timeout'))
}, MOBILE_MARKDOWN_RENDERER_TIMEOUT_MS)
const onResponse = (
event: Electron.IpcMainEvent,
response: RuntimeMobileMarkdownResponse
): void => {
if (event.sender !== mainWindow.webContents) {
return
}
if (response.id !== id) {
return
}
clearTimeout(timeout)
ipcMain.removeListener('ui:mobileMarkdownResponse', onResponse)
if (response.ok) {
resolve(response.result)
} else {
reject(new Error(response.error))
}
}
ipcMain.on('ui:mobileMarkdownResponse', onResponse)
mainWindow.webContents.send('ui:mobileMarkdownRequest', { id, ...request })
})
}