mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 10:27:33 +00:00
* perf(mobile): back off spare page refills after an unclaimed drop or memory warning * fix(mobile): skip a spare whose store read outlived an unclaimed drop * fix(mobile): arm the spare refill timer on whole milliseconds
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { requireOptionalNativeModule } from 'expo-modules-core'
|
|
|
|
type SpareDocumentModule = {
|
|
prepareSpareDocument?: (directory: string, sessionId: string) => Promise<boolean>
|
|
claimSpareDocument?: (directory: string) => Promise<string | null>
|
|
discardSpareDocument?: () => Promise<void>
|
|
}
|
|
|
|
// A binary built before the spare existed has the module without these functions.
|
|
const spareModule = (): SpareDocumentModule | null =>
|
|
requireOptionalNativeModule<SpareDocumentModule>('OrcaMobileWebShell')
|
|
|
|
// Boot a page from `directory` under `sessionId` and park it, invisible, until a screen claims it.
|
|
// False when native declined: a phone under 4 GB, the app not active, a page document shown, or an iOS
|
|
// memory warning in the last few minutes.
|
|
export async function prepareSpareDocument(directory: string, sessionId: string): Promise<boolean> {
|
|
return (await spareModule()?.prepareSpareDocument?.(directory, sessionId)) ?? false
|
|
}
|
|
|
|
// The parked spare's session id when it was booted from `directory`, handed out once. The view
|
|
// mounted under that id adopts the booted page.
|
|
export async function claimSpareDocument(directory: string): Promise<string | null> {
|
|
return (await spareModule()?.claimSpareDocument?.(directory)) ?? null
|
|
}
|
|
|
|
export async function discardSpareDocument(): Promise<void> {
|
|
await spareModule()?.discardSpareDocument?.()
|
|
}
|