2025-09-07 00:33:37 -04:00
|
|
|
import { type ThemeInstance } from "vuetify";
|
|
|
|
|
import { LightTheme, DarkTheme } from "@/plugins/vuetify";
|
|
|
|
|
|
|
|
|
|
export const resetTheme = (theme: ThemeInstance) => {
|
2026-03-24 17:49:56 -05:00
|
|
|
const themeType = theme.global.current.value.dark ? "dark" : "light";
|
2025-09-07 00:33:37 -04:00
|
|
|
localStorage.removeItem(`${themeType}-background`);
|
|
|
|
|
localStorage.removeItem(`${themeType}-primary`);
|
|
|
|
|
localStorage.removeItem(`${themeType}-secondary`);
|
|
|
|
|
localStorage.removeItem(`${themeType}-surface`);
|
|
|
|
|
|
|
|
|
|
restoreThemeConfig(theme);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getThemeColor = (theme: ThemeInstance, color: string): string => {
|
2026-03-24 17:49:56 -05:00
|
|
|
const themeType = theme.global.current.value.dark ? "dark" : "light";
|
|
|
|
|
const defaultTheme = theme.global.current.value.dark ? DarkTheme : LightTheme;
|
2025-09-07 00:33:37 -04:00
|
|
|
return localStorage.getItem(`${themeType}-${color}`) ?? defaultTheme.colors![color]!;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setThemeColor = (theme: ThemeInstance, color: string, value: string | null) => {
|
2026-03-24 17:49:56 -05:00
|
|
|
const themeType = theme.global.current.value.dark ? "dark" : "light";
|
2025-09-07 00:33:37 -04:00
|
|
|
if (value) localStorage.setItem(`${themeType}-${color}`, value);
|
|
|
|
|
else localStorage.removeItem(`${themeType}-${color}`);
|
|
|
|
|
|
|
|
|
|
restoreThemeConfig(theme);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const toggleTheme = (theme: ThemeInstance) => {
|
|
|
|
|
const currentTheme = localStorage.getItem("theme");
|
|
|
|
|
localStorage.setItem("theme", currentTheme === "LightTheme" ? "DarkTheme" : "LightTheme");
|
|
|
|
|
|
|
|
|
|
restoreThemeConfig(theme);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const restoreThemeConfig = (theme: ThemeInstance) => {
|
|
|
|
|
// Restore theme preference
|
|
|
|
|
const storedTheme = localStorage.getItem("theme");
|
|
|
|
|
if (storedTheme) theme.global.name.value = storedTheme;
|
|
|
|
|
|
|
|
|
|
// Restore custom theme colors
|
2026-03-24 17:49:56 -05:00
|
|
|
const themeType = theme.global.current.value.dark ? "dark" : "light";
|
2025-09-07 00:33:37 -04:00
|
|
|
const defaultTheme = theme.global.name.value === "LightTheme" ? LightTheme : DarkTheme;
|
|
|
|
|
|
|
|
|
|
const customBackground = localStorage.getItem(`${themeType}-background`);
|
|
|
|
|
const customPrimary = localStorage.getItem(`${themeType}-primary`);
|
|
|
|
|
const customSecondary = localStorage.getItem(`${themeType}-secondary`);
|
|
|
|
|
const customSurface = localStorage.getItem(`${themeType}-surface`);
|
|
|
|
|
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.background = customBackground ?? defaultTheme.colors!.background!;
|
2026-03-24 17:49:56 -05:00
|
|
|
theme.themes.value[theme.global.name.value].colors.sidebar = theme.global.current.value.dark
|
2025-09-07 00:33:37 -04:00
|
|
|
? (customBackground ?? defaultTheme.colors!.sidebar!)
|
|
|
|
|
: (customSurface ?? defaultTheme.colors!.sidebar!);
|
|
|
|
|
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.primary = customPrimary ?? defaultTheme.colors!.primary!;
|
2025-12-05 04:02:46 -05:00
|
|
|
theme.themes.value[theme.global.name.value].colors.buttonActive =
|
|
|
|
|
(themeType === "light" ? customPrimary : customSecondary) ?? defaultTheme.colors!.buttonActive!;
|
2025-09-07 00:33:37 -04:00
|
|
|
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.secondary = customSecondary ?? defaultTheme.colors!.secondary!;
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.buttonPassive =
|
2025-12-05 04:02:46 -05:00
|
|
|
(themeType === "light" ? customSecondary : customPrimary) ?? defaultTheme.colors!.buttonPassive!;
|
2025-09-07 00:33:37 -04:00
|
|
|
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.accent = customSecondary ?? defaultTheme.colors!.accent!;
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.toggle = customSecondary ?? defaultTheme.colors!.toggle!;
|
|
|
|
|
|
|
|
|
|
theme.themes.value[theme.global.name.value].colors.surface = customSurface ?? defaultTheme.colors!.surface!;
|
|
|
|
|
};
|