feat: Added light mode plus various bug fixes
- Added click handler for Easter egg that enables music inspiration feature. - Updated credits page to include new icons and handle click events. - Enhanced inspiration page to fetch and display Spotify track embed HTML. - Refactored inspiration loading logic to include track data. - Introduced theme selection in settings with light and dark modes. - Updated settings page to reflect new theme options and improve toast messages. - Refined layout styles across various pages for consistent theming. - Bumped application version to 1.5.0 in installer script.
This commit is contained in:
45
frontend/src/lib/utils/theme.ts
Normal file
45
frontend/src/lib/utils/theme.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { browser } from "$app/environment";
|
||||
|
||||
const THEME_KEY = "emly_theme";
|
||||
|
||||
export type Theme = "light" | "dark";
|
||||
|
||||
/**
|
||||
* Applies the theme to the document element and saves it to localStorage
|
||||
*/
|
||||
export function applyTheme(theme: Theme) {
|
||||
if (!browser) return;
|
||||
|
||||
const isDark = theme === "dark";
|
||||
document.documentElement.classList.toggle("dark", isDark);
|
||||
|
||||
try {
|
||||
localStorage.setItem(THEME_KEY, theme);
|
||||
} catch (e) {
|
||||
console.error("Failed to save theme to localStorage:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current theme from localStorage or returns the default
|
||||
*/
|
||||
export function getStoredTheme(): Theme {
|
||||
if (!browser) return "light";
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(THEME_KEY);
|
||||
return stored === "light" || stored === "dark" ? stored : "light";
|
||||
} catch {
|
||||
return "light";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles between light and dark theme
|
||||
*/
|
||||
export function toggleTheme(): Theme {
|
||||
const current = getStoredTheme();
|
||||
const newTheme: Theme = current === "dark" ? "light" : "dark";
|
||||
applyTheme(newTheme);
|
||||
return newTheme;
|
||||
}
|
||||
Reference in New Issue
Block a user