diff --git a/src/lib/globalFunctions/darkMode.ts b/src/lib/globalFunctions/darkMode.ts index 9f806d62..b74291de 100644 --- a/src/lib/globalFunctions/darkMode.ts +++ b/src/lib/globalFunctions/darkMode.ts @@ -4,17 +4,25 @@ import CapacitorPersistedStore from "../storage/capacitorPersistedStore"; import { get } from "svelte/store"; export const darkMode = new CapacitorPersistedStore(false, "darkMode"); +export const autoDarkMode = new CapacitorPersistedStore(true, "autoDarkMode"); + // Check if dark mode is enabled and set it if it is export async function checkAppMode() { + let isAuto = get(autoDarkMode); let isDark = get(darkMode); - if (isDark == null || isDark == undefined) { // Setting default dark mode | Fixes the toggle being ticked wrongly - darkMode.set(false); + if (isAuto) { + isDark = typeof window !== 'undefined' ? window.matchMedia('(prefers-color-scheme: dark)').matches : false; + darkMode.set(isDark); + } else if (isDark == null || isDark == undefined) { darkMode.set(false); isDark = false; - document.body.classList.add('dark'); - await StatusBar.setStyle({ style: Style.Dark }); } document.body.classList.toggle('dark', isDark); + if (isDark) { + await StatusBar.setStyle({ style: Style.Dark }); + } else { + await StatusBar.setStyle({ style: Style.Light }); + } } @@ -22,10 +30,25 @@ export async function checkAppMode() { export async function toggleDarkTheme() { const isDark = document.body.classList.toggle('dark'); darkMode.set(isDark); - // nativeSettings(); if (isDark) { await StatusBar.setStyle({ style: Style.Dark }); } else { await StatusBar.setStyle({ style: Style.Light }); } } + +export async function toggleAutoDarkMode() { + let isAuto = !get(autoDarkMode); + autoDarkMode.set(isAuto); + if (isAuto) { + checkAppMode(); + } +} +if (typeof window !== 'undefined') { + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', async (e) => { + if (get(autoDarkMode)) { + darkMode.set(e.matches); + checkAppMode(); + } + }); +} diff --git a/src/routes/personalInfo/about.svelte b/src/routes/personalInfo/about.svelte index 6f149393..b3af4290 100644 --- a/src/routes/personalInfo/about.svelte +++ b/src/routes/personalInfo/about.svelte @@ -9,6 +9,7 @@ import contributors from "$lib/components/personalInfo/contributors.json"; import { t, locale, locales} from "$lib/i18n"; import SubPageHeader from '$shared/subPageHeader.svelte'; + import IonPage from 'ionic-svelte/components/IonPage.svelte'; import { construct } from 'ionicons/icons'; interface Contributor { @@ -51,7 +52,7 @@ - +
@@ -121,6 +122,7 @@
+
- \ No newline at end of file