Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 26
Add light/dark mode toggle and fix log readability#243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,6 +5,86 @@ | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>LED Matrix Control Panel - v3</title> | ||
| <!-- Theme initialization (must run before CSS to prevent flash) --> | ||
| <script> | ||
| (function() { | ||
| // Safely read from localStorage (may throw in private browsing / restricted contexts) | ||
| function getStorage(key) { | ||
| try { return localStorage.getItem(key); } catch (e) { return null; } | ||
| } | ||
| function setStorage(key, value) { | ||
| try { localStorage.setItem(key, value); } catch (e) { /* no-op */ } | ||
| } | ||
| // Safely query prefers-color-scheme (matchMedia may be unavailable) | ||
| function prefersDark() { | ||
| try { | ||
| return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
| } catch (e) { return false; } | ||
| } | ||
| var saved = getStorage('theme'); | ||
| var theme = saved || (prefersDark() ? 'dark' : 'light'); | ||
| document.documentElement.setAttribute('data-theme', theme); | ||
| // Theme toggle function | ||
| window.toggleTheme = function() { | ||
| try { | ||
| var current = document.documentElement.getAttribute('data-theme'); | ||
| var next = current === 'dark' ? 'light' : 'dark'; | ||
| document.documentElement.setAttribute('data-theme', next); | ||
| setStorage('theme', next); | ||
| window.updateThemeIcon(next); | ||
| } catch (e) { /* no-op */ } | ||
| }; | ||
| // Update icon visibility and ARIA state based on current theme | ||
| window.updateThemeIcon = function(theme) { | ||
| var darkIcon = document.getElementById('theme-icon-dark'); | ||
| var lightIcon = document.getElementById('theme-icon-light'); | ||
| var btn = document.getElementById('theme-toggle'); | ||
| if (darkIcon && lightIcon) { | ||
| if (theme === 'dark') { | ||
| darkIcon.classList.add('hidden'); | ||
| lightIcon.classList.remove('hidden'); | ||
| } else { | ||
| darkIcon.classList.remove('hidden'); | ||
| lightIcon.classList.add('hidden'); | ||
| } | ||
| } | ||
| if (btn) { | ||
| var isDark = theme === 'dark'; | ||
| btn.setAttribute('aria-pressed', String(isDark)); | ||
| var label = isDark ? 'Switch to light mode' : 'Switch to dark mode'; | ||
| btn.setAttribute('aria-label', label); | ||
| btn.setAttribute('title', label); | ||
| } | ||
| }; | ||
| // Initialize icon state once DOM is ready | ||
| document.addEventListener('DOMContentLoaded', function() { | ||
| window.updateThemeIcon(document.documentElement.getAttribute('data-theme') || 'light'); | ||
| }); | ||
| // Listen for OS theme changes (only when no explicit user preference) | ||
| try { | ||
| var mql = window.matchMedia('(prefers-color-scheme: dark)'); | ||
| var handler = function(e) { | ||
| if (!getStorage('theme')) { | ||
| var t = e.matches ? 'dark' : 'light'; | ||
| document.documentElement.setAttribute('data-theme', t); | ||
| window.updateThemeIcon(t); | ||
| } | ||
| }; | ||
| if (mql.addEventListener) { | ||
| mql.addEventListener('change', handler); | ||
| } else if (mql.addListener) { | ||
| mql.addListener(handler); | ||
| } | ||
| } catch (e) { /* matchMedia unavailable */ } | ||
| })(); | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| </script> | ||
| <!-- Resource hints for CDN resources --> | ||
| <link rel="preconnect" href="https://unpkg.com" crossorigin> | ||
| <link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin> | ||
| @@ -1309,8 +1389,20 @@ <h1 class="text-xl font-bold text-gray-900"> | ||
| </h1> | ||
| </div> | ||
| <!-- Connection status --> | ||
| <!-- Connection status and theme toggle --> | ||
| <div class="flex items-center space-x-4"> | ||
| <!-- Theme toggle --> | ||
| <button id="theme-toggle" | ||
| type="button" | ||
| onclick="toggleTheme()" | ||
| class="theme-toggle-btn p-2 rounded-md" | ||
| title="Switch to dark mode" | ||
| aria-label="Switch to dark mode" | ||
| aria-pressed="false"> | ||
| <i class="fas fa-moon" id="theme-icon-dark" aria-hidden="true"></i> | ||
| <i class="fas fa-sun hidden" id="theme-icon-light" aria-hidden="true"></i> | ||
| </button> | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| <div id="connection-status" class="flex items-center space-x-2 text-sm"> | ||
| <div class="w-2 h-2 bg-red-500 rounded-full"></div> | ||
| <span class="text-gray-600">Disconnected</span> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.