Skip to content

Commit ecf5d58

Browse files
authored
Merge pull request #103 from netbootxyz/add-dark-mode-support
Add dark mode support to webapp UI
2 parents 7d6cacc + 5da74c4 commit ecf5d58

File tree

3 files changed

+426
-2
lines changed

3 files changed

+426
-2
lines changed

public/index.ejs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<link rel="stylesheet" href="<%= baseurl %>public/vendor/css/bootstrap.min.css">
3030
<link rel="stylesheet" href="<%= baseurl %>public/vendor/css/docs.min.css">
3131
<link rel="stylesheet" href="<%= baseurl %>public/vendor/css/dataTables.bootstrap4.min.css">
32+
<link rel="stylesheet" href="<%= baseurl %>public/vendor/css/dark-theme.css">
3233
</head>
3334
<body>
3435
<!-- Navigation -->
@@ -54,6 +55,11 @@
5455
</ul>
5556
<ul class="navbar-nav ml-auto">
5657
<div id="statusbar" style="width:500px" ></div>
58+
<li class="nav-item">
59+
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle dark/light theme">
60+
<span id="theme-icon">🌙</span>
61+
</button>
62+
</li>
5763
</ul>
5864
</div>
5965
</nav>

public/netbootxyz-web.ejs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
11
// netboot.xyz
22
// Client side javascript
33

4+
//// Theme Management ////
5+
function initializeTheme() {
6+
const savedTheme = localStorage.getItem('netbootxyz-theme') || 'light';
7+
applyTheme(savedTheme);
8+
}
9+
10+
function toggleTheme() {
11+
const currentTheme = document.documentElement.getAttribute('data-theme') || 'light';
12+
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
13+
applyTheme(newTheme);
14+
localStorage.setItem('netbootxyz-theme', newTheme);
15+
}
16+
17+
function applyTheme(theme) {
18+
document.documentElement.setAttribute('data-theme', theme);
19+
const themeIcon = document.getElementById('theme-icon');
20+
if (themeIcon) {
21+
themeIcon.textContent = theme === 'light' ? '🌙' : '☀️';
22+
}
23+
24+
// Update Ace Editor theme if it exists
25+
updateAceEditorTheme(theme);
26+
}
27+
28+
function updateAceEditorTheme(theme) {
29+
const editorElement = document.getElementById('editor');
30+
if (editorElement && typeof ace !== 'undefined') {
31+
try {
32+
const editor = ace.edit('editor');
33+
const aceTheme = theme === 'dark' ? 'ace/theme/monokai' : 'ace/theme/chrome';
34+
editor.setTheme(aceTheme);
35+
} catch (e) {
36+
// Editor might not be initialized yet, ignore
37+
}
38+
}
39+
}
40+
441

542
// Initiate a websocket connection to the server
643
var host = window.location.hostname;
744
var port = window.location.port;
845
var protocol = window.location.protocol;
946
var socket = io.connect(protocol + '//' + host + ':' + port, {path: "<%= baseurl %>socket.io"});
1047
// If the page is being loaded for the first time render in the homepage
11-
$(document).ready(function(){renderdash()})
48+
$(document).ready(function(){
49+
// Initialize theme from localStorage or default to light
50+
initializeTheme();
51+
renderdash();
52+
})
1253

1354

1455
//// Dashboard Page rendering ////
@@ -212,7 +253,9 @@ socket.on('editrenderfile', function(response,filename,metadata){
212253
</div>\
213254
<div id="editor" style="height:100%;width:100%"></div>');
214255
editor = ace.edit('editor');
215-
editor.setTheme('ace/theme/chrome');
256+
const currentTheme = document.documentElement.getAttribute('data-theme') || 'light';
257+
const aceTheme = currentTheme === 'dark' ? 'ace/theme/monokai' : 'ace/theme/chrome';
258+
editor.setTheme(aceTheme);
216259
editor.session.setMode('ace/mode/sh');
217260
editor.$blockScrolling = Infinity;
218261
editor.setOptions({

0 commit comments

Comments
 (0)