fix(app): preserve workspace route during desktop refresh

This commit is contained in:
Mohamed Boudra
2026-06-11 16:08:50 +07:00
parent f5a7055e7e
commit d802534e7b
12 changed files with 395 additions and 235 deletions
+23 -2
View File
@@ -40,6 +40,7 @@ import { replaceFetchedAgentDirectory } from "@/utils/agent-directory-sync";
import { useSessionStore } from "@/stores/session-store";
export type HostRuntimeConnectionStatus = "idle" | "connecting" | "online" | "offline" | "error";
export type HostRegistryStatus = "loading" | "ready";
export type ActiveConnection =
| { type: "directTcp"; endpoint: string; display: string }
@@ -1238,6 +1239,7 @@ export class HostRuntimeStore {
private version = 0;
private hostListVersion = 0;
private hosts: HostProfile[] = [];
private hostRegistryStatus: HostRegistryStatus = "loading";
private deps: HostRuntimeControllerDeps;
private lastConnectionStatusByServer = new Map<string, HostRuntimeConnectionStatus>();
private agentDirectoryBootstrapInFlight = new Map<string, Promise<void>>();
@@ -1254,6 +1256,10 @@ export class HostRuntimeStore {
return this.hosts;
}
getHostRegistryStatus(): HostRegistryStatus {
return this.hostRegistryStatus;
}
subscribeHostList(listener: () => void): () => void {
this.hostListListeners.add(listener);
return () => {
@@ -1299,6 +1305,7 @@ export class HostRuntimeStore {
}
private async loadFromStorage(): Promise<void> {
let shouldPersistHosts = false;
try {
const stored = await AsyncStorage.getItem(REGISTRY_STORAGE_KEY);
if (!stored) {
@@ -1314,12 +1321,17 @@ export class HostRuntimeStore {
const profiles = normalizedProfiles.filter((entry) => !isPlaceholderServerId(entry.serverId));
this.hosts = profiles;
this.syncHosts(profiles);
this.emitHostList();
if (profiles.length !== normalizedProfiles.length) {
void this.persistHosts();
shouldPersistHosts = true;
}
} catch (error) {
console.error("[HostRuntime] Failed to load host registry from storage", error);
} finally {
this.hostRegistryStatus = "ready";
this.emitHostList();
if (shouldPersistHosts) {
void this.persistHosts();
}
}
}
@@ -2069,6 +2081,15 @@ export function useHosts(): HostProfile[] {
);
}
export function useHostRegistryStatus(): HostRegistryStatus {
const store = getHostRuntimeStore();
return useSyncExternalStore(
(onStoreChange) => store.subscribeHostList(onStoreChange),
() => store.getHostRegistryStatus(),
() => store.getHostRegistryStatus(),
);
}
export interface HostMutations {
upsertDirectConnection: (input: {
serverId: string;