fix: UI Not updating when start button is used
This commit is contained in:
@ -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');
|
||||
|
Reference in New Issue
Block a user