diff --git a/public/js/system-status.js b/public/js/system-status.js index afd2079..63d3b05 100644 --- a/public/js/system-status.js +++ b/public/js/system-status.js @@ -16,7 +16,9 @@ function initSystemStatus() { // Load system status function loadSystemStatus() { - fetch('/api/system/status', { + // Add cache-busting parameter + const cacheBuster = `?_=${new Date().getTime()}`; + fetch('/api/system/status' + cacheBuster, { headers: authHeaders() }) .then(handleResponse) @@ -214,7 +216,10 @@ function initSystemStatus() { // Add test=true parameter to force update availability for testing const testMode = localStorage.getItem('showUpdateButton') === 'true'; - const url = testMode ? '/api/system/check-updates?test=true' : '/api/system/check-updates'; + const cacheBuster = `_=${new Date().getTime()}`; + const url = testMode + ? `/api/system/check-updates?test=true&${cacheBuster}` + : `/api/system/check-updates?${cacheBuster}`; // Set a timeout to detect network issues const timeoutId = setTimeout(() => { @@ -375,9 +380,34 @@ function initSystemStatus() { clearTimeout(updateTimeoutId); if (data.status === 'success') { - // Hide update notification immediately after successful update + // Check if there's an update message to determine if an update was actually applied + const updateApplied = data.message && data.message.includes('Update applied successfully'); + const noNewUpdate = data.data && data.data.output && data.data.output.includes('already have the latest version'); + + // Hide update notification hideUpdateAlert(); + if (noNewUpdate) { + // If no update was needed, show a different message + showNotification('You already have the latest version. No update was needed.', 'info'); + + // Re-enable both buttons + if (updateButton) { + updateButton.disabled = false; + updateButton.innerHTML = ' Check Again'; + } + + const floatingButton = document.getElementById('floating-update-button'); + if (floatingButton) { + floatingButton.disabled = false; + floatingButton.textContent = 'Check Again'; + } + + // Update page to show current version without reloading + loadSystemStatus(); + return; + } + // Show success notification showNotification('Update applied successfully. The page will reload in 30 seconds.', 'success'); @@ -415,7 +445,7 @@ function initSystemStatus() { localStorage.removeItem(REMOTE_VERSION_KEY); // Force a clean reload - window.location.href = window.location.href.split('#')[0]; + window.location.href = window.location.href.split('#')[0] + '?t=' + new Date().getTime(); } }, 1000); @@ -428,8 +458,8 @@ function initSystemStatus() { localStorage.removeItem(CURRENT_VERSION_KEY); localStorage.removeItem(REMOTE_VERSION_KEY); - // Force a clean reload - window.location.href = window.location.href.split('#')[0]; + // Force a clean reload with cache-busting parameter + window.location.href = window.location.href.split('#')[0] + '?t=' + new Date().getTime(); }, 30000); } else { // Enable both buttons on failure @@ -512,7 +542,22 @@ function initSystemStatus() { } else { // If disabling test mode, check for real updates hideUpdateAlert(); - checkForUpdates(); + + // Force a check without the test parameter to get real status + const realCheckUrl = '/api/system/check-updates'; + fetch(realCheckUrl, { headers: authHeaders() }) + .then(response => response.json()) + .then(data => { + console.log('Real update check result:', data); + if (data.status === 'success' && data.data && !data.data.updateAvailable) { + showNotification('No actual updates are available.', 'info'); + } else if (data.status === 'success' && data.data && data.data.updateAvailable) { + showUpdateAlert(data.data.currentVersion, data.data.remoteVersion); + showNotification(`A real update is available: ${data.data.currentVersion} → ${data.data.remoteVersion}`, 'info'); + } + }) + .catch(error => console.error('Error checking for real updates:', error)); + showNotification('Test update button disabled', 'info'); } });