- Updated page titles and structure for clarity. - Enhanced sidebar navigation and status indicators. - Improved form styling and user feedback during updates. - Added WebSocket handling for real-time status updates. - Streamlined version fetching logic across pages.
158 lines
6.7 KiB
HTML
158 lines
6.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>FilaMan - Firmware Upgrade</title>
|
|
<link rel="icon" type="image/png" href="/favicon.ico">
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<div class="fm-page">
|
|
<aside class="fm-sidebar">
|
|
<div class="sidebar-brand">
|
|
<img src="/logo.png" alt="Logo" class="sidebar-logo">
|
|
<div class="brand-text">
|
|
<h1>FilaMan <span class="version"></span></h1>
|
|
</div>
|
|
</div>
|
|
<nav class="fm-nav">
|
|
<a href="/">Start</a>
|
|
<a href="/waage">Scale</a>
|
|
<a href="/setup">Setup</a>
|
|
<a href="/upgrade" class="active">Upgrade</a>
|
|
</nav>
|
|
<div class="sidebar-status">
|
|
<div class="status-item">
|
|
<span class="status-dot" id="filamanDot"></span>
|
|
<span>System Sync</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<span id="ramStatus"></span>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<main class="fm-main">
|
|
<header>
|
|
<h1>Firmware Upgrade</h1>
|
|
<p>Keep your device up to date with the latest features and security improvements.</p>
|
|
</header>
|
|
|
|
<div class="fm-card" style="border-color: var(--accent-3);">
|
|
<h3 style="color: var(--accent-3);">Important Warning</h3>
|
|
<p>Do <strong>not</strong> power off the device during the update process. A failed update may require manual recovery.</p>
|
|
</div>
|
|
|
|
<div class="features-grid">
|
|
<div class="fm-card">
|
|
<h2>Firmware Update</h2>
|
|
<p>Upload a new binary firmware file.</p>
|
|
<form id="firmwareForm" enctype='multipart/form-data' data-type="firmware">
|
|
<div class="fm-form-group">
|
|
<input type='file' name='update' accept='.bin' required class="fm-input">
|
|
</div>
|
|
<input type='submit' value='Start Update' class="fm-btn fm-btn-primary" style="width: 100%;">
|
|
</form>
|
|
</div>
|
|
|
|
<div class="fm-card">
|
|
<h2>Webpage Update</h2>
|
|
<p>Update the internal web interface assets.</p>
|
|
<form id="webpageForm" enctype='multipart/form-data' data-type="webpage">
|
|
<div class="fm-form-group">
|
|
<input type='file' name='update' accept='.bin' required class="fm-input">
|
|
</div>
|
|
<input type='submit' value='Start Update' class="fm-btn fm-btn-outline" style="width: 100%;">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="progressContainer" class="fm-card" style="display: none; margin-top: 2rem;">
|
|
<h3 id="updateStatus">Update in progress...</h3>
|
|
<div style="width: 100%; background: var(--bg); height: 24px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); margin: 1rem 0;">
|
|
<div id="progressBar" style="width: 0%; height: 100%; background: var(--accent); transition: width 0.3s ease;"></div>
|
|
</div>
|
|
<p id="detailedStatus" style="font-size: 0.85rem;"></p>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<script>
|
|
// Fetch Version
|
|
fetch('/api/version')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const versionSpan = document.querySelector('.version');
|
|
if (versionSpan) versionSpan.textContent = 'v' + data.version;
|
|
})
|
|
.catch(error => console.error('Error fetching version:', error));
|
|
|
|
const progress = document.getElementById('progressBar');
|
|
const progressContainer = document.getElementById('progressContainer');
|
|
const status = document.getElementById('detailedStatus');
|
|
let updateInProgress = false;
|
|
let lastReceivedProgress = 0;
|
|
|
|
// WebSocket Handling
|
|
let ws = null;
|
|
function connectWebSocket() {
|
|
ws = new WebSocket('ws://' + window.location.host + '/ws');
|
|
ws.onmessage = function(event) {
|
|
const data = JSON.parse(event.data);
|
|
if (data.type === "heartbeat") {
|
|
const dot = document.getElementById('filamanDot');
|
|
dot.className = data.filaman_connected ? 'status-dot online' : 'status-dot offline';
|
|
document.getElementById('ramStatus').textContent = data.freeHeap + ' KB free';
|
|
}
|
|
if (data.type === "updateProgress" && updateInProgress) {
|
|
progressContainer.style.display = 'block';
|
|
const newProgress = parseInt(data.progress);
|
|
if (!isNaN(newProgress) && newProgress >= lastReceivedProgress) {
|
|
progress.style.width = newProgress + '%';
|
|
lastReceivedProgress = newProgress;
|
|
}
|
|
if (data.message) {
|
|
status.textContent = data.message;
|
|
}
|
|
}
|
|
};
|
|
ws.onclose = () => setTimeout(connectWebSocket, 2000);
|
|
}
|
|
connectWebSocket();
|
|
|
|
function handleUpdate(e) {
|
|
e.preventDefault();
|
|
const form = e.target;
|
|
const file = form.update.files[0];
|
|
|
|
if (!file) return;
|
|
|
|
updateInProgress = true;
|
|
progressContainer.style.display = 'block';
|
|
progress.style.width = '0%';
|
|
|
|
document.querySelectorAll('input[type=submit]').forEach(btn => btn.disabled = true);
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/update', true);
|
|
xhr.onload = function() {
|
|
if (xhr.status !== 200) {
|
|
status.textContent = "Update failed: " + xhr.responseText;
|
|
status.style.color = 'var(--error-text)';
|
|
updateInProgress = false;
|
|
document.querySelectorAll('input[type=submit]').forEach(btn => btn.disabled = false);
|
|
}
|
|
};
|
|
|
|
const formData = new FormData();
|
|
formData.append('update', file);
|
|
xhr.send(formData);
|
|
}
|
|
|
|
document.getElementById('firmwareForm').addEventListener('submit', handleUpdate);
|
|
document.getElementById('webpageForm').addEventListener('submit', handleUpdate);
|
|
</script>
|
|
</body>
|
|
</html>
|