Files
orca/src/preload/api/wsl-hosts-api.ts
T
Neil 03eee256f1 fix(wsl-host): let an app update reach a WSL host orcad (E1) (#28458)
* fix(wsl-host): read the running orcad's census before an app update replaces it

* fix(wsl-host): keep Force, the incumbent watch and its freshness through an update

* fix(orcad): recount terminals just before an update stops the incumbent

* refactor(wsl-host): move watch arming and pairing identity out of oversized modules
2026-10-13 20:38:33 -07:00

55 lines
2.3 KiB
TypeScript

/**
* WSL distros as hosts; desktop-only and Windows-only (or the e2e fake) behind the internal gate,
* else undefined.
*/
import { ipcRenderer } from 'electron'
import {
WSL_HOST_STATUS_CHANNEL,
type WslHostAddResult,
type WslHostCapability,
type WslHostDistro,
type WslHostServerStop,
type WslHostStatus
} from '../../shared/wsl-host-types'
import { isWslHostsInternalGateOpen } from '../../shared/wsl-host-internal-gate'
export type WslHostsPreloadApi = {
getCapability: () => Promise<WslHostCapability>
listDistros: () => Promise<WslHostDistro[]>
add: (args: { distro: string; startIfStopped?: boolean }) => Promise<WslHostAddResult>
remove: (args: { environmentId: string }) => Promise<WslHostServerStop>
/** `force` takes an update that live terminals deferred. */
connect: (args: { environmentId: string; force?: boolean }) => Promise<void>
getStatuses: () => Promise<WslHostStatus[]>
onStatusChanged: (callback: (status: WslHostStatus) => void) => () => void
/** The WSL hosts an open project or terminal needs; only these may boot a stopped distro. */
setVisibleWork: (args: { environmentIds: string[] }) => Promise<void>
}
const wslHostsApi: WslHostsPreloadApi = {
getCapability: () => ipcRenderer.invoke('wslHosts:getCapability'),
listDistros: () => ipcRenderer.invoke('wslHosts:listDistros'),
add: (args) => ipcRenderer.invoke('wslHosts:add', args),
remove: (args) => ipcRenderer.invoke('wslHosts:remove', args),
connect: (args) => ipcRenderer.invoke('wslHosts:connect', args),
getStatuses: () => ipcRenderer.invoke('wslHosts:getStatuses'),
onStatusChanged: (callback) => {
const listener = (_event: Electron.IpcRendererEvent, status: WslHostStatus): void =>
callback(status)
ipcRenderer.on(WSL_HOST_STATUS_CHANNEL, listener)
return () => ipcRenderer.removeListener(WSL_HOST_STATUS_CHANNEL, listener)
},
setVisibleWork: (args) => ipcRenderer.invoke('wslHosts:setVisibleWork', args)
}
/** Undefined hides every WSL host surface in the renderer; main refuses the calls regardless. */
export function getWslHostsApi(
env: Readonly<Record<string, string | undefined>> = process.env,
platform: NodeJS.Platform = process.platform
): WslHostsPreloadApi | undefined {
if (!isWslHostsInternalGateOpen(env)) {
return undefined
}
return platform === 'win32' || env.ORCA_E2E_FAKE_WSL_HOSTS ? wslHostsApi : undefined
}