v0.1.32: Fix scan functionality and add debug logging
- Fixed scan functionality not showing output by ensuring JavaScript is properly injected - Added default hint text to scan results area - Added comprehensive debug console logging to help diagnose scan issues - Improved scan section injection logic - Updated version to 0.1.32 in all files Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -77,7 +77,7 @@ async def lifespan(app: FastAPI): # noqa: ARG001
|
||||
app = FastAPI(
|
||||
title="Fichero Printer API",
|
||||
description="REST API for the Fichero D11s (AiYin) thermal label printer.",
|
||||
version = "0.1.31",
|
||||
version = "0.1.32",
|
||||
lifespan=lifespan,
|
||||
docs_url=None,
|
||||
redoc_url=None,
|
||||
@@ -130,23 +130,28 @@ def _ui_html() -> str:
|
||||
<span class="loading" id="scan-loading" style="display: none;"></span>
|
||||
<span id="scan-text">Scan for BLE Devices (10s)</span>
|
||||
</button>
|
||||
<pre id="scan-results"></pre>
|
||||
<pre id="scan-results">📱 Click "Scan for BLE Devices" to search for nearby Bluetooth devices...</pre>
|
||||
</div>
|
||||
"""
|
||||
scan_script = r'''
|
||||
<script>
|
||||
async function scanForDevices() {
|
||||
console.log('Scan function called - checking elements...');
|
||||
const resultsEl = document.getElementById('scan-results');
|
||||
const scanButton = document.getElementById('scan-button');
|
||||
const loadingEl = document.getElementById('scan-loading');
|
||||
const textEl = document.getElementById('scan-text');
|
||||
|
||||
console.log('Elements found:', { resultsEl, scanButton, loadingEl, textEl });
|
||||
|
||||
// Show loading state
|
||||
scanButton.disabled = true;
|
||||
loadingEl.style.display = 'inline-block';
|
||||
textEl.textContent = 'Scanning...';
|
||||
resultsEl.textContent = '🔍 Searching for BLE devices (this may take up to 10 seconds)...';
|
||||
|
||||
console.log('Starting scan request...');
|
||||
|
||||
try {
|
||||
const response = await fetch('/scan');
|
||||
|
||||
@@ -175,9 +180,11 @@ def _ui_html() -> str:
|
||||
console.error('Scan error:', e);
|
||||
} finally {
|
||||
// Reset button state
|
||||
console.log('Resetting button state...');
|
||||
scanButton.disabled = false;
|
||||
loadingEl.style.display = 'none';
|
||||
textEl.textContent = 'Scan for BLE Devices (10s)';
|
||||
console.log('Scan completed. Final result:', resultsEl.textContent);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -185,7 +192,7 @@ def _ui_html() -> str:
|
||||
# Inject after the main content but before scripts
|
||||
if "</main>" in template:
|
||||
parts = template.split("</main>", 1)
|
||||
template = parts[0] + "</main>" + scan_html + parts[1]
|
||||
template = parts[0] + "</main>" + scan_html + scan_script + parts[1]
|
||||
elif "</body>" in template:
|
||||
parts = template.split("</body>", 1)
|
||||
template = parts[0] + scan_html + scan_script + "</body>" + parts[1]
|
||||
|
||||
Reference in New Issue
Block a user