mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-04-30 11:33:36 +00:00
* Expand SCSS variables for improved theming * Redesign 404 page with dynamic movie quotes * Add password generator page * Add missing Plex authentication page * Improve torrent table and torrents page * Enhance toast notification component * Enhance popup components * Refine UI components and remove DarkmodeToggle * Add user profile component for settings * Update autocomplete dropdown component * Update register page * Redesign signin and register pages with improved UX * Improve torrent table with sort toggle and highlight colors * eslint & prettier fixes
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { ref, computed } from "vue";
|
|
|
|
type Theme = "light" | "dark" | "auto";
|
|
|
|
const currentTheme = ref<Theme>("auto");
|
|
|
|
function systemDarkModeEnabled(): boolean {
|
|
const computedStyle = window.getComputedStyle(document.body);
|
|
if (computedStyle?.colorScheme != null) {
|
|
return computedStyle.colorScheme.includes("dark");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function applyTheme(theme: Theme) {
|
|
if (theme === "auto") {
|
|
const systemDark = systemDarkModeEnabled();
|
|
document.body.className = systemDark ? "dark" : "light";
|
|
} else {
|
|
document.body.className = theme;
|
|
}
|
|
}
|
|
|
|
export function useTheme() {
|
|
const savedTheme = computed(
|
|
() => (localStorage.getItem("theme-preference") as Theme) || "auto"
|
|
);
|
|
|
|
function initTheme() {
|
|
const theme = savedTheme.value;
|
|
currentTheme.value = theme;
|
|
applyTheme(theme);
|
|
|
|
// Listen for system theme changes when in auto mode
|
|
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
mediaQuery.addEventListener("change", e => {
|
|
const currentSetting = localStorage.getItem("theme-preference") as Theme;
|
|
if (currentSetting === "auto") {
|
|
document.body.className = e.matches ? "dark" : "light";
|
|
}
|
|
});
|
|
}
|
|
|
|
function setTheme(theme: Theme) {
|
|
currentTheme.value = theme;
|
|
localStorage.setItem("theme-preference", theme);
|
|
applyTheme(theme);
|
|
}
|
|
|
|
return {
|
|
currentTheme,
|
|
savedTheme,
|
|
initTheme,
|
|
setTheme
|
|
};
|
|
}
|