Files
AstralRinth/apps/frontend/src/plugins/1.theme.js
Evan Song c20242cf1c Fix Cloudflare Pages build (#1285)
* fix(temp): remove box shadows from tailwind config

* fix(temp): "polyfill" global during build process

* refactor: use `import.meta` instead of deprecated `process`

* oops: replace `process.server` as well
2024-07-11 05:17:04 +00:00

28 lines
820 B
JavaScript

export default defineNuxtPlugin(async (nuxtApp) => {
await useAuth();
await useUser();
const themeStore = useTheme();
const cosmetics = useCosmetics();
nuxtApp.hook("app:mounted", () => {
if (import.meta.client && themeStore.value.preference === "system") {
const colorSchemeQueryList = window.matchMedia("(prefers-color-scheme: light)");
const setColorScheme = (e) => {
if (themeStore.value.preference === "system") {
if (e.matches) {
updateTheme("light");
} else {
updateTheme(cosmetics.value.preferredDarkTheme ?? "dark");
}
}
};
setColorScheme(colorSchemeQueryList);
colorSchemeQueryList.addEventListener("change", setColorScheme);
}
});
nuxtApp.provide("colorMode", themeStore.value);
});