feat: add dead-man's switch overlay and console warning

- Poll /health every 5s; show full-screen overlay after 2 consecutive
  failures telling the user the console was closed
- Auto-hide overlay when backend comes back online
- Added to base.html (all main pages) and setup.html (first-run/settings)
- setup.html: suppress false-positive overlay during intentional restart
  via awaitingRestart flag
- setup.html: add amber warning banner that the console must stay open
- .gitignore: block *_import.sql and *_export.csv to prevent future
  accidental commits of real supplier/pricing data

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-05-15 17:44:28 +03:00
parent 6dbaccdf6f
commit 860ffa0231
3 changed files with 111 additions and 0 deletions

View File

@@ -50,6 +50,25 @@
<div id="toast" class="fixed bottom-4 right-4 z-50"></div>
<!-- Dead-man's switch overlay: shown when backend process stops responding -->
<div id="backend-offline-overlay" class="hidden fixed inset-0 z-[9999] bg-black/80 flex items-center justify-center p-6">
<div class="bg-white rounded-xl shadow-2xl max-w-md w-full p-8 text-center">
<div class="text-red-500 mb-4">
<svg class="w-16 h-16 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
</svg>
</div>
<h2 class="text-xl font-bold text-gray-900 mb-3">Приложение остановлено</h2>
<p class="text-gray-600 mb-4">Консольное окно QuoteForge было закрыто — без него программа не работает.</p>
<div class="bg-amber-50 border border-amber-200 rounded-lg p-3 mb-6 text-sm text-amber-800">
Запустите программу заново и нажмите «Обновить страницу».
</div>
<button onclick="window.location.reload()" class="w-full px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 font-medium">
Обновить страницу
</button>
</div>
</div>
<!-- Sync Info Modal -->
<div id="sync-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
<div class="bg-white rounded-lg shadow-xl max-w-lg w-full max-h-[90vh] flex flex-col">
@@ -493,6 +512,35 @@
loadDBUser();
checkWritePermission();
// Dead-man's switch: detect if the backend process has stopped
(function() {
const POLL_MS = 5000;
const FAIL_THRESHOLD = 2;
let failCount = 0;
async function checkBackend() {
try {
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 3000);
const resp = await fetch('/health', { signal: ctrl.signal });
clearTimeout(timer);
if (resp.ok) {
failCount = 0;
document.getElementById('backend-offline-overlay').classList.add('hidden');
} else {
failCount++;
}
} catch (_) {
failCount++;
}
if (failCount >= FAIL_THRESHOLD) {
document.getElementById('backend-offline-overlay').classList.remove('hidden');
}
}
setInterval(checkBackend, POLL_MS);
})();
// Load last sync time - removed since dropdown is gone
// document.addEventListener('DOMContentLoaded', loadLastSyncTime);
</script>