fix
This commit is contained in:
parent
0e94f047c0
commit
1dc39decf7
45
app.js
45
app.js
@ -21,7 +21,38 @@ window.openTerminals = {};
|
||||
let activePeer = null;
|
||||
window.activePeer = null; // Expose to other modules
|
||||
hideStatusIndicator();
|
||||
let statsInterval = null; // Global variable to hold the interval
|
||||
|
||||
function stopStatsInterval() {
|
||||
if (statsInterval) {
|
||||
clearInterval(statsInterval);
|
||||
statsInterval = null;
|
||||
console.log('[INFO] Stats interval stopped.');
|
||||
}
|
||||
}
|
||||
|
||||
function startStatsInterval() {
|
||||
// Clear any existing interval
|
||||
if (statsInterval) {
|
||||
clearInterval(statsInterval);
|
||||
}
|
||||
|
||||
// Start a new interval to request stats every second
|
||||
statsInterval = setInterval(() => {
|
||||
if (window.activePeer) {
|
||||
console.log('[INFO] Requesting container stats...');
|
||||
sendCommand('stats', {}); // Adjust the command if specific arguments are needed
|
||||
} else {
|
||||
console.warn('[WARN] No active peer; skipping stats request.');
|
||||
}
|
||||
}, 1000); // 1 second interval
|
||||
}
|
||||
|
||||
function refreshContainerStats() {
|
||||
console.log('[INFO] Refreshing container stats...');
|
||||
sendCommand('listContainers'); // Request an updated container list
|
||||
startStatsInterval(); // Restart stats interval
|
||||
}
|
||||
|
||||
function waitForPeerResponse(expectedMessageFragment, timeout = 900000) {
|
||||
console.log(`[DEBUG] Waiting for peer response with fragment: "${expectedMessageFragment}"`);
|
||||
@ -486,6 +517,7 @@ function switchConnection(topicId) {
|
||||
if (!connection || !connection.peer) {
|
||||
console.error('[ERROR] No connection found or no active peer.');
|
||||
showWelcomePage();
|
||||
stopStatsInterval(); // Stop stats interval if no active peer
|
||||
return;
|
||||
}
|
||||
|
||||
@ -496,9 +528,14 @@ function switchConnection(topicId) {
|
||||
resetContainerList();
|
||||
|
||||
console.log(`[INFO] Switched to connection: ${topicId}`);
|
||||
|
||||
// Start the stats interval
|
||||
startStatsInterval();
|
||||
|
||||
sendCommand('listContainers'); // Request containers for the new connection
|
||||
}
|
||||
|
||||
|
||||
// Attach switchConnection to the global window object
|
||||
window.switchConnection = switchConnection;
|
||||
|
||||
@ -595,6 +632,9 @@ function addActionListeners(row, container) {
|
||||
|
||||
// Refresh the container list to update states
|
||||
sendCommand('listContainers');
|
||||
|
||||
// Restart stats interval
|
||||
startStatsInterval();
|
||||
} catch (error) {
|
||||
console.error('[ERROR] Failed to start container:', error.message);
|
||||
showAlert('danger', error.message || 'Failed to start container.');
|
||||
@ -604,6 +644,7 @@ function addActionListeners(row, container) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
stopBtn.addEventListener('click', async () => {
|
||||
showStatusIndicator(`Stopping container "${container.Names[0]}"...`);
|
||||
sendCommand('stopContainer', { id: container.Id });
|
||||
@ -618,6 +659,9 @@ function addActionListeners(row, container) {
|
||||
|
||||
// Refresh the container list to update states
|
||||
sendCommand('listContainers');
|
||||
|
||||
// Restart stats interval
|
||||
startStatsInterval();
|
||||
} catch (error) {
|
||||
console.error('[ERROR] Failed to stop container:', error.message);
|
||||
showAlert('danger', error.message || 'Failed to stop container.');
|
||||
@ -628,6 +672,7 @@ function addActionListeners(row, container) {
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Restart Button
|
||||
restartBtn.addEventListener('click', async () => {
|
||||
showStatusIndicator(`Restarting container "${container.Names[0]}"...`);
|
||||
|
Loading…
Reference in New Issue
Block a user