| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <script>
- // Immediately set dark mode if needed, before page loads
- const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
- const savedTheme = localStorage.getItem('theme');
- if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
- document.documentElement.classList.add('dark');
- }
- </script>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <link crossorigin="" href="https://fonts.gstatic.com/" rel="preconnect" />
- <link
- as="style"
- href="https://fonts.googleapis.com/css2?display=swap&family=Noto+Sans%3Awght%40400%3B500%3B700%3B900&family=Plus+Jakarta+Sans%3Awght%40400%3B500%3B700%3B800"
- onload="this.rel='stylesheet'"
- rel="stylesheet"
- />
- <!-- Preload Material Icons fonts for faster loading -->
- <link rel="preload" href="/static/fonts/material-icons/MaterialIcons-Regular.woff2" as="font" type="font/woff2" crossorigin>
- <link rel="preload" href="/static/fonts/material-icons/MaterialIconsOutlined-Regular.woff2" as="font" type="font/woff2" crossorigin>
- <title>{% block title %}{{ app_name or 'Dune Weaver' }}{% endblock %}</title>
- <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
- <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
- <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
- <link rel="manifest" href="/static/site.webmanifest?v=2">
- <link rel="stylesheet" href="/static/css/tailwind.css">
- <link rel="stylesheet" href="/static/css/material-icons.css">
- <style>
- /* Mobile navigation styles */
- @media (max-width: 640px) {
- nav.flex {
- display: grid;
- grid-template-columns: repeat(5, 1fr);
- gap: 0;
- }
- nav.flex a {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- text-align: center;
- padding: 0.75rem 0;
- }
- nav.flex a .material-icons {
- margin-bottom: 0.25rem;
- }
- }
- /* Dark mode styles */
- .dark {
- color-scheme: dark;
- }
- .dark body {
- background-color: #1a1a1a;
- color: #e5e5e5;
- }
- .dark header {
- background-color: #262626;
- border-color: #404040;
- }
- .dark footer {
- background-color: #262626;
- border-color: #404040;
- }
- .dark .inactive-tab {
- color: #9ca3af;
- }
- .dark .inactive-tab:hover {
- color: #d1d5db;
- }
- .dark #player-status-bar-container {
- background-color: #262626;
- color: #e5e5e5;
- }
- .dark .bg-gray-100 {
- background-color: #262626;
- }
- .dark .bg-gray-200 {
- background-color: #404040;
- }
- .dark .bg-gray-300 {
- background-color: #525252;
- }
- .dark .text-gray-500 {
- color: #9ca3af;
- }
- .dark .text-gray-700 {
- color: #d1d5db;
- }
- .dark .text-gray-800 {
- color: #e5e5e5;
- }
- .dark .border-gray-200 {
- border-color: #404040;
- }
- .dark .hover\:bg-gray-200:hover {
- background-color: #404040;
- }
- .dark .hover\:bg-gray-300:hover {
- background-color: #525252;
- }
- .dark .hover\:border-gray-300:hover {
- border-color: #525252;
- }
- .dark .hover\:bg-gray-50:hover {
- background-color: #262626;
- }
- .dark .bg-white {
- background-color: #262626;
- }
- .dark #shutdown-button:hover {
- background-color: #404040;
- }
- .dark #theme-toggle:hover {
- background-color: #404040;
- }
- .dark .bg-gray-50 {
- background-color: #1a1a1a;
- }
- .dark .text-gray-900 {
- color: #e5e5e5;
- }
- .dark .text-gray-400 {
- color: #9ca3af;
- }
- .dark .border-gray-300 {
- border-color: #404040;
- }
- .dark .focus\:ring-offset-2 {
- --tw-ring-offset-color: #262626;
- }
- .dark .shadow-sm {
- box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
- }
- .dark .shadow-lg {
- box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
- }
- .dark .shadow-xl {
- box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
- }
- /* Existing styles */
- .active-tab {
- color: #0c7ff2;
- border-color: #0c7ff2;
- }
- .active-tab .material-icons {
- color: #0c7ff2;
- }
- .inactive-tab {
- color: #6b7280;
- border-color: transparent;
- }
- .inactive-tab:hover {
- color: #374151;
- }
- #status-message {
- transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
- }
- /* Switch toggle styles */
- .switch {
- position: relative;
- display: inline-block;
- width: 40px;
- height: 20px;
- }
- .switch input {
- opacity: 0;
- width: 0;
- height: 0;
- }
- .slider {
- position: absolute;
- cursor: pointer;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: #ccc;
- transition: .4s;
- border-radius: 20px;
- }
- .slider:before {
- position: absolute;
- content: "";
- height: 16px;
- width: 16px;
- left: 2px;
- bottom: 2px;
- background-color: white;
- transition: .4s;
- border-radius: 50%;
- }
- input:checked + .slider {
- background-color: #0c7ff2;
- }
- input:checked + .slider:before {
- transform: translateX(20px);
- }
- /* Shadow for top of status bar */
- .shadow-lg-top {
- box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 -2px 4px -2px rgb(0 0 0 / 0.1);
- }
- /* Marquee animation for pattern name on small screens */
- @keyframes marquee {
- 0% { transform: translateX(0%); }
- 50% { transform: translateX(-50%); }
- }
- .pattern-marquee {
- display: inline-block;
- min-width: 100%;
- animation: marquee 8s linear infinite;
- }
- @media (min-width: 640px) { /* sm: and up, disable marquee */
- .pattern-marquee {
- animation: none !important;
- transform: none !important;
- }
- }
- {% block additional_styles %}{% endblock %}
- </style>
- {% block additional_head %}{% endblock %}
- </head>
- <body
- class="bg-gray-50"
- style="font-family: 'Plus Jakarta Sans', 'Noto Sans', sans-serif"
- >
- <div
- class="mt-2 w-full text-center px-4 z-50 pointer-events-none absolute"
- id="status-message-container"
- >
- <p
- class="text-base font-semibold opacity-0 transform -translate-y-2 transition-all duration-300 ease-in-out px-10 py-2 rounded-lg shadow-lg"
- id="status-message"
- ></p>
- </div>
- <div
- class="relative flex size-full min-h-screen flex-col group/design-root overflow-x-hidden"
- >
- <div class="layout-container flex min-h-full grow flex-col">
- <header
- class="fixed top-0 left-0 right-0 z-10 flex items-center justify-between whitespace-nowrap border-b border-solid border-b-gray-200 bg-white px-4 sm:px-6 md:px-10 py-3 sm:py-4 shadow-sm"
- >
- <div class="flex items-center gap-3 text-gray-800">
- <a href="/" class="flex items-center gap-3 text-gray-800 hover:opacity-80 transition-opacity">
- <div class="text-blue-600 w-9 h-9 rounded-full shadow">
- <img src="/static/apple-touch-icon.png" alt="Dune Weaver Logo"/>
- </div>
- <h1
- class="text-gray-800 text-xl font-bold leading-tight tracking-tight flex items-center gap-2"
- >
- {{ app_name or 'Dune Weaver' }}
- <span
- id="connectionStatusDot"
- class="inline-block size-2 rounded-full bg-red-500 ml-2 align-middle"
- ></span>
- </h1>
- </a>
- </div>
- <div class="flex items-center gap-2">
- <!-- Update Available Indicator -->
- <button
- id="update-indicator"
- class="hidden p-1.5 flex rounded-lg hover:bg-green-100 dark:hover:bg-green-900 focus:outline-none focus:ring-2 focus:ring-green-500"
- aria-label="Update available"
- title="Software update available - Click to view"
- >
- <span class="material-icons text-green-600 dark:text-green-400 animate-pulse">system_update</span>
- </button>
- <button
- id="theme-toggle"
- class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- aria-label="Toggle dark mode"
- >
- <span class="material-icons" id="theme-toggle-icon">dark_mode</span>
- </button>
- <button
- id="shutdown-button"
- class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-red-500"
- aria-label="Shutdown system"
- title="Shutdown System (Raspberry Pi only)"
- >
- <span class="material-icons text-red-600">power_settings_new</span>
- </button>
- </div>
- </header>
- <main class="flex flex-1 justify-center px-4 sm:px-6 lg:px-8 pt-16 sm:pt-20">
- {% block content %}{% endblock %}
- </main>
- <!-- Floating Preview Button -->
- <button
- id="toggle-preview-modal-btn"
- class="fixed bottom-24 right-4 z-30 bg-blue-600 hover:bg-blue-700 text-white rounded-full shadow-lg w-12 h-12 flex items-center justify-center transition-all focus:outline-none focus:ring-2 focus:ring-blue-500"
- title="Toggle Pattern Preview"
- >
- <span class="material-icons text-xl">preview</span>
- </button>
- <footer
- class="fixed bottom-0 left-0 right-0 z-10 bg-white border-t border-gray-200 shadow-t-sm"
- >
- <nav class="mx-auto flex max-w-5xl justify-around">
- <a
- class="{% if request.url.path == '/' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] {% if request.url.path != '/' %}border-transparent{% endif %} py-3 text-xs font-medium sm:text-sm"
- href="/"
- >
- <span class="material-icons">search</span> Browse
- </a>
- <a
- class="{% if request.url.path == '/playlists' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/playlists"
- >
- <span class="material-icons">list_alt</span> Playlists
- </a>
- <a
- class="{% if request.url.path == '/table_control' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/table_control"
- >
- <span class="material-icons">table_chart</span> Table Control
- </a>
- <a
- class="{% if request.url.path == '/led' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/led"
- >
- <span class="material-icons">lightbulb</span> <span id="led-nav-label">LED</span>
- </a>
- <a
- class="{% if request.url.path == '/settings' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/settings"
- >
- <span class="material-icons">settings</span> Settings
- </a>
- </nav>
- </footer>
- </div>
- </div>
- {% block scripts %}{% endblock %}
- <script src="/static/js/base.js"></script>
- <!-- Cache Progress Modal -->
- <div id="cacheProgressModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
- <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
- <div class="p-6">
- <div class="text-center">
- <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Initializing Pattern Cache</h2>
- <p class="text-gray-600 dark:text-gray-400 mb-4">Preparing your pattern previews...</p>
-
- <div class="mb-4">
- <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
- <div id="cacheProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
- </div>
- <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
- <span id="cacheProgressText">Starting...</span>
- <span id="cacheProgressPercentage">0%</span>
- </div>
- </div>
-
- <div class="text-sm text-gray-500 dark:text-gray-400">
- <p id="cacheCurrentStage">Preparing...</p>
- <p id="cacheCurrentFile" class="mt-1 truncate"></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- Player Preview Modal -->
- <div id="playerPreviewModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-40 hidden p-4">
- <div class="bg-white rounded-lg shadow-xl w-full max-w-5xl max-h-[95vh] flex flex-col">
- <div class="flex items-center justify-between p-4 border-b border-gray-200 flex-shrink-0">
- <h2 id="playerPreviewTitle" class="text-xl font-semibold text-gray-800">Pattern Preview</h2>
- <button id="closePlayerPreview" class="text-gray-400 hover:text-gray-600 transition-colors">
- <span class="material-icons text-2xl">close</span>
- </button>
- </div>
- <!-- Canvas Area -->
- <div class="flex-1 p-4 flex justify-center items-center overflow-hidden">
- <div class="relative flex items-center justify-center w-full h-full">
- <div class="relative max-w-[min(800px,90vw)] max-h-[min(600px,80vh)] aspect-square">
- <canvas id="playerPreviewCanvas" width="800" height="800" class="w-full h-full rounded-full border border-gray-300 dark:invert"></canvas>
- </div>
- </div>
- </div>
- <!-- Pattern Info and Controls -->
- <div class="flex-shrink-0 p-4 border-b border-gray-200 flex items-center gap-4 flex-wrap">
- <!-- Pattern Preview Image -->
- <div class="flex-shrink-0">
- <img id="modal-pattern-preview-img"
- class="w-[126px] h-[126px] rounded-full border border-gray-300 object-cover dark:invert" src="">
- </div>
- <div class="flex-grow w-auto">
- <div class="flex items-center justify-between mb-2">
- <div class="min-w-0 max-w-[50%]">
- <div class="overflow-hidden relative">
- <p class="text-lg font-semibold whitespace-nowrap" id="modal-pattern-name">
- No pattern playing
- </p>
- </div>
- <p class="text-base text-gray-500" id="modal-eta">
- ETA: --:--
- </p>
- </div>
- <div class="flex items-center gap-2 flex-shrink-0">
- <button
- aria-label="Next"
- class="w-12 aspect-square rounded-full flex items-center justify-center hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- id="modal-skip-button"
- >
- <span class="material-icons text-gray-700">skip_next</span>
- </button>
- <button
- aria-label="Pause"
- class="w-12 aspect-square rounded-full flex items-center justify-center hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- id="modal-pause-button"
- >
- <span class="material-icons text-gray-700">pause</span>
- </button>
- <button
- aria-label="Stop"
- class="w-12 aspect-square rounded-full flex items-center justify-center hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- id="modal-stop-button"
- >
- <span class="material-icons text-gray-700">stop</span>
- </button>
- </div>
- </div>
- <div class="w-full bg-gray-300 rounded-full h-2.5 mb-2">
- <div
- class="bg-blue-600 h-2.5 rounded-full"
- id="modal-progress-bar"
- style="width: 0%"
- ></div>
- </div>
- <div class="flex items-center justify-between">
- <div class="text-base text-gray-500">
- Next:
- <span class="text-gray-700 font-medium" id="modal-next-pattern">None</span>
- </div>
- <div class="flex items-center gap-3 text-sm">
- <span class="text-gray-500">Speed:</span>
- <div class="flex items-center gap-2">
- <div class="relative min-w-[4ch] text-center cursor-pointer inline-flex items-center" id="modal-speed-container">
- <span class="inline-block px-2 py-1 text-gray-700 font-medium border border-transparent rounded hover:border-gray-300 hover:bg-gray-50 transition-colors" id="modal-speed-display" title="Click to edit speed">--</span>
- <input type="number" min="1" max="5000" step="1" class="w-16 sm:w-20 px-2 py-1 text-sm border border-blue-500 rounded focus:border-blue-500 focus:ring-1 focus:ring-blue-500 text-center hidden" id="modal-speed-input" />
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- // Function to show status message
- function showStatusMessage(message, type = "success") {
- const statusContainer = document.getElementById(
- "status-message-container"
- );
- const statusMessage = document.getElementById("status-message");
- if (!statusContainer || !statusMessage) return;
- // Set message and color based on type
- statusMessage.textContent = message;
- statusMessage.className = `text-base font-semibold opacity-0 transform -translate-y-2 transition-all duration-300 ease-in-out px-4 py-2 rounded-lg shadow-lg ${
- type === "success"
- ? "bg-green-50 text-green-700 border border-green-200"
- : type === "error"
- ? "bg-red-50 text-red-700 border border-red-200"
- : type === "warning"
- ? "bg-yellow-50 text-yellow-700 border border-yellow-200"
- : "bg-blue-50 text-blue-700 border border-blue-200"
- }`;
- // Show message with animation
- requestAnimationFrame(() => {
- statusMessage.classList.remove("opacity-0", "-translate-y-2");
- statusMessage.classList.add("opacity-100", "translate-y-0");
- });
- // Hide message after 5 seconds
- setTimeout(() => {
- statusMessage.classList.remove("opacity-100", "translate-y-0");
- statusMessage.classList.add("opacity-0", "-translate-y-2");
- }, 5000);
- }
- // Initial connection status check
- async function checkInitialConnectionStatus() {
- try {
- const response = await fetch("/serial_status");
- if (response.ok) {
- const data = await response.json();
- const statusDot = document.getElementById("connectionStatusDot");
- if (statusDot) {
- statusDot.className = `inline-block size-2 rounded-full ml-2 align-middle ${
- data.connected ? "bg-green-500" : "bg-red-500"
- }`;
- }
- }
- } catch (error) {
- console.error("Error checking initial connection status:", error);
- }
- }
- // Check initial status on page load
- document.addEventListener("DOMContentLoaded", checkInitialConnectionStatus);
- // Player bar toggle logic will be handled by base.js
- </script>
-
- <script>
- // Cache progress modal functionality
- let cacheProgressSocket = null;
- let cacheProgressCheckInterval = null;
-
- function initCacheProgressModal() {
- const modal = document.getElementById('cacheProgressModal');
- const progressBar = document.getElementById('cacheProgressBar');
- const progressText = document.getElementById('cacheProgressText');
- const progressPercentage = document.getElementById('cacheProgressPercentage');
- const currentStage = document.getElementById('cacheCurrentStage');
- const currentFile = document.getElementById('cacheCurrentFile');
-
- // Check if cache generation is needed on page load
- fetch('/cache-progress')
- .then(response => response.json())
- .then(data => {
- if (data.is_running) {
- showCacheProgressModal();
- }
- })
- .catch(error => {
- console.error('Error checking initial cache progress:', error);
- });
-
- function showCacheProgressModal() {
- modal.classList.remove('hidden');
-
- // Connect to WebSocket for real-time updates
- const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
- const wsUrl = `${protocol}//${window.location.host}/ws/cache-progress`;
-
- cacheProgressSocket = new WebSocket(wsUrl);
-
- cacheProgressSocket.onmessage = function(event) {
- const data = JSON.parse(event.data);
- if (data.type === 'cache_progress') {
- updateCacheProgress(data.data);
- }
- };
-
- cacheProgressSocket.onclose = function() {
- // Fallback to polling if WebSocket fails
- startProgressPolling();
- };
-
- cacheProgressSocket.onerror = function() {
- // Fallback to polling if WebSocket fails
- startProgressPolling();
- };
- }
-
- function startProgressPolling() {
- if (cacheProgressCheckInterval) {
- clearInterval(cacheProgressCheckInterval);
- }
-
- cacheProgressCheckInterval = setInterval(() => {
- fetch('/cache-progress')
- .then(response => response.json())
- .then(data => updateCacheProgress(data))
- .catch(error => console.error('Error fetching cache progress:', error));
- }, 1000);
- }
-
- function updateCacheProgress(data) {
- if (!data.is_running && data.stage === 'complete') {
- console.log('Initial cache generation completed');
- hideCacheProgressModal();
- // Trigger cache all prompt after initial cache generation completes
- if (typeof onInitialCacheComplete === 'function') {
- console.log('Calling onInitialCacheComplete()');
- onInitialCacheComplete();
- } else {
- console.log('onInitialCacheComplete function not found');
- }
- return;
- }
-
- if (!data.is_running && data.stage === 'error') {
- progressText.textContent = 'Error occurred';
- currentStage.textContent = data.error || 'Unknown error';
- currentFile.textContent = '';
- return;
- }
-
- if (!data.is_running) {
- hideCacheProgressModal();
- return;
- }
-
- // Calculate progress percentage
- const percentage = data.total_files > 0 ? Math.round((data.processed_files / data.total_files) * 100) : 0;
-
- // Update progress bar
- progressBar.style.width = `${percentage}%`;
- progressPercentage.textContent = `${percentage}%`;
-
- // Update text based on stage
- let stageText = '';
- let progressTextContent = '';
-
- switch (data.stage) {
- case 'starting':
- stageText = 'Initializing...';
- progressTextContent = 'Getting ready...';
- break;
- case 'metadata':
- stageText = 'Processing pattern metadata';
- progressTextContent = `${data.processed_files} of ${data.total_files} patterns`;
- break;
- case 'images':
- stageText = 'Generating pattern previews';
- progressTextContent = `${data.processed_files} of ${data.total_files} previews`;
- break;
- default:
- stageText = 'Processing...';
- progressTextContent = `${data.processed_files} of ${data.total_files} files`;
- }
-
- currentStage.textContent = stageText;
- progressText.textContent = progressTextContent;
-
- // Update current file
- if (data.current_file) {
- currentFile.textContent = `Current: ${data.current_file}`;
- } else {
- currentFile.textContent = '';
- }
- }
-
- function hideCacheProgressModal() {
- modal.classList.add('hidden');
-
- if (cacheProgressSocket) {
- cacheProgressSocket.close();
- cacheProgressSocket = null;
- }
-
- if (cacheProgressCheckInterval) {
- clearInterval(cacheProgressCheckInterval);
- cacheProgressCheckInterval = null;
- }
- }
-
- // Expose functions globally for potential external use
- window.showCacheProgressModal = showCacheProgressModal;
- window.hideCacheProgressModal = hideCacheProgressModal;
- }
-
- // Initialize when DOM is loaded
- document.addEventListener('DOMContentLoaded', initCacheProgressModal);
- </script>
- <script>
- // Theme switching functionality
- document.addEventListener('DOMContentLoaded', function() {
- const themeToggle = document.getElementById('theme-toggle');
- const themeToggleIcon = document.getElementById('theme-toggle-icon');
- // Update icon based on current theme
- function updateThemeIcon() {
- const isDark = document.documentElement.classList.contains('dark');
- themeToggleIcon.textContent = isDark ? 'light_mode' : 'dark_mode';
- }
- // Initial icon update
- updateThemeIcon();
- // Theme toggle click handler
- themeToggle.addEventListener('click', () => {
- const isDark = document.documentElement.classList.toggle('dark');
- localStorage.setItem('theme', isDark ? 'dark' : 'light');
- updateThemeIcon();
- });
- });
- // Shutdown button functionality
- document.addEventListener('DOMContentLoaded', function() {
- const shutdownButton = document.getElementById('shutdown-button');
- // Shutdown button click handler
- shutdownButton.addEventListener('click', async () => {
- const confirmed = confirm('Are you sure you want to shutdown the system?\n\nNote: This only works on Raspberry Pi.\n\nThis will:\n1. Stop Docker containers\n2. Shut down the system\n\nYou will need physical access to restart it.');
- if (!confirmed) return;
- try {
- showStatusMessage('Initiating shutdown...', 'warning');
- const response = await fetch('/api/system/shutdown', { method: 'POST' });
- const data = await response.json();
- if (data.success) {
- showStatusMessage('System is shutting down...', 'success');
- } else {
- showStatusMessage('Shutdown failed: ' + data.message, 'error');
- }
- } catch (error) {
- showStatusMessage('Failed to shutdown: ' + error.message, 'error');
- }
- });
- });
- // Update indicator functionality
- document.addEventListener('DOMContentLoaded', async function() {
- const updateIndicator = document.getElementById('update-indicator');
- if (!updateIndicator) return;
- // Check for updates
- async function checkForUpdates() {
- try {
- const response = await fetch('/api/version');
- const data = await response.json();
- // Show indicator if update is available
- if (data.update_available) {
- updateIndicator.classList.remove('hidden');
- } else {
- updateIndicator.classList.add('hidden');
- }
- } catch (error) {
- console.error('Failed to check for updates:', error);
- }
- }
- // Initial check
- await checkForUpdates();
- // Check every hour
- setInterval(checkForUpdates, 3600000);
- // Click handler - navigate to settings and scroll to update section
- updateIndicator.addEventListener('click', () => {
- // Navigate to settings page
- window.location.href = '/settings#software-version-section';
- });
- });
- </script>
- <!-- Cache All Previews Prompt Modal -->
- <div id="cacheAllPromptModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
- <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
- <div class="p-6">
- <div class="text-center">
- <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Cache All Pattern Previews?</h2>
- <p class="text-gray-600 dark:text-gray-400 mb-4 max-w-md mx-auto">
- Would you like to cache all pattern previews for faster browsing? This will download and store preview images in your browser for instant loading.
- </p>
-
- <div class="bg-amber-50 dark:bg-amber-900 p-3 rounded-lg mb-4 text-sm">
- <p class="text-amber-700 dark:text-amber-300">
- <strong>Note:</strong> This cache is browser-specific. You'll need to repeat this process for each browser you use.
- </p>
- </div>
-
- <!-- Progress section (hidden initially) -->
- <div id="cacheAllProgress" class="mb-4 hidden">
- <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
- <div id="cacheAllProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
- </div>
- <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
- <span id="cacheAllProgressText">Starting...</span>
- <span id="cacheAllProgressPercentage">0%</span>
- </div>
- </div>
-
- <!-- Buttons -->
- <div id="cacheAllButtons" class="flex gap-3 justify-center">
- <button id="skipCacheAllBtn" class="px-4 py-2 text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 transition-colors">
- Skip for now
- </button>
- <button id="startCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
- Cache All Previews
- </button>
- </div>
-
- <!-- Completion message (hidden initially) -->
- <div id="cacheAllComplete" class="hidden">
- <p class="text-green-600 dark:text-green-400 mb-4">✓ All previews cached successfully!</p>
- <button id="closeCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
- Done
- </button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
|