Skip to content

Commit

Permalink
Fix old version management
Browse files Browse the repository at this point in the history
  • Loading branch information
xypnox committed Feb 9, 2024
1 parent 7fa8358 commit 3456cc3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/themeManager/loadTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ if (style && themeCss) {
if (version && version === THEME_MANAGER_VERSION) {
if (themeString) style.innerHTML = themeString;
} else {
console.log("Theme Manager outdated, not loading theme, setting version");
localStorage.setItem("xypnox-themeConfig", JSON.stringify({ ...conf, version: THEME_MANAGER_VERSION }));
console.warn("Theme Manager version mismatch, not loading theme, Open Theme editor again to update version.", {
localVersion: version,
currentVersion: THEME_MANAGER_VERSION,
});
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions src/components/themeManager/themeStateDef.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createEffect, createMemo, createSignal, on, onMount } from "solid-js";
import { createStoredStore, setLocalStorage } from "../../utils/localStore";
import { createStoredStore, parseLocalStorage, setLocalStorage } from "../../utils/localStore";

import { generateThemeFromPalette, type ThemeMode, type ThemePalette, defaultPalettes, cssConverter } from "../../theme"
import { THEME_MANAGER_VERSION } from "./version";
Expand All @@ -11,10 +11,16 @@ const getUserPreferenceMode = () => {
return 'light';
}


export const createThemeState = (initTheme?: 'default_aster' | 'default_brutalist', initMode?: ThemeMode) => {
const themesData = createStoredStore<ThemePalette[]>('xypnox-themes', []);

const defaultConfig = {
mode: initMode ?? 'auto',
theme: initTheme ?? 'default_aster',
debug: false,
version: THEME_MANAGER_VERSION,
}

const themeConfig = createStoredStore<{
mode: ThemeMode;
theme: string;
Expand All @@ -25,6 +31,23 @@ export const createThemeState = (initTheme?: 'default_aster' | 'default_brutalis
theme: initTheme ?? 'default_aster',
debug: false,
version: THEME_MANAGER_VERSION,
}); // This is the default configuration

// If it is a old version, we need to update it, for now the structure remains same for config, no need to update it,
// and the css generators are functions that are updated as new version is shipped

onMount(() => {
const localConf = parseLocalStorage('xypnox-themeConfig', defaultConfig);
if (localConf.version !== THEME_MANAGER_VERSION) {
console.log("Theme Manager version mismatch, Updating version.", {
localVersion: localConf.version,
currentVersion: THEME_MANAGER_VERSION,
});
setLocalStorage('xypnox-themeConfig', {
...localConf,
version: THEME_MANAGER_VERSION,
});
}
});

const themes = createMemo(() => {
Expand Down

0 comments on commit 3456cc3

Please sign in to comment.