+
+
A new version is available!
+
+
+
diff --git a/public/js/system-status.js b/public/js/system-status.js
index fe93106..d55adf6 100644
--- a/public/js/system-status.js
+++ b/public/js/system-status.js
@@ -54,31 +54,61 @@ function initSystemStatus() {
});
}
- // Track update check status
- let updateAvailable = localStorage.getItem('updateAvailable') === 'true';
+ // More robust update check status tracking
+ const UPDATE_KEY = 'trm_update_available';
+ const CURRENT_VERSION_KEY = 'trm_current_version';
+ const REMOTE_VERSION_KEY = 'trm_remote_version';
let updateCheckInProgress = false;
- // If we have stored update info, restore it
- if (updateAvailable) {
- const currentVersion = localStorage.getItem('currentVersion');
- const remoteVersion = localStorage.getItem('remoteVersion');
+ // Function to show update alert
+ function showUpdateAlert(currentVersion, remoteVersion) {
+ // Set status text
+ updateStatusElement.innerHTML = '
Update available';
- if (currentVersion && remoteVersion) {
- updateStatusElement.innerHTML = '
Update available';
- updateAvailableDiv.classList.remove('d-none');
- updateAvailableDiv.style.display = 'block'; // Force display
- updateAvailableDiv.querySelector('span').textContent =
- `A new version is available: ${currentVersion} → ${remoteVersion}`;
+ // Show alert box
+ const alertBox = updateAvailableDiv.querySelector('.alert');
+ if (alertBox) {
+ alertBox.style.display = 'block';
+ // Update message
+ const spanElement = alertBox.querySelector('span');
+ if (spanElement) {
+ spanElement.textContent = `A new version is available: ${currentVersion} → ${remoteVersion}`;
+ }
}
+
+ // Store in localStorage
+ localStorage.setItem(UPDATE_KEY, 'true');
+ localStorage.setItem(CURRENT_VERSION_KEY, currentVersion);
+ localStorage.setItem(REMOTE_VERSION_KEY, remoteVersion);
}
+ // Function to hide update alert
+ function hideUpdateAlert() {
+ const alertBox = updateAvailableDiv.querySelector('.alert');
+ if (alertBox) {
+ alertBox.style.display = 'none';
+ }
+
+ // Clear localStorage
+ localStorage.removeItem(UPDATE_KEY);
+ localStorage.removeItem(CURRENT_VERSION_KEY);
+ localStorage.removeItem(REMOTE_VERSION_KEY);
+ }
+
+ // Check localStorage on init
+ (function checkStoredUpdateStatus() {
+ const isUpdateAvailable = localStorage.getItem(UPDATE_KEY) === 'true';
+ if (isUpdateAvailable) {
+ const currentVersion = localStorage.getItem(CURRENT_VERSION_KEY);
+ const remoteVersion = localStorage.getItem(REMOTE_VERSION_KEY);
+ if (currentVersion && remoteVersion) {
+ showUpdateAlert(currentVersion, remoteVersion);
+ }
+ }
+ })();
+
// Check for updates
function checkForUpdates() {
- // Don't hide update button if an update is available and we're just refreshing
- if (!updateAvailable) {
- updateAvailableDiv.classList.add('d-none');
- }
-
updateStatusElement.innerHTML = '
Checking...';
updateCheckInProgress = true;
@@ -131,30 +161,21 @@ function initSystemStatus() {
if (data.status === 'success') {
if (data.data && data.data.updateAvailable) {
- updateAvailable = true;
- updateStatusElement.innerHTML = '
Update available';
+ // Show update alert with version info
+ showUpdateAlert(data.data.currentVersion, data.data.remoteVersion);
- // Make update button visible immediately
- updateAvailableDiv.classList.remove('d-none');
- updateAvailableDiv.style.display = 'block'; // Force display
-
- updateAvailableDiv.querySelector('span').textContent =
- `A new version is available: ${data.data.currentVersion} → ${data.data.remoteVersion}`;
-
- // Store update info in localStorage to persist across refreshes
- localStorage.setItem('updateAvailable', 'true');
- localStorage.setItem('currentVersion', data.data.currentVersion);
- localStorage.setItem('remoteVersion', data.data.remoteVersion);
+ // Log to console for debugging
+ console.log('Update available detected:', data.data.currentVersion, '->', data.data.remoteVersion);
} else {
- updateAvailable = false;
+ // No update available
updateStatusElement.innerHTML = '
Up to date';
- localStorage.removeItem('updateAvailable');
+ hideUpdateAlert();
}
} else {
// Error status but with a response
- updateAvailable = false;
updateStatusElement.innerHTML = '
Check failed';
showNotification(data.message || 'Failed to check for updates', 'danger');
+ // Don't clear update status on error - keep any previous update notification
}
})
.catch(error => {
@@ -171,6 +192,8 @@ function initSystemStatus() {
} else {
showNotification(error.message || 'Failed to connect to server', 'danger');
}
+
+ // Don't clear update status on error - keep any previous update notification
});
}
@@ -305,10 +328,17 @@ function initSystemStatus() {
localStorage.setItem('showUpdateButton', newSetting);
testToggle.innerText = newSetting ? 'Disable Test Update' : 'Enable Test Update';
- // Re-check for updates with new setting
- checkForUpdates();
-
- showNotification(`Test update button ${newSetting ? 'enabled' : 'disabled'}`, 'info');
+ if (newSetting) {
+ // If enabling test mode, force show update button
+ showUpdateAlert('2.0.10', '2.1.0-test');
+ updateStatusElement.innerHTML = '
Update available';
+ showNotification('Test update button enabled', 'info');
+ } else {
+ // If disabling test mode, check for real updates
+ hideUpdateAlert();
+ checkForUpdates();
+ showNotification('Test update button disabled', 'info');
+ }
});
}