fix: UI Not updating when start button is used

This commit is contained in:
MCHost
2025-06-16 13:25:30 -04:00
parent 09d206ef13
commit f655fbe037

View File

@ -381,7 +381,6 @@ document.addEventListener('DOMContentLoaded', () => {
} }
} }
function updateDockerUI(message) { function updateDockerUI(message) {
//console.log('Updating Docker UI:', message); //console.log('Updating Docker UI:', message);
if (message.error) { if (message.error) {
@ -1302,14 +1301,44 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById('startBtn').addEventListener('click', async () => { document.getElementById('startBtn').addEventListener('click', async () => {
try { try {
const notification = showNotification('Starting server...');
await wsRequest('/start'); await wsRequest('/start');
initializeTerminal(); initializeTerminal();
if (ws && ws.readyState === WebSocket.OPEN) { if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'subscribe', endpoints: ['docker-logs'] })); ws.send(JSON.stringify({ type: 'subscribe', endpoints: ['docker', 'docker-logs'] }));
//console.log('Re-subscribed to docker-logs after starting server');
} else { } 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) { } catch (error) {
console.error('Start server error:', error); console.error('Start server error:', error);
showNotification(`Failed to start server: ${error.message}`, 'error'); showNotification(`Failed to start server: ${error.message}`, 'error');