more robust theme selector

This commit is contained in:
SethBurkart123
2023-11-02 17:11:02 +11:00
parent 46e86b9643
commit 8508169cd7
7 changed files with 246 additions and 109 deletions
+5 -2
View File
@@ -66,16 +66,19 @@ const applyTheme = async (themeName) => {
}
};
export const listThemes = async () => {
const themes = await localforage.keys();
return themes.filter((key) => key.startsWith("css_")).map((key) => key.replace("css_", ""));
};
export const downloadTheme = async (themeName, themeUrl) => {
console.log(`Fetching theme ${themeName} from ${themeUrl}...`);
const themeData = await fetchThemeJSON(themeUrl);
await saveToIndexedDB(themeData, themeName);
console.log(`Theme ${themeName} saved to IndexedDB`);
return;
};
export const setTheme = async (themeName, themeUrl) => {
await downloadTheme(themeName, themeUrl);
if (!(await themeExistsInDB(themeName))) {
await downloadTheme(themeName, themeUrl);
}