Files
orca/src/main/runtime/runtime-desktop-surface.ts
T
Jinwoo Hong 9586a3fbb5 feat(sidebar): main serves workspace icons as small data URLs for the phone (dark) (#30046)
* feat(sidebar): main serves workspace icons as small data URLs for the phone, unused until the phone switch

* fix(sidebar): settle review findings in the icons RPC and the manual-redirect port fix

* docs(sidebar): scope the icon fetch-slot bound to a lone read

* fix(sidebar): gate the icons RPC behind the sidebar-inputs switch; prove re-encoding end to end

* fix(sidebar): restore two files the merge reformatted; one pure annotation for the icons params

* fix(sidebar): restore two files the pre-commit formatter rewrote during the merge

* fix(sidebar): icons fetch through their own manual-redirect request; shared desktop HTTP client back to main

* fix(sidebar): settle review findings in the icons manual-redirect request

* fix(sidebar): end a bodyless icon response at once; clearer fetchRepoIcon doc
2026-10-17 15:10:49 -07:00

50 lines
2.3 KiB
TypeScript

import type { BrowserWindow, IpcMainEvent } from 'electron'
/**
* The desktop facilities `OrcaRuntimeService` uses, which a Node host does not have.
*
* Three sites, all optional by nature: a native notification toast, a lookup of the
* authoritative renderer window, and one ipcMain channel used only by the
* renderer-backed tab-create fallback. With no renderer that fallback is unreachable —
* `createTerminal` already takes the background spawn branch when there is no
* authoritative window (#10333) — so a Node host needs none of them.
*
* Defaults are inert rather than throwing, for the same reason as the PTY bindings: a
* host with no desktop legitimately has nothing here, and that is not a downgrade.
* Where absence IS user-visible — a notification that would have been shown — the
* runtime already routes to paired clients, which is the better destination anyway.
*/
export type RuntimeDesktopSurface = {
/** Headless hosts retain the formatter's English defaults. */
translateNotification?(key: string, fallback: string): string
/** Show a native notification. Returns false when the host cannot, so callers can say so. */
isAwayForMobileNotifications?(): boolean | undefined
showNotification(input: { title: string; body: string }): boolean
/** The renderer window with this id, or null when there is no desktop. */
findWindowById(id: number): BrowserWindow | null
onIpc(channel: string, listener: (event: IpcMainEvent, ...args: never[]) => void): void
removeIpcListener(channel: string, listener: (...args: never[]) => void): void
/** Re-encodes as a PNG fitting `maxEdge`; null if undecodable. Absent on Node hosts. */
encodeRepoIconPng?(bytes: Uint8Array, maxEdge: number): Uint8Array | null
/** A GET answering redirects with the 3xx, without proxy login; absent where fetch already does. */
fetchRepoIcon?(url: string, init: RequestInit): Promise<Response>
}
const inertDesktopSurface: RuntimeDesktopSurface = {
showNotification: () => false,
findWindowById: () => null,
onIpc: () => {},
removeIpcListener: () => {}
}
let current: RuntimeDesktopSurface = inertDesktopSurface
export function setRuntimeDesktopSurface(surface: RuntimeDesktopSurface | null): void {
current = surface ?? inertDesktopSurface
}
export function getRuntimeDesktopSurface(): RuntimeDesktopSurface {
return current
}