Skip to content

Commit e501054

Browse files
committed
Start with user's default light/dark theme
1 parent 610aabf commit e501054

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

Lib/profiling/sampling/_heatmap_assets/heatmap.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ function toggleTheme() {
3434
}
3535

3636
function restoreUIState() {
37-
// Restore theme
38-
const savedTheme = localStorage.getItem('heatmap-theme');
39-
if (savedTheme) {
40-
document.documentElement.setAttribute('data-theme', savedTheme);
41-
const btn = document.getElementById('theme-btn');
42-
if (btn) {
43-
btn.querySelector('.icon-moon').style.display = savedTheme === 'dark' ? 'none' : '';
44-
btn.querySelector('.icon-sun').style.display = savedTheme === 'dark' ? '' : 'none';
45-
}
37+
// Restore theme from localStorage, or use browser preference
38+
let theme = localStorage.getItem('heatmap-theme');
39+
if (!theme) {
40+
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
41+
}
42+
document.documentElement.setAttribute('data-theme', theme);
43+
const btn = document.getElementById('theme-btn');
44+
if (btn) {
45+
btn.querySelector('.icon-moon').style.display = theme === 'dark' ? 'none' : '';
46+
btn.querySelector('.icon-sun').style.display = theme === 'dark' ? '' : 'none';
4647
}
4748
}
4849

Lib/profiling/sampling/_heatmap_assets/heatmap_index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ function toggleTheme() {
3636
}
3737

3838
function restoreUIState() {
39-
// Restore theme
40-
const savedTheme = localStorage.getItem('heatmap-theme');
41-
if (savedTheme) {
42-
document.documentElement.setAttribute('data-theme', savedTheme);
43-
const btn = document.getElementById('theme-btn');
44-
if (btn) {
45-
btn.querySelector('.icon-moon').style.display = savedTheme === 'dark' ? 'none' : '';
46-
btn.querySelector('.icon-sun').style.display = savedTheme === 'dark' ? '' : 'none';
47-
}
39+
// Restore theme from localStorage, or use browser preference
40+
let theme = localStorage.getItem('heatmap-theme');
41+
if (!theme) {
42+
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
43+
}
44+
document.documentElement.setAttribute('data-theme', theme);
45+
const btn = document.getElementById('theme-btn');
46+
if (btn) {
47+
btn.querySelector('.icon-moon').style.display = theme === 'dark' ? 'none' : '';
48+
btn.querySelector('.icon-sun').style.display = theme === 'dark' ? '' : 'none';
4849
}
4950
}
5051

Lib/profiling/sampling/_heatmap_assets/heatmap_index_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en" data-theme="light">
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en" data-theme="light">
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">

0 commit comments

Comments
 (0)