From f655fbe0378d22f74d9fe8124921a36ed6dad00d Mon Sep 17 00:00:00 2001 From: MCHost Date: Mon, 16 Jun 2025 13:25:30 -0400 Subject: [PATCH] fix: UI Not updating when start button is used --- public/app.js | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/public/app.js b/public/app.js index 543cf66..e3e2f49 100644 --- a/public/app.js +++ b/public/app.js @@ -381,7 +381,6 @@ document.addEventListener('DOMContentLoaded', () => { } } - function updateDockerUI(message) { //console.log('Updating Docker UI:', message); if (message.error) { @@ -1302,14 +1301,44 @@ document.addEventListener('DOMContentLoaded', () => { document.getElementById('startBtn').addEventListener('click', async () => { try { + const notification = showNotification('Starting server...'); await wsRequest('/start'); initializeTerminal(); if (ws && ws.readyState === WebSocket.OPEN) { - ws.send(JSON.stringify({ type: 'subscribe', endpoints: ['docker-logs'] })); - //console.log('Re-subscribed to docker-logs after starting server'); + ws.send(JSON.stringify({ type: 'subscribe', endpoints: ['docker', 'docker-logs'] })); } else { - console.warn('WebSocket not connected, cannot subscribe to docker-logs'); + console.warn('WebSocket not connected, cannot subscribe to docker events'); + updateNotification(notification, 'WebSocket not connected', 'error'); + return; } + // Poll server status until it becomes 'Running' or timeout + let attempts = 0; + const maxAttempts = 30; // 30 seconds (1 second per attempt) + const checkStatus = async () => { + try { + const response = await wsRequest('/status', 'GET'); + const status = response?.data?.status || 'Unknown'; + if (status.toLowerCase() === 'running') { + updateNotification(notification, 'Server started successfully', 'success'); + state.serverStatus = status; + elements.serverStatus.textContent = status; + toggleSections(status); + } else if (attempts < maxAttempts) { + attempts++; + setTimeout(checkStatus, 1000); + } else { + updateNotification(notification, 'Server start timed out', 'error'); + } + } catch (error) { + if (attempts < maxAttempts) { + attempts++; + setTimeout(checkStatus, 1000); + } else { + updateNotification(notification, `Failed to verify server status: ${error.message}`, 'error'); + } + } + }; + setTimeout(checkStatus, 1000); } catch (error) { console.error('Start server error:', error); showNotification(`Failed to start server: ${error.message}`, 'error');