Skip to content

Commit 9405824

Browse files
committed
Add loading spinner to MCP add button during polling
- Send mcp-polling-started event from main process before each poll - Show spinner on add button when polling starts - Restore + button when mcp-servers-updated event received - Spinner shows on initial load and every 60s refresh
1 parent 639ec0a commit 9405824

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ function spawnMcpPoller(sessionId: string, projectDir: string) {
158158
console.log(`[MCP Poller ${sessionId}] Starting polling loop`);
159159
const pollMcp = () => {
160160
if (mcpPollerPtyProcesses.has(sessionId)) {
161+
// Notify renderer that polling is starting
162+
if (mainWindow && !mainWindow.isDestroyed()) {
163+
mainWindow.webContents.send("mcp-polling-started", sessionId);
164+
}
165+
161166
const command = `claude mcp list`;
162167
console.log(`[MCP Poller ${sessionId}] Running command: ${command}`);
163168
ptyProcess.write(command + "\r");

renderer.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const DEFAULT_SETTINGS: TerminalSettings = {
225225
const sessions = new Map<string, Session>();
226226
let activeSessionId: string | null = null;
227227
let mcpServers: McpServer[] = [];
228+
let mcpPollerActive = false;
228229
let terminalSettings: TerminalSettings = { ...DEFAULT_SETTINGS };
229230

230231
function createTerminalUI(sessionId: string) {
@@ -962,25 +963,11 @@ async function loadMcpServers() {
962963
return;
963964
}
964965

965-
const addMcpServerBtn = document.getElementById("add-mcp-server");
966-
967-
// Show loading spinner
968-
if (addMcpServerBtn) {
969-
addMcpServerBtn.innerHTML = '<span class="loading-spinner"></span>';
970-
addMcpServerBtn.classList.add("pointer-events-none");
971-
}
972-
973966
try {
974967
await ipcRenderer.invoke("list-mcp-servers", activeSessionId);
975968
// Results will come via mcp-servers-updated event
976969
} catch (error) {
977970
console.error("Failed to load MCP servers:", error);
978-
} finally {
979-
// Restore button
980-
if (addMcpServerBtn) {
981-
addMcpServerBtn.innerHTML = '+';
982-
addMcpServerBtn.classList.remove("pointer-events-none");
983-
}
984971
}
985972
}
986973

@@ -1243,12 +1230,34 @@ removeMcpDetailsBtn?.addEventListener("click", async () => {
12431230
}
12441231
});
12451232

1233+
// Listen for MCP polling started event
1234+
ipcRenderer.on("mcp-polling-started", (_event, sessionId: string) => {
1235+
console.log(`[MCP UI] Polling started for session ${sessionId}, active: ${activeSessionId}`);
1236+
if (sessionId === activeSessionId) {
1237+
const addMcpServerBtn = document.getElementById("add-mcp-server");
1238+
if (addMcpServerBtn) {
1239+
console.log("[MCP UI] Setting add button to loading state");
1240+
addMcpServerBtn.innerHTML = '<span class="loading-spinner"></span>';
1241+
addMcpServerBtn.classList.add("pointer-events-none");
1242+
}
1243+
}
1244+
});
1245+
12461246
// Listen for MCP server updates from main process
12471247
ipcRenderer.on("mcp-servers-updated", (_event, sessionId: string, servers: McpServer[]) => {
1248+
console.log(`[MCP UI] Received update for session ${sessionId}, active: ${activeSessionId}`);
12481249
// Only update if this is for the active session
12491250
if (sessionId === activeSessionId) {
12501251
mcpServers = servers;
12511252
renderMcpServers();
1253+
1254+
// Restore add button
1255+
console.log("[MCP UI] Restoring add button from loading state");
1256+
const addMcpServerBtn = document.getElementById("add-mcp-server");
1257+
if (addMcpServerBtn) {
1258+
addMcpServerBtn.innerHTML = '+';
1259+
addMcpServerBtn.classList.remove("pointer-events-none");
1260+
}
12521261
}
12531262
});
12541263

0 commit comments

Comments
 (0)