From 467979971aff472e4d2a9724f8cce1c3c84da7c4 Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Mon, 10 Mar 2025 18:27:32 +0000 Subject: [PATCH] Fix update process to properly handle completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Enhanced applyUpdate function to handle both original and floating buttons - Added immediate update notification removal after successful update - Implemented proper countdown display on both update buttons - Added localStorage cleanup to ensure clean page reload - Fixed error handling to re-enable both buttons on failure - Improved page reload with forced clean URL (no hash fragments) - Added consistent handling across success and error cases - Created updateCountdown function for cleaner code reuse 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- public/js/system-status.js | 104 ++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 14 deletions(-) diff --git a/public/js/system-status.js b/public/js/system-status.js index f8a1aaa..afd2079 100644 --- a/public/js/system-status.js +++ b/public/js/system-status.js @@ -304,15 +304,36 @@ function initSystemStatus() { return; } - // Show loading state - updateButton.disabled = true; - updateButton.innerHTML = ' Updating...'; + // Show loading state on both update buttons + // Original button + if (updateButton) { + updateButton.disabled = true; + updateButton.innerHTML = ' Updating...'; + } + + // Floating notification button + const floatingButton = document.getElementById('floating-update-button'); + if (floatingButton) { + floatingButton.disabled = true; + floatingButton.textContent = 'Updating...'; + } + showNotification('Applying update. Please wait...', 'info'); // Set a timeout for the update process const updateTimeoutId = setTimeout(() => { - updateButton.disabled = false; - updateButton.innerHTML = ' Update Now'; + // Re-enable original button + if (updateButton) { + updateButton.disabled = false; + updateButton.innerHTML = ' Update Now'; + } + + // Re-enable floating button + if (floatingButton) { + floatingButton.disabled = false; + floatingButton.textContent = 'Update Now'; + } + showNotification('Update process timed out. Please try again or check server logs.', 'warning'); }, 60000); // 60 second timeout for the entire update process @@ -354,38 +375,93 @@ function initSystemStatus() { clearTimeout(updateTimeoutId); if (data.status === 'success') { + // Hide update notification immediately after successful update + hideUpdateAlert(); + + // Show success notification showNotification('Update applied successfully. The page will reload in 30 seconds.', 'success'); - // Show a countdown to reload + // Update both buttons with countdown let secondsLeft = 30; - updateButton.innerHTML = ` Reloading in ${secondsLeft}s...`; + // Function to update the countdown text + function updateCountdown() { + // Update original button if it exists + if (updateButton) { + updateButton.innerHTML = ` Reloading in ${secondsLeft}s...`; + } + + // Update floating button if it exists + const floatingButton = document.getElementById('floating-update-button'); + if (floatingButton) { + floatingButton.textContent = `Reloading in ${secondsLeft}s...`; + } + } + + // Initial text update + updateCountdown(); + + // Start countdown const countdownInterval = setInterval(() => { secondsLeft--; - updateButton.innerHTML = ` Reloading in ${secondsLeft}s...`; + updateCountdown(); if (secondsLeft <= 0) { clearInterval(countdownInterval); - window.location.reload(); + + // Clear localStorage to ensure a clean reload + localStorage.removeItem(UPDATE_KEY); + localStorage.removeItem(CURRENT_VERSION_KEY); + localStorage.removeItem(REMOTE_VERSION_KEY); + + // Force a clean reload + window.location.href = window.location.href.split('#')[0]; } }, 1000); // Set a timer to reload the page after the service has time to restart setTimeout(() => { clearInterval(countdownInterval); - window.location.reload(); + + // Clear localStorage to ensure a clean reload + localStorage.removeItem(UPDATE_KEY); + localStorage.removeItem(CURRENT_VERSION_KEY); + localStorage.removeItem(REMOTE_VERSION_KEY); + + // Force a clean reload + window.location.href = window.location.href.split('#')[0]; }, 30000); } else { - updateButton.disabled = false; - updateButton.innerHTML = ' Update Now'; + // Enable both buttons on failure + if (updateButton) { + updateButton.disabled = false; + updateButton.innerHTML = ' Update Now'; + } + + const floatingButton = document.getElementById('floating-update-button'); + if (floatingButton) { + floatingButton.disabled = false; + floatingButton.textContent = 'Update Now'; + } + showNotification(data.message || 'Failed to apply update', 'danger'); } }) .catch(error => { clearTimeout(updateTimeoutId); console.error('Error applying update:', error); - updateButton.disabled = false; - updateButton.innerHTML = ' Update Now'; + + // Re-enable both buttons on error + if (updateButton) { + updateButton.disabled = false; + updateButton.innerHTML = ' Update Now'; + } + + const floatingButton = document.getElementById('floating-update-button'); + if (floatingButton) { + floatingButton.disabled = false; + floatingButton.textContent = 'Update Now'; + } // More specific error message based on the error type if (error.name === 'AbortError') {