- Fix bug in dependencies-module.sh that would prompt to install transmission-daemon for remote installations - Add checks for TRANSMISSION_REMOTE flag to correctly handle remote vs local installations - Update version to 2.0.2 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
131 lines
4.8 KiB
JavaScript
131 lines
4.8 KiB
JavaScript
// Client-side JavaScript for system status and updates
|
|
// Add this to the public/js/app.js file
|
|
|
|
// System status and updates functionality
|
|
function initSystemStatus() {
|
|
// Elements
|
|
const versionElement = document.getElementById('system-version');
|
|
const uptimeElement = document.getElementById('uptime');
|
|
const transmissionStatusElement = document.getElementById('transmission-status');
|
|
const updateStatusElement = document.getElementById('update-status');
|
|
const updateAvailableDiv = document.getElementById('update-available');
|
|
const updateButton = document.getElementById('btn-update-now');
|
|
const refreshButton = document.getElementById('btn-refresh-status');
|
|
|
|
// Load system status
|
|
function loadSystemStatus() {
|
|
fetch('/api/system/status')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status === 'success') {
|
|
versionElement.textContent = data.data.version;
|
|
uptimeElement.textContent = data.data.uptime;
|
|
|
|
// Update transmission status with icon
|
|
if (data.data.transmissionStatus === 'Connected') {
|
|
transmissionStatusElement.innerHTML = '<i class="fas fa-check-circle text-success"></i> Connected';
|
|
} else {
|
|
transmissionStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Disconnected';
|
|
}
|
|
} else {
|
|
showToast('error', 'Failed to load system status');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error fetching system status:', error);
|
|
showToast('error', 'Failed to connect to server');
|
|
});
|
|
}
|
|
|
|
// Check for updates
|
|
function checkForUpdates() {
|
|
updateStatusElement.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> Checking...';
|
|
updateAvailableDiv.classList.add('d-none');
|
|
|
|
fetch('/api/system/check-updates')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status === 'success') {
|
|
if (data.data.updateAvailable) {
|
|
updateStatusElement.innerHTML = '<i class="fas fa-exclamation-circle text-warning"></i> Update available';
|
|
updateAvailableDiv.classList.remove('d-none');
|
|
updateAvailableDiv.querySelector('span').textContent =
|
|
`A new version is available: ${data.data.currentVersion} → ${data.data.remoteVersion}`;
|
|
} else {
|
|
updateStatusElement.innerHTML = '<i class="fas fa-check-circle text-success"></i> Up to date';
|
|
}
|
|
} else {
|
|
updateStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Check failed';
|
|
showToast('error', data.message || 'Failed to check for updates');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error checking for updates:', error);
|
|
updateStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Check failed';
|
|
showToast('error', 'Failed to connect to server');
|
|
});
|
|
}
|
|
|
|
// Apply update
|
|
function applyUpdate() {
|
|
// Show confirmation dialog
|
|
if (!confirm('Are you sure you want to update the application? The service will restart.')) {
|
|
return;
|
|
}
|
|
|
|
// Show loading state
|
|
updateButton.disabled = true;
|
|
updateButton.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> Updating...';
|
|
showToast('info', 'Applying update. Please wait...');
|
|
|
|
fetch('/api/system/update', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status === 'success') {
|
|
showToast('success', 'Update applied successfully. The page will reload in 30 seconds.');
|
|
// Set a timer to reload the page after the service has time to restart
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 30000);
|
|
} else {
|
|
updateButton.disabled = false;
|
|
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now';
|
|
showToast('error', data.message || 'Failed to apply update');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error applying update:', error);
|
|
updateButton.disabled = false;
|
|
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now';
|
|
showToast('error', 'Failed to connect to server');
|
|
});
|
|
}
|
|
|
|
// Event listeners
|
|
if (refreshButton) {
|
|
refreshButton.addEventListener('click', () => {
|
|
loadSystemStatus();
|
|
checkForUpdates();
|
|
});
|
|
}
|
|
|
|
if (updateButton) {
|
|
updateButton.addEventListener('click', applyUpdate);
|
|
}
|
|
|
|
// Initialize
|
|
loadSystemStatus();
|
|
checkForUpdates();
|
|
|
|
// Set interval to refresh uptime every minute
|
|
setInterval(loadSystemStatus, 60000);
|
|
}
|
|
|
|
// Call this function from the main init function
|
|
// Add this line to your document ready or DOMContentLoaded handler:
|
|
// initSystemStatus();
|