Files
Febe/src/Febe.Web/wwwroot/js/core/theme.js
T
Claude e33540246e Interfaccia web, parte 1: ospite, sicurezza, API, modalità dimostrativa, libreria, visualizzatore e account
Febe.Web: AddFebeWeb/UseFebe/FebeWebHost per le due vesti, interfaccia incorporata con IFileProvider proprio, indirizzi italiani, API JSON con contesto generato, eventi SSE, controlli di Host/Origin, gettone del desktop e password con blocco (§13.1), INativeShell e capacità per veste. Modalità --demo con 38 account e circa 18.000 elementi finti e scene del motore. Pagine Libreria, Visualizzatore, Account, Aggiungi account e Scheda account (contenuti, impostazioni con piano, cronologia); schermate in docs/schermate con le differenze dai mockup; prove delle API, della sicurezza, dell'esportazione CSV e dei dati dimostrativi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
2026-10-13 19:14:35 +00:00

57 lines
1.9 KiB
JavaScript

// Light, dark or as the system (spec §10.5). The choice is stored on the server (Impostazioni, Generali) and kept in
// this browser too, so the page does not flash at start (js/tema.js applies it before the first paint).
// In the demo «?tema=chiaro|scuro» wins for the whole tab without changing the stored choice.
import { api, carriedValue } from './api.js';
const media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
let choice = 'sistema';
function paint() {
const forced = carriedValue('tema');
const effective = forced === 'chiaro' || forced === 'scuro'
? forced
: choice === 'sistema' ? (media && media.matches ? 'scuro' : 'chiaro') : choice;
document.documentElement.setAttribute('data-tema', effective);
document.documentElement.setAttribute('data-scelta-tema', choice);
}
/** The stored choice: «chiaro», «scuro» or «sistema». */
export function themeChoice() {
return choice;
}
/** Applies a choice locally (no server call). */
export function applyTheme(value) {
choice = value === 'chiaro' || value === 'scuro' ? value : 'sistema';
try {
localStorage.setItem('febe.tema', choice);
} catch {
// storage blocked: the choice still applies to this page
}
paint();
}
/** At start: local choice first, then the server's. */
export async function initTheme() {
try {
choice = localStorage.getItem('febe.tema') || 'sistema';
} catch {
choice = 'sistema';
}
paint();
if (media && media.addEventListener) media.addEventListener('change', paint);
try {
const prefs = await api('/api/preferences');
if (prefs && prefs.theme && prefs.theme !== choice) applyTheme(prefs.theme);
} catch {
// keep the local choice
}
}
/** Stores a new choice on the server and applies it («Tema» in Impostazioni, Generali). */
export async function saveTheme(value) {
applyTheme(value);
await api('/api/preferences', { method: 'PUT', body: { theme: choice } });
}