1
0

base.html 36 KB

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