fix(desktop): race existing connections against bootstrap for faster startup

The Electron startup blocked on a ~2.6s synchronous CLI status check before
showing the app. Now the host runtime controllers (which probe persisted
connections) race against the bootstrap path — if the daemon is already
running, the UI comes online in milliseconds.

Also converts the desktop CLI spawn calls from spawnSync to async spawn
so the Electron main thread is no longer blocked during daemon status checks.
This commit is contained in:
Mohamed Boudra
2026-04-03 23:20:56 +07:00
parent 255c2665cc
commit 71ce95de90
4 changed files with 140 additions and 59 deletions
+35
View File
@@ -1681,6 +1681,41 @@ export class HostRuntimeStore {
};
}
waitForAnyConnectionOnline(): { promise: Promise<void>; cancel: () => void } {
let unsubscribe: (() => void) | null = null;
const isAnyOnline = (): boolean => {
for (const host of this.hosts) {
const snapshot = this.getSnapshot(host.serverId);
if (snapshot?.connectionStatus === "online") return true;
}
return false;
};
const promise = new Promise<void>((resolve) => {
if (isAnyOnline()) {
resolve();
return;
}
unsubscribe = this.subscribeAll(() => {
if (isAnyOnline()) {
unsubscribe?.();
unsubscribe = null;
resolve();
}
});
});
return {
promise,
cancel: () => {
unsubscribe?.();
unsubscribe = null;
},
};
}
ensureConnectedAll(): void {
for (const controller of this.controllers.values()) {
controller.ensureConnected();