Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/desktop/src/main/runtime-host-boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
createClientRuntimeHostCredentialStore,
createClientRuntimeHostProfileCatalog,
createRuntimeHostCandidateLaunchBarrier,
createRuntimeHostPeerClientFromEnvironment,
LOCAL_RUNTIME_HOST_PROFILE,
loadOrCreateRuntimeHostClientInstanceId,
} from "@maka/runtime-host/client";
Expand Down Expand Up @@ -220,6 +221,9 @@ const runtimeHostDirectPeerAvailable = await configureDesktopRuntimeHostPeerClie
resourcesPath: process.resourcesPath,
clientDataRoot: userDataDir,
});
const runtimeHostPeerClient = runtimeHostDirectPeerAvailable
? createRuntimeHostPeerClientFromEnvironment()
: undefined;
const runtimeHostClientInstanceId = await loadOrCreateRuntimeHostClientInstanceId(
join(userDataDir, "runtime-host-client.json"),
);
Expand Down Expand Up @@ -724,6 +728,7 @@ runtimeHostManager = await startRuntimeHostDesktopManager(
clientInstanceId: runtimeHostClientInstanceId,
generation: runtimeHostGeneration,
candidateLaunchBarrier: runtimeHostCandidateLaunchBarrier,
...(runtimeHostPeerClient ? { peerClient: runtimeHostPeerClient } : {}),
// The Desktop E2E composition lives behind its own entry module, which
// release packaging drops: picking it here is what keeps FakeBackend and
// the E2E bootstrap out of the shipped Runtime Host.
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/main/runtime-host-desktop-candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
type RuntimeHostSshOperatorActivationInput,
connectOrSpawnRuntimeHost,
connectRemoteRuntimeHostProfile,
type RuntimeHostPeerClient,
type RuntimeHostSshInteraction,
type RuntimeHostSshTunnel,
type RuntimeHostSshTunnelInput,
Expand Down Expand Up @@ -176,6 +177,7 @@ export interface DesktopRuntimeHostCandidateStartInput
/** Candidate-exit sink forwarded to the launcher; the Desktop owns the sink. */
readonly onExit?: (details: CandidateExitDetails) => void;
readonly candidateLaunchBarrier?: RuntimeHostCandidateLaunchBarrier;
readonly peerClient?: RuntimeHostPeerClient;
readonly remote?: {
readonly profile: RemoteRuntimeHostProfile;
readonly credential: string;
Expand Down Expand Up @@ -388,6 +390,7 @@ async function startRemoteDesktopRuntimeHostCandidate(
? {}
: { handshakeTimeoutMs: input.handshakeTimeoutMs }),
readyTimeoutMs: input.electionDeadlineMs ?? 45_000,
...(input.peerClient === undefined ? {} : { peerClient: input.peerClient }),
...(remote.sshInteraction === undefined
? {}
: { sshInteraction: remote.sshInteraction }),
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/main/runtime-host-desktop-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,12 @@ class RuntimeHostDesktopManagerImpl implements RuntimeHostDesktopManager {
const results = await Promise.allSettled(
[...this.#targets.values()].map((target) => this.#removeTarget(target)),
);
const peerResults = await Promise.allSettled(
this.#baseInput.peerClient ? [this.#baseInput.peerClient.close()] : [],
);
this.#baseInput.candidateLaunchBarrier?.release();
this.#ipcMain.close();
const failures = results.filter(
const failures = [...results, ...peerResults].filter(
(result): result is PromiseRejectedResult => result.status === 'rejected',
);
if (failures.length > 0) {
Expand Down
15 changes: 15 additions & 0 deletions native/runtime-host-peer/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct StartPeerEndpointOptions {

#[napi(object)]
pub struct ConnectPeerOptions {
pub request_id: u32,
pub peer_id: String,
pub route_hints: Vec<String>,
pub coordination_relays: Option<Vec<String>>,
Expand Down Expand Up @@ -88,6 +89,7 @@ impl PeerEndpoint {
self.commands
.send(EngineCommand::Connect {
options: engine::ConnectOptions {
request_id: options.request_id,
peer_id,
route_hints,
coordination_relays,
Expand All @@ -110,6 +112,19 @@ impl PeerEndpoint {
)
}

#[napi]
pub async fn cancel_connect(&self, request_id: u32) -> Result<bool> {
let (result_tx, result_rx) = oneshot::channel();
self.commands
.send(EngineCommand::CancelConnect {
request_id,
result: result_tx,
})
.await
.map_err(|_| native_closed_error())?;
result_rx.await.map_err(|_| native_closed_error())
}

#[napi]
pub async fn accept(&self) -> Result<Option<PeerStream>> {
let mut incoming = self.incoming.lock().await;
Expand Down
Loading
Loading