base.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <script>
  5. // Immediately set dark mode if needed, before page loads
  6. const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
  7. const savedTheme = localStorage.getItem('theme');
  8. if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
  9. document.documentElement.classList.add('dark');
  10. }
  11. </script>
  12. <meta charset="utf-8" />
  13. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  14. <link crossorigin="" href="https://fonts.gstatic.com/" rel="preconnect" />
  15. <link
  16. as="style"
  17. href="https://fonts.googleapis.com/css2?display=swap&amp;family=Noto+Sans%3Awght%40400%3B500%3B700%3B900&amp;family=Plus+Jakarta+Sans%3Awght%40400%3B500%3B700%3B800"
  18. onload="this.rel='stylesheet'"
  19. rel="stylesheet"
  20. />
  21. <!-- Preload Material Icons fonts for faster loading -->
  22. <link rel="preload" href="/static/fonts/material-icons/MaterialIcons-Regular.woff2" as="font" type="font/woff2" crossorigin>
  23. <link rel="preload" href="/static/fonts/material-icons/MaterialIconsOutlined-Regular.woff2" as="font" type="font/woff2" crossorigin>
  24. <title>{% block title %}{{ app_name or 'Dune Weaver' }}{% endblock %}</title>
  25. <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
  26. <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
  27. <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
  28. <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
  29. <link rel="manifest" href="/static/site.webmanifest?v=2">
  30. <link rel="stylesheet" href="/static/css/tailwind.css">
  31. <link rel="stylesheet" href="/static/css/material-icons.css">
  32. <style>
  33. /* Mobile navigation styles */
  34. @media (max-width: 640px) {
  35. nav.flex {
  36. display: grid;
  37. grid-template-columns: repeat(5, 1fr);
  38. gap: 0;
  39. }
  40. nav.flex a {
  41. display: flex;
  42. flex-direction: column;
  43. align-items: center;
  44. justify-content: center;
  45. text-align: center;
  46. padding: 0.75rem 0;
  47. }
  48. nav.flex a .material-icons {
  49. margin-bottom: 0.25rem;
  50. }
  51. }
  52. /* Dark mode styles */
  53. .dark {
  54. color-scheme: dark;
  55. }
  56. .dark body {
  57. background-color: #1a1a1a;
  58. color: #e5e5e5;
  59. }
  60. .dark header {
  61. background-color: #262626;
  62. border-color: #404040;
  63. }
  64. .dark footer {
  65. background-color: #262626;
  66. border-color: #404040;
  67. }
  68. .dark .inactive-tab {
  69. color: #9ca3af;
  70. }
  71. .dark .inactive-tab:hover {
  72. color: #d1d5db;
  73. }
  74. .dark #player-status-bar-container {
  75. background-color: #262626;
  76. color: #e5e5e5;
  77. }
  78. .dark .bg-gray-100 {
  79. background-color: #262626;
  80. }
  81. .dark .bg-gray-200 {
  82. background-color: #404040;
  83. }
  84. .dark .bg-gray-300 {
  85. background-color: #525252;
  86. }
  87. .dark .text-gray-500 {
  88. color: #9ca3af;
  89. }
  90. .dark .text-gray-700 {
  91. color: #d1d5db;
  92. }
  93. .dark .text-gray-800 {
  94. color: #e5e5e5;
  95. }
  96. .dark .border-gray-200 {
  97. border-color: #404040;
  98. }
  99. .dark .hover\:bg-gray-200:hover {
  100. background-color: #404040;
  101. }
  102. .dark .hover\:bg-gray-300:hover {
  103. background-color: #525252;
  104. }
  105. .dark .hover\:border-gray-300:hover {
  106. border-color: #525252;
  107. }
  108. .dark .hover\:bg-gray-50:hover {
  109. background-color: #262626;
  110. }
  111. .dark .bg-white {
  112. background-color: #262626;
  113. }
  114. .dark #shutdown-button:hover {
  115. background-color: #404040;
  116. }
  117. .dark #theme-toggle:hover {
  118. background-color: #404040;
  119. }
  120. .dark .bg-gray-50 {
  121. background-color: #1a1a1a;
  122. }
  123. .dark .text-gray-900 {
  124. color: #e5e5e5;
  125. }
  126. .dark .text-gray-400 {
  127. color: #9ca3af;
  128. }
  129. .dark .border-gray-300 {
  130. border-color: #404040;
  131. }
  132. .dark .focus\:ring-offset-2 {
  133. --tw-ring-offset-color: #262626;
  134. }
  135. .dark .shadow-sm {
  136. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  137. }
  138. .dark .shadow-lg {
  139. box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  140. }
  141. .dark .shadow-xl {
  142. box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  143. }
  144. /* Existing styles */
  145. .active-tab {
  146. color: #0c7ff2;
  147. border-color: #0c7ff2;
  148. }
  149. .active-tab .material-icons {
  150. color: #0c7ff2;
  151. }
  152. .inactive-tab {
  153. color: #6b7280;
  154. border-color: transparent;
  155. }
  156. .inactive-tab:hover {
  157. color: #374151;
  158. }
  159. #status-message {
  160. transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
  161. }
  162. /* Switch toggle styles */
  163. .switch {
  164. position: relative;
  165. display: inline-block;
  166. width: 40px;
  167. height: 20px;
  168. }
  169. .switch input {
  170. opacity: 0;
  171. width: 0;
  172. height: 0;
  173. }
  174. .slider {
  175. position: absolute;
  176. cursor: pointer;
  177. top: 0;
  178. left: 0;
  179. right: 0;
  180. bottom: 0;
  181. background-color: #ccc;
  182. transition: .4s;
  183. border-radius: 20px;
  184. }
  185. .slider:before {
  186. position: absolute;
  187. content: "";
  188. height: 16px;
  189. width: 16px;
  190. left: 2px;
  191. bottom: 2px;
  192. background-color: white;
  193. transition: .4s;
  194. border-radius: 50%;
  195. }
  196. input:checked + .slider {
  197. background-color: #0c7ff2;
  198. }
  199. input:checked + .slider:before {
  200. transform: translateX(20px);
  201. }
  202. /* Shadow for top of status bar */
  203. .shadow-lg-top {
  204. box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 -2px 4px -2px rgb(0 0 0 / 0.1);
  205. }
  206. /* Marquee animation for pattern name on small screens */
  207. @keyframes marquee {
  208. 0% { transform: translateX(0%); }
  209. 50% { transform: translateX(-50%); }
  210. }
  211. .pattern-marquee {
  212. display: inline-block;
  213. min-width: 100%;
  214. animation: marquee 8s linear infinite;
  215. }
  216. @media (min-width: 640px) { /* sm: and up, disable marquee */
  217. .pattern-marquee {
  218. animation: none !important;
  219. transform: none !important;
  220. }
  221. }
  222. {% block additional_styles %}{% endblock %}
  223. </style>
  224. {% block additional_head %}{% endblock %}
  225. </head>
  226. <body
  227. class="bg-gray-50"
  228. style="font-family: 'Plus Jakarta Sans', 'Noto Sans', sans-serif"
  229. >
  230. <div
  231. class="mt-2 w-full text-center px-4 z-50 pointer-events-none absolute"
  232. id="status-message-container"
  233. >
  234. <p
  235. 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"
  236. id="status-message"
  237. ></p>
  238. </div>
  239. <div
  240. class="relative flex size-full min-h-screen flex-col group/design-root overflow-x-hidden"
  241. >
  242. <div class="layout-container flex min-h-full grow flex-col">
  243. <header
  244. 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"
  245. >
  246. <div class="flex items-center gap-3 text-gray-800">
  247. <a href="/" class="flex items-center gap-3 text-gray-800 hover:opacity-80 transition-opacity">
  248. <div class="text-blue-600 w-9 h-9 rounded-full shadow">
  249. <img src="/static/apple-touch-icon.png" alt="Dune Weaver Logo"/>
  250. </div>
  251. <h1
  252. class="text-gray-800 text-xl font-bold leading-tight tracking-tight flex items-center gap-2"
  253. >
  254. {{ app_name or 'Dune Weaver' }}
  255. <span
  256. id="connectionStatusDot"
  257. class="inline-block size-2 rounded-full bg-red-500 ml-2 align-middle"
  258. ></span>
  259. </h1>
  260. </a>
  261. </div>
  262. <div class="flex items-center gap-2">
  263. <!-- Update Available Indicator -->
  264. <button
  265. id="update-indicator"
  266. 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"
  267. aria-label="Update available"
  268. title="Software update available - Click to view"
  269. >
  270. <span class="material-icons text-green-600 dark:text-green-400 animate-pulse">system_update</span>
  271. </button>
  272. <button
  273. id="theme-toggle"
  274. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
  275. aria-label="Toggle dark mode"
  276. >
  277. <span class="material-icons" id="theme-toggle-icon">dark_mode</span>
  278. </button>
  279. <button
  280. id="shutdown-button"
  281. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-red-500"
  282. aria-label="Shutdown system"
  283. title="Shutdown System (Raspberry Pi only)"
  284. >
  285. <span class="material-icons text-red-600">power_settings_new</span>
  286. </button>
  287. </div>
  288. </header>
  289. <main class="flex flex-1 justify-center px-4 sm:px-6 lg:px-8 pt-16 sm:pt-20">
  290. {% block content %}{% endblock %}
  291. </main>
  292. <!-- Floating Preview Button -->
  293. <button
  294. id="toggle-preview-modal-btn"
  295. 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"
  296. title="Toggle Pattern Preview"
  297. >
  298. <span class="material-icons text-xl">preview</span>
  299. </button>
  300. <footer
  301. class="fixed bottom-0 left-0 right-0 z-10 bg-white border-t border-gray-200 shadow-t-sm"
  302. >
  303. <nav class="mx-auto flex max-w-5xl justify-around">
  304. <a
  305. 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"
  306. href="/"
  307. >
  308. <span class="material-icons">search</span> Browse
  309. </a>
  310. <a
  311. 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"
  312. href="/playlists"
  313. >
  314. <span class="material-icons">list_alt</span> Playlists
  315. </a>
  316. <a
  317. 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"
  318. href="/table_control"
  319. >
  320. <span class="material-icons">table_chart</span> Table Control
  321. </a>
  322. <a
  323. 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"
  324. href="/led"
  325. >
  326. <span class="material-icons">lightbulb</span> <span id="led-nav-label">LED</span>
  327. </a>
  328. <a
  329. 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"
  330. href="/settings"
  331. >
  332. <span class="material-icons">settings</span> Settings
  333. </a>
  334. </nav>
  335. </footer>
  336. </div>
  337. </div>
  338. {% block scripts %}{% endblock %}
  339. <script src="/static/js/base.js"></script>
  340. <!-- Cache Progress Modal -->
  341. <div id="cacheProgressModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  342. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
  343. <div class="p-6">
  344. <div class="text-center">
  345. <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Initializing Pattern Cache</h2>
  346. <p class="text-gray-600 dark:text-gray-400 mb-4">Preparing your pattern previews...</p>
  347. <div class="mb-4">
  348. <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
  349. <div id="cacheProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
  350. </div>
  351. <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
  352. <span id="cacheProgressText">Starting...</span>
  353. <span id="cacheProgressPercentage">0%</span>
  354. </div>
  355. </div>
  356. <div class="text-sm text-gray-500 dark:text-gray-400">
  357. <p id="cacheCurrentStage">Preparing...</p>
  358. <p id="cacheCurrentFile" class="mt-1 truncate"></p>
  359. </div>
  360. </div>
  361. </div>
  362. </div>
  363. </div>
  364. <!-- Player Preview Modal -->
  365. <div id="playerPreviewModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-40 hidden p-4">
  366. <div class="bg-white rounded-lg shadow-xl w-full max-w-5xl max-h-[95vh] flex flex-col">
  367. <div class="flex items-center justify-between p-4 border-b border-gray-200 flex-shrink-0">
  368. <h2 id="playerPreviewTitle" class="text-xl font-semibold text-gray-800">Pattern Preview</h2>
  369. <button id="closePlayerPreview" class="text-gray-400 hover:text-gray-600 transition-colors">
  370. <span class="material-icons text-2xl">close</span>
  371. </button>
  372. </div>
  373. <!-- Canvas Area -->
  374. <div class="flex-1 p-4 flex justify-center items-center overflow-hidden">
  375. <div class="relative flex items-center justify-center w-full h-full">
  376. <div class="relative max-w-[min(800px,90vw)] max-h-[min(600px,80vh)] aspect-square">
  377. <canvas id="playerPreviewCanvas" width="800" height="800" class="w-full h-full rounded-full border border-gray-300 dark:invert"></canvas>
  378. </div>
  379. </div>
  380. </div>
  381. <!-- Pattern Info and Controls -->
  382. <div class="flex-shrink-0 p-4 border-b border-gray-200 flex items-center gap-4 flex-wrap">
  383. <!-- Pattern Preview Image -->
  384. <div class="flex-shrink-0">
  385. <img id="modal-pattern-preview-img"
  386. class="w-[126px] h-[126px] rounded-full border border-gray-300 object-cover dark:invert" src="">
  387. </div>
  388. <div class="flex-grow w-auto">
  389. <div class="flex items-center justify-between mb-2">
  390. <div class="min-w-0 max-w-[50%]">
  391. <div class="overflow-hidden relative">
  392. <p class="text-lg font-semibold whitespace-nowrap" id="modal-pattern-name">
  393. No pattern playing
  394. </p>
  395. </div>
  396. <p class="text-base text-gray-500" id="modal-eta">
  397. ETA: --:--
  398. </p>
  399. </div>
  400. <div class="flex items-center gap-2 flex-shrink-0">
  401. <button
  402. aria-label="Next"
  403. 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"
  404. id="modal-skip-button"
  405. >
  406. <span class="material-icons text-gray-700">skip_next</span>
  407. </button>
  408. <button
  409. aria-label="Pause"
  410. 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"
  411. id="modal-pause-button"
  412. >
  413. <span class="material-icons text-gray-700">pause</span>
  414. </button>
  415. <button
  416. aria-label="Stop"
  417. 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"
  418. id="modal-stop-button"
  419. >
  420. <span class="material-icons text-gray-700">stop</span>
  421. </button>
  422. </div>
  423. </div>
  424. <div class="w-full bg-gray-300 rounded-full h-2.5 mb-2">
  425. <div
  426. class="bg-blue-600 h-2.5 rounded-full"
  427. id="modal-progress-bar"
  428. style="width: 0%"
  429. ></div>
  430. </div>
  431. <div class="flex items-center justify-between">
  432. <div class="text-base text-gray-500">
  433. Next:
  434. <span class="text-gray-700 font-medium" id="modal-next-pattern">None</span>
  435. </div>
  436. <div class="flex items-center gap-3 text-sm">
  437. <span class="text-gray-500">Speed:</span>
  438. <div class="flex items-center gap-2">
  439. <div class="relative min-w-[4ch] text-center cursor-pointer inline-flex items-center" id="modal-speed-container">
  440. <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>
  441. <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" />
  442. </div>
  443. </div>
  444. </div>
  445. </div>
  446. </div>
  447. </div>
  448. </div>
  449. </div>
  450. <script>
  451. // Function to show status message
  452. function showStatusMessage(message, type = "success") {
  453. const statusContainer = document.getElementById(
  454. "status-message-container"
  455. );
  456. const statusMessage = document.getElementById("status-message");
  457. if (!statusContainer || !statusMessage) return;
  458. // Set message and color based on type
  459. statusMessage.textContent = message;
  460. 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 ${
  461. type === "success"
  462. ? "bg-green-50 text-green-700 border border-green-200"
  463. : type === "error"
  464. ? "bg-red-50 text-red-700 border border-red-200"
  465. : type === "warning"
  466. ? "bg-yellow-50 text-yellow-700 border border-yellow-200"
  467. : "bg-blue-50 text-blue-700 border border-blue-200"
  468. }`;
  469. // Show message with animation
  470. requestAnimationFrame(() => {
  471. statusMessage.classList.remove("opacity-0", "-translate-y-2");
  472. statusMessage.classList.add("opacity-100", "translate-y-0");
  473. });
  474. // Hide message after 5 seconds
  475. setTimeout(() => {
  476. statusMessage.classList.remove("opacity-100", "translate-y-0");
  477. statusMessage.classList.add("opacity-0", "-translate-y-2");
  478. }, 5000);
  479. }
  480. // Initial connection status check
  481. async function checkInitialConnectionStatus() {
  482. try {
  483. const response = await fetch("/serial_status");
  484. if (response.ok) {
  485. const data = await response.json();
  486. const statusDot = document.getElementById("connectionStatusDot");
  487. if (statusDot) {
  488. statusDot.className = `inline-block size-2 rounded-full ml-2 align-middle ${
  489. data.connected ? "bg-green-500" : "bg-red-500"
  490. }`;
  491. }
  492. }
  493. } catch (error) {
  494. console.error("Error checking initial connection status:", error);
  495. }
  496. }
  497. // Check initial status on page load
  498. document.addEventListener("DOMContentLoaded", checkInitialConnectionStatus);
  499. // Player bar toggle logic will be handled by base.js
  500. </script>
  501. <script>
  502. // Cache progress modal functionality
  503. let cacheProgressSocket = null;
  504. let cacheProgressCheckInterval = null;
  505. function initCacheProgressModal() {
  506. const modal = document.getElementById('cacheProgressModal');
  507. const progressBar = document.getElementById('cacheProgressBar');
  508. const progressText = document.getElementById('cacheProgressText');
  509. const progressPercentage = document.getElementById('cacheProgressPercentage');
  510. const currentStage = document.getElementById('cacheCurrentStage');
  511. const currentFile = document.getElementById('cacheCurrentFile');
  512. // Check if cache generation is needed on page load
  513. fetch('/cache-progress')
  514. .then(response => response.json())
  515. .then(data => {
  516. if (data.is_running) {
  517. showCacheProgressModal();
  518. }
  519. })
  520. .catch(error => {
  521. console.error('Error checking initial cache progress:', error);
  522. });
  523. function showCacheProgressModal() {
  524. modal.classList.remove('hidden');
  525. // Connect to WebSocket for real-time updates
  526. const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
  527. const wsUrl = `${protocol}//${window.location.host}/ws/cache-progress`;
  528. cacheProgressSocket = new WebSocket(wsUrl);
  529. cacheProgressSocket.onmessage = function(event) {
  530. const data = JSON.parse(event.data);
  531. if (data.type === 'cache_progress') {
  532. updateCacheProgress(data.data);
  533. }
  534. };
  535. cacheProgressSocket.onclose = function() {
  536. // Fallback to polling if WebSocket fails
  537. startProgressPolling();
  538. };
  539. cacheProgressSocket.onerror = function() {
  540. // Fallback to polling if WebSocket fails
  541. startProgressPolling();
  542. };
  543. }
  544. function startProgressPolling() {
  545. if (cacheProgressCheckInterval) {
  546. clearInterval(cacheProgressCheckInterval);
  547. }
  548. cacheProgressCheckInterval = setInterval(() => {
  549. fetch('/cache-progress')
  550. .then(response => response.json())
  551. .then(data => updateCacheProgress(data))
  552. .catch(error => console.error('Error fetching cache progress:', error));
  553. }, 1000);
  554. }
  555. function updateCacheProgress(data) {
  556. if (!data.is_running && data.stage === 'complete') {
  557. console.log('Initial cache generation completed');
  558. hideCacheProgressModal();
  559. // Trigger cache all prompt after initial cache generation completes
  560. if (typeof onInitialCacheComplete === 'function') {
  561. console.log('Calling onInitialCacheComplete()');
  562. onInitialCacheComplete();
  563. } else {
  564. console.log('onInitialCacheComplete function not found');
  565. }
  566. return;
  567. }
  568. if (!data.is_running && data.stage === 'error') {
  569. progressText.textContent = 'Error occurred';
  570. currentStage.textContent = data.error || 'Unknown error';
  571. currentFile.textContent = '';
  572. return;
  573. }
  574. if (!data.is_running) {
  575. hideCacheProgressModal();
  576. return;
  577. }
  578. // Calculate progress percentage
  579. const percentage = data.total_files > 0 ? Math.round((data.processed_files / data.total_files) * 100) : 0;
  580. // Update progress bar
  581. progressBar.style.width = `${percentage}%`;
  582. progressPercentage.textContent = `${percentage}%`;
  583. // Update text based on stage
  584. let stageText = '';
  585. let progressTextContent = '';
  586. switch (data.stage) {
  587. case 'starting':
  588. stageText = 'Initializing...';
  589. progressTextContent = 'Getting ready...';
  590. break;
  591. case 'metadata':
  592. stageText = 'Processing pattern metadata';
  593. progressTextContent = `${data.processed_files} of ${data.total_files} patterns`;
  594. break;
  595. case 'images':
  596. stageText = 'Generating pattern previews';
  597. progressTextContent = `${data.processed_files} of ${data.total_files} previews`;
  598. break;
  599. default:
  600. stageText = 'Processing...';
  601. progressTextContent = `${data.processed_files} of ${data.total_files} files`;
  602. }
  603. currentStage.textContent = stageText;
  604. progressText.textContent = progressTextContent;
  605. // Update current file
  606. if (data.current_file) {
  607. currentFile.textContent = `Current: ${data.current_file}`;
  608. } else {
  609. currentFile.textContent = '';
  610. }
  611. }
  612. function hideCacheProgressModal() {
  613. modal.classList.add('hidden');
  614. if (cacheProgressSocket) {
  615. cacheProgressSocket.close();
  616. cacheProgressSocket = null;
  617. }
  618. if (cacheProgressCheckInterval) {
  619. clearInterval(cacheProgressCheckInterval);
  620. cacheProgressCheckInterval = null;
  621. }
  622. }
  623. // Expose functions globally for potential external use
  624. window.showCacheProgressModal = showCacheProgressModal;
  625. window.hideCacheProgressModal = hideCacheProgressModal;
  626. }
  627. // Initialize when DOM is loaded
  628. document.addEventListener('DOMContentLoaded', initCacheProgressModal);
  629. </script>
  630. <script>
  631. // Theme switching functionality
  632. document.addEventListener('DOMContentLoaded', function() {
  633. const themeToggle = document.getElementById('theme-toggle');
  634. const themeToggleIcon = document.getElementById('theme-toggle-icon');
  635. // Update icon based on current theme
  636. function updateThemeIcon() {
  637. const isDark = document.documentElement.classList.contains('dark');
  638. themeToggleIcon.textContent = isDark ? 'light_mode' : 'dark_mode';
  639. }
  640. // Initial icon update
  641. updateThemeIcon();
  642. // Theme toggle click handler
  643. themeToggle.addEventListener('click', () => {
  644. const isDark = document.documentElement.classList.toggle('dark');
  645. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  646. updateThemeIcon();
  647. });
  648. });
  649. // Shutdown button functionality
  650. document.addEventListener('DOMContentLoaded', function() {
  651. const shutdownButton = document.getElementById('shutdown-button');
  652. // Shutdown button click handler
  653. shutdownButton.addEventListener('click', async () => {
  654. 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.');
  655. if (!confirmed) return;
  656. try {
  657. showStatusMessage('Initiating shutdown...', 'warning');
  658. const response = await fetch('/api/system/shutdown', { method: 'POST' });
  659. const data = await response.json();
  660. if (data.success) {
  661. showStatusMessage('System is shutting down...', 'success');
  662. } else {
  663. showStatusMessage('Shutdown failed: ' + data.message, 'error');
  664. }
  665. } catch (error) {
  666. showStatusMessage('Failed to shutdown: ' + error.message, 'error');
  667. }
  668. });
  669. });
  670. // Update indicator functionality
  671. document.addEventListener('DOMContentLoaded', async function() {
  672. const updateIndicator = document.getElementById('update-indicator');
  673. if (!updateIndicator) return;
  674. // Check for updates
  675. async function checkForUpdates() {
  676. try {
  677. const response = await fetch('/api/version');
  678. const data = await response.json();
  679. // Show indicator if update is available
  680. if (data.update_available) {
  681. updateIndicator.classList.remove('hidden');
  682. } else {
  683. updateIndicator.classList.add('hidden');
  684. }
  685. } catch (error) {
  686. console.error('Failed to check for updates:', error);
  687. }
  688. }
  689. // Initial check
  690. await checkForUpdates();
  691. // Check every hour
  692. setInterval(checkForUpdates, 3600000);
  693. // Click handler - navigate to settings and scroll to update section
  694. updateIndicator.addEventListener('click', () => {
  695. // Navigate to settings page
  696. window.location.href = '/settings#software-version-section';
  697. });
  698. });
  699. </script>
  700. <!-- Cache All Previews Prompt Modal -->
  701. <div id="cacheAllPromptModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  702. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
  703. <div class="p-6">
  704. <div class="text-center">
  705. <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Cache All Pattern Previews?</h2>
  706. <p class="text-gray-600 dark:text-gray-400 mb-4 max-w-md mx-auto">
  707. Would you like to cache all pattern previews for faster browsing? This will download and store preview images in your browser for instant loading.
  708. </p>
  709. <div class="bg-amber-50 dark:bg-amber-900 p-3 rounded-lg mb-4 text-sm">
  710. <p class="text-amber-700 dark:text-amber-300">
  711. <strong>Note:</strong> This cache is browser-specific. You'll need to repeat this process for each browser you use.
  712. </p>
  713. </div>
  714. <!-- Progress section (hidden initially) -->
  715. <div id="cacheAllProgress" class="mb-4 hidden">
  716. <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
  717. <div id="cacheAllProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
  718. </div>
  719. <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
  720. <span id="cacheAllProgressText">Starting...</span>
  721. <span id="cacheAllProgressPercentage">0%</span>
  722. </div>
  723. </div>
  724. <!-- Buttons -->
  725. <div id="cacheAllButtons" class="flex gap-3 justify-center">
  726. <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">
  727. Skip for now
  728. </button>
  729. <button id="startCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
  730. Cache All Previews
  731. </button>
  732. </div>
  733. <!-- Completion message (hidden initially) -->
  734. <div id="cacheAllComplete" class="hidden">
  735. <p class="text-green-600 dark:text-green-400 mb-4">✓ All previews cached successfully!</p>
  736. <button id="closeCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
  737. Done
  738. </button>
  739. </div>
  740. </div>
  741. </div>
  742. </div>
  743. </div>
  744. </body>
  745. </html>