Fix update process to properly handle completion

- 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 <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-10 18:27:32 +00:00
parent 5ce348d61e
commit 467979971a

View File

@ -304,15 +304,36 @@ function initSystemStatus() {
return; return;
} }
// Show loading state // Show loading state on both update buttons
// Original button
if (updateButton) {
updateButton.disabled = true; updateButton.disabled = true;
updateButton.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> Updating...'; updateButton.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> 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'); showNotification('Applying update. Please wait...', 'info');
// Set a timeout for the update process // Set a timeout for the update process
const updateTimeoutId = setTimeout(() => { const updateTimeoutId = setTimeout(() => {
// Re-enable original button
if (updateButton) {
updateButton.disabled = false; updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now'; updateButton.innerHTML = '<i class="fas fa-download"></i> 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'); showNotification('Update process timed out. Please try again or check server logs.', 'warning');
}, 60000); // 60 second timeout for the entire update process }, 60000); // 60 second timeout for the entire update process
@ -354,38 +375,93 @@ function initSystemStatus() {
clearTimeout(updateTimeoutId); clearTimeout(updateTimeoutId);
if (data.status === 'success') { 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'); 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; let secondsLeft = 30;
updateButton.innerHTML = `<i class="fas fa-sync"></i> Reloading in ${secondsLeft}s...`;
// Function to update the countdown text
function updateCountdown() {
// Update original button if it exists
if (updateButton) {
updateButton.innerHTML = `<i class="fas fa-sync"></i> 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(() => { const countdownInterval = setInterval(() => {
secondsLeft--; secondsLeft--;
updateButton.innerHTML = `<i class="fas fa-sync"></i> Reloading in ${secondsLeft}s...`; updateCountdown();
if (secondsLeft <= 0) { if (secondsLeft <= 0) {
clearInterval(countdownInterval); 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); }, 1000);
// Set a timer to reload the page after the service has time to restart // Set a timer to reload the page after the service has time to restart
setTimeout(() => { setTimeout(() => {
clearInterval(countdownInterval); 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); }, 30000);
} else { } else {
// Enable both buttons on failure
if (updateButton) {
updateButton.disabled = false; updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now'; updateButton.innerHTML = '<i class="fas fa-download"></i> 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'); showNotification(data.message || 'Failed to apply update', 'danger');
} }
}) })
.catch(error => { .catch(error => {
clearTimeout(updateTimeoutId); clearTimeout(updateTimeoutId);
console.error('Error applying update:', error); console.error('Error applying update:', error);
// Re-enable both buttons on error
if (updateButton) {
updateButton.disabled = false; updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now'; updateButton.innerHTML = '<i class="fas fa-download"></i> 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 // More specific error message based on the error type
if (error.name === 'AbortError') { if (error.name === 'AbortError') {