mealie/frontend/plugins/theme.ts
Hoa (Kyle) Trinh c24d532608
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend Tests (push) Waiting to run
Docker Nightly Production / Build Package (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Release Drafter / ✏️ Draft release (push) Waiting to run
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
2025-06-19 17:09:12 +00:00

76 lines
2.1 KiB
TypeScript

export interface ThemeConfig {
lightPrimary: string;
lightAccent: string;
lightSecondary: string;
lightSuccess: string;
lightInfo: string;
lightWarning: string;
lightError: string;
darkPrimary: string;
darkAccent: string;
darkSecondary: string;
darkSuccess: string;
darkInfo: string;
darkWarning: string;
darkError: string;
}
let __cachedTheme: ThemeConfig | undefined;
async function fetchTheme(): Promise<ThemeConfig | undefined> {
const route = "/api/app/about/theme";
try {
const response = await fetch(route);
const data = await response.json();
return data as ThemeConfig;
}
catch {
return undefined;
}
}
export default defineNuxtPlugin(async (nuxtApp) => {
nuxtApp.hook("vuetify:before-create", async ({ vuetifyOptions }) => {
let theme = __cachedTheme;
if (!theme) {
theme = await fetchTheme();
__cachedTheme = theme;
}
vuetifyOptions.theme = {
defaultTheme: nuxtApp.$config.public.useDark ? "dark" : "light",
variations: {
colors: ["primary", "accent", "secondary", "success", "info", "warning", "error", "background"],
lighten: 3,
darken: 3,
},
themes: {
dark: {
dark: true,
colors: {
primary: theme?.lightPrimary ?? "#E58325",
accent: theme?.lightAccent ?? "#007A99",
secondary: theme?.lightSecondary ?? "#973542",
success: theme?.lightSuccess ?? "#43A047",
info: theme?.lightInfo ?? "#1976d2",
warning: theme?.lightWarning ?? "#FF6D00",
error: theme?.lightError ?? "#EF5350",
background: "#1E1E1E",
},
},
light: {
dark: false,
colors: {
primary: theme?.darkPrimary ?? "#E58325",
accent: theme?.darkAccent ?? "#007A99",
secondary: theme?.darkSecondary ?? "#973542",
success: theme?.darkSuccess ?? "#43A047",
info: theme?.darkInfo ?? "#1976d2",
warning: theme?.darkWarning ?? "#FF6D00",
error: theme?.darkError ?? "#EF5350",
},
},
},
};
});
});