feat(light-dark): normalize light/dark/like-os mode

permits user to define light, dark or like the desktop
This commit is contained in:
Edouard Vanbelle
2026-05-30 01:06:32 +02:00
parent ea83891a61
commit ca1a2bb649
13 changed files with 494 additions and 342 deletions
+21 -3
View File
@@ -1,3 +1,21 @@
// Apply saved theme immediately (render-blocking) to prevent FOUC.
// This file MUST be loaded without "defer" or "async".
if (localStorage.getItem('oxicloud_theme') === 'dark') document.documentElement.setAttribute('data-theme', 'dark');
// Apply saved colour-scheme choice immediately (render-blocking) to prevent FOUC.
// This file MUST be loaded WITHOUT "defer" or "async" so it runs before any paint.
//
// localStorage values:
// 'light' / 'dark' → force that mode (stamp html[data-color-scheme]).
// 'auto' / absent → follow the OS preference (no attribute → CSS default
// `color-scheme: light dark` resolves via prefers-color-scheme).
//
// Backward compat: existing users have 'light' / 'dark' stored from the old
// binary toggle; both still apply correctly. New 'auto' value is introduced
// by the segmented control in user-menu.
(() => {
var saved = localStorage.getItem('oxicloud_theme');
var html = document.documentElement;
if (saved === 'light' || saved === 'dark') {
html.setAttribute('data-color-scheme', saved);
} else {
html.removeAttribute('data-color-scheme');
}
})();