π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
π¨ Neatness tweaks for theme applying
Alicia Sykesa2a23d63fe93
diff --git a/src/App.vue b/src/App.vueindex a305274f..415d4577 100644--- a/src/App.vue+++ b/src/App.vue@@ -55,9 +55,7 @@ export default {handler() { syncPageMeta(this.$route, this.$store); },immediate: true,},- /* Apply the effective theme whenever it changes β on app load, when the- * user picks a new theme, when navigating between sub-configs, or when- * a route declares its own theme via `meta.theme` (e.g. the 404 page). */+ /* Apply the effective theme whenever it changes */effectiveTheme: {immediate: true,handler(t) { applyTheme(t, this.appConfig); },@@ -220,19 +218,11 @@ export default {e.preventDefault();return 'You may have unsaved edits. Are you sure you want to exit the page?';},- /* If dayTheme/nightTheme is configured, switch to it based on OS preference.- * Commits to the store β the `theme` watcher then handles DOM application. */- applyThemeBasedOnOSPreference() {- const prefersDark = window.matchMedia?.('(prefers-color-scheme: dark)').matches;- const osTheme = prefersDark ? this.appConfig.nightTheme : this.appConfig.dayTheme;- if (osTheme) this.$store.commit(Keys.SET_THEME, osTheme);- },},/* Basic initialization tasks on app load */async mounted() {await this.$store.dispatch(Keys.INITIALIZE_CONFIG); // Initialize config before moving onthis.applyLanguage(); // Apply users local language- this.applyThemeBasedOnOSPreference(); // Override with OS-preference theme, if configuredthis.hideSplash(); // Hide the splash screen, if visiblethis.applyCustomStyles(); // Apply custom CSS and external stylesheetsthis.hideLoader(); // If initial placeholder still visible, hide itdiff --git a/src/components/Settings/CustomThemeMaker.vue b/src/components/Settings/CustomThemeMaker.vueindex 229b053d..73732cdd 100644--- a/src/components/Settings/CustomThemeMaker.vue+++ b/src/components/Settings/CustomThemeMaker.vue@@ -51,7 +51,6 @@</template><script>-import StoreKeys from '@/utils/StoreMutations';import { localStorageKeys, mainCssVars } from '@/utils/config/defaults';import Button from '@/components/FormElements/Button';import SaveIcon from '@/assets/interface-icons/save-config.svg';@@ -82,14 +81,13 @@ export default {setVariable(variable, value) {document.documentElement.style.setProperty(`--${variable}`, value);},- /* Updates browser storage, and srore with new color settings, and shows success msg */+ /* Persist new color settings to localStorage and notify user */saveChanges() {let priorSettings = {};try { priorSettings = JSON.parse(localStorage[localStorageKeys.CUSTOM_COLORS] || '{}'); }catch (e) { /* ignore corrupt data */ }priorSettings[this.themeToEdit] = this.customColors;localStorage.setItem(localStorageKeys.CUSTOM_COLORS, JSON.stringify(priorSettings));- this.$store.commit(StoreKeys.SET_CUSTOM_COLORS, priorSettings);this.$toast(this.$t('theme-maker.saved-toast', { theme: this.themeToEdit }));this.$emit('closeThemeConfigurator');},diff --git a/src/store.js b/src/store.jsindex 5440898c..f81a8dd4 100644--- a/src/store.js+++ b/src/store.js@@ -22,7 +22,6 @@ const {SET_ITEM_LAYOUT,SET_ITEM_SIZE,SET_THEME,- SET_CUSTOM_COLORS,UPDATE_ITEM,USE_MAIN_CONFIG,SET_EDIT_MODE,@@ -113,8 +112,17 @@ const store = createStore({theme(state) {const localStorageKey = state.currentConfigInfo.confId? `${localStorageKeys.THEME}-${state.currentConfigInfo.confId}` : localStorageKeys.THEME;- const configTheme = state.config?.appConfig?.theme;- return localStorage[localStorageKey] || configTheme || defaultTheme;+ // Read reactive deps upfront so Vuex tracks every branch (avoids the+ // short-circuit caching bug where unread props wouldn't invalidate).+ const cfg = state.config?.appConfig;+ const configTheme = cfg?.theme;+ const dayTheme = cfg?.dayTheme;+ const nightTheme = cfg?.nightTheme;+ // Resolution: user's saved choice β OS preference (if configured) β config default+ const localTheme = localStorage[localStorageKey];+ if (localTheme) return localTheme;+ const prefersDark = window.matchMedia?.('(prefers-color-scheme: dark)').matches;+ return (prefersDark ? nightTheme : dayTheme) || configTheme || defaultTheme;},webSearch(state, getters) {return getters.appConfig.webSearch || {};@@ -342,12 +350,6 @@ const store = createStore({localStorage.setItem(themeStoreKey, theme);InfoHandler('Theme updated', InfoKeys.VISUAL);},- [SET_CUSTOM_COLORS](state, customColors) {- const newConfig = { ...state.config };- newConfig.appConfig.customColors = customColors;- state.config = newConfig;- InfoHandler('Color palette updated', InfoKeys.VISUAL);- },[SET_ITEM_LAYOUT](state, layout) {const newConfig = { ...state.config };newConfig.appConfig.layout = layout;diff --git a/src/utils/StoreMutations.js b/src/utils/StoreMutations.jsindex 0332d8fd..c918b6fc 100644--- a/src/utils/StoreMutations.js+++ b/src/utils/StoreMutations.js@@ -14,7 +14,6 @@ const KEY_NAMES = ['SET_ITEM_LAYOUT','SET_ITEM_SIZE','SET_THEME',- 'SET_CUSTOM_COLORS','USE_MAIN_CONFIG','UPDATE_ITEM','SET_PAGE_INFO',diff --git a/src/utils/Theming.js b/src/utils/Theming.jsindex e40bc203..30d1fbaf 100644--- a/src/utils/Theming.js+++ b/src/utils/Theming.js@@ -42,20 +42,42 @@ const applyRemote = (href) => {document.head.appendChild(link);};+/* Collect every CSS var name that appears in any theme's custom colors */+const allKnownVarNames = (colorMap) => {+ const names = new Set();+ Object.values(colorMap || {}).forEach((themeVars) => {+ Object.keys(themeVars || {}).forEach((v) => names.add(v));+ });+ return names;+};+const applyCustomVars = (theme, appConfig) => {- mainCssVars.forEach((v) => html().style.removeProperty(`--${v}`));let localColors = {};try {localColors = JSON.parse(localStorage[localStorageKeys.CUSTOM_COLORS] || '{}');- } catch (e) { /* corrupt JSON β skip */ }- const vars = { ...(appConfig?.customColors || {}), ...localColors }[theme];+ } catch (e) {+ ErrorHandler('Corrupted theme data in localstorage', e);+ }+ const configColors = appConfig?.customColors || {};++ // Clear any and all vars set by a previous theme+ const toClear = new Set([+ ...mainCssVars,+ ...allKnownVarNames(configColors),+ ...allKnownVarNames(localColors),+ ]);+ toClear.forEach((v) => html().style.removeProperty(`--${v}`));++ // Apply the current theme's custom colors (localStorage overrides appConfig)+ const vars = { ...configColors, ...localColors }[theme];if (!vars) return;Object.entries(vars).forEach(([k, v]) => html().style.setProperty(`--${k}`, v));};/**- * Apply a theme name to the document. Handles built-in + user-defined + external- * stylesheets + the special "default" reset + per-theme custom CSS vars+ * Apply a theme name to the document+ * Handles built-in, user-defined, external stylesheets,+ * the special "default" reset, and per-theme custom CSS vars*/export const applyTheme = (theme, appConfig = {}) => {if (!theme) return;