diff --git a/frontend/index.html b/frontend/index.html index 310ae82..9dc4f1e 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -6,10 +6,10 @@ Planer2 diff --git a/frontend/src/App.vue b/frontend/src/App.vue index e772ce0..73483cc 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -10,7 +10,15 @@ import { offen as pruefungOffen, starte as startePruefung, schliesse as schliess const projekte = ref([]) const aktivesProjekt = ref(null) const meldung = ref('') -const dunkel = ref(document.documentElement.classList.contains('dark')) + +// Drei Modi im Kreis; „auto" folgt der Systemeinstellung +const MODI = ['auto', 'hell', 'dunkel'] +const ICONS = { auto: 'A', hell: '☀', dunkel: '☾' } +const TITEL = { auto: 'Systemeinstellung', hell: 'Hellmodus', dunkel: 'Dunkelmodus' } + +const systemDunkel = window.matchMedia('(prefers-color-scheme: dark)') +const gemerkterModus = localStorage.getItem('darkModus') +const modus = ref(MODI.includes(gemerkterModus) ? gemerkterModus : 'auto') async function ladeProjekte() { meldung.value = '' @@ -40,12 +48,20 @@ watch(aktivesProjekt, name => { else localStorage.removeItem('aktivesProjekt') }) -function wechsleDarkMode() { - dunkel.value = !dunkel.value - document.documentElement.classList.toggle('dark', dunkel.value) - localStorage.setItem('darkMode', dunkel.value) +function wendeAn() { + const dunkel = modus.value === 'auto' ? systemDunkel.matches : modus.value === 'dunkel' + document.documentElement.classList.toggle('dark', dunkel) } +function wechsleDarkMode() { + modus.value = MODI[(MODI.indexOf(modus.value) + 1) % MODI.length] + localStorage.setItem('darkModus', modus.value) + wendeAn() +} + +// Systemwechsel wirkt sofort, solange „auto" aktiv ist +systemDunkel.addEventListener('change', () => { if (modus.value === 'auto') wendeAn() }) + onMounted(async () => { await ladeProjekte() const gemerkt = localStorage.getItem('aktivesProjekt') @@ -70,8 +86,8 @@ onMounted(async () => { title="Karten prüfen" @click="startePruefung(aktivesProjekt)" >⌾ -