|
11 | 11 | */ |
12 | 12 |
|
13 | 13 | import { useCallback, useEffect, useRef, useState } from 'react'; |
| 14 | +import { EcaRemoteApi } from '../bridge/api'; |
14 | 15 | import { probePort, testConnection } from '../bridge/connection'; |
15 | 16 | import type { WebBridge } from '../bridge/transport'; |
16 | 17 | import type { ChatEntry, WorkspaceFolder } from '../bridge/types'; |
@@ -51,13 +52,42 @@ export function RemoteProduct() { |
51 | 52 | // --- Persistence --- |
52 | 53 |
|
53 | 54 | useEffect(() => { |
54 | | - saveConnections(entries.map(({ id, host, password, protocol }) => ({ id, host, password, protocol }))); |
| 55 | + saveConnections(entries.map(({ id, host, password, protocol, workspaceFolders }) => ({ id, host, password, protocol, workspaceFolders }))); |
55 | 56 | }, [entries]); |
56 | 57 |
|
57 | 58 | useEffect(() => { |
58 | 59 | saveActiveId(activeId); |
59 | 60 | }, [activeId]); |
60 | 61 |
|
| 62 | + // --- Proactive workspace folder fetch --- |
| 63 | + // For entries that don't have workspace folders yet (e.g. freshly added or |
| 64 | + // loaded from storage before this feature existed), fire a lightweight |
| 65 | + // session request to populate them. Uses a ref to avoid re-fetching. |
| 66 | + |
| 67 | + const fetchedWorkspaceIdsRef = useRef(new Set<string>()); |
| 68 | + |
| 69 | + useEffect(() => { |
| 70 | + for (const entry of entries) { |
| 71 | + if (entry.workspaceFolders || fetchedWorkspaceIdsRef.current.has(entry.id)) continue; |
| 72 | + fetchedWorkspaceIdsRef.current.add(entry.id); |
| 73 | + |
| 74 | + const api = new EcaRemoteApi(entry.host, entry.password, entry.protocol); |
| 75 | + api.session() |
| 76 | + .then((session) => { |
| 77 | + if (session.workspaceFolders?.length) { |
| 78 | + setEntries((prev) => |
| 79 | + prev.map((e) => |
| 80 | + e.id === entry.id && !e.workspaceFolders |
| 81 | + ? { ...e, workspaceFolders: session.workspaceFolders } |
| 82 | + : e, |
| 83 | + ), |
| 84 | + ); |
| 85 | + } |
| 86 | + }) |
| 87 | + .catch(() => { /* server not reachable yet — will populate when session connects */ }); |
| 88 | + } |
| 89 | + }, [entries]); |
| 90 | + |
61 | 91 | // --- Deep-link on mount --- |
62 | 92 |
|
63 | 93 | useEffect(() => { |
|
0 commit comments