only single selected theme or custom background at once

This commit is contained in:
SethBurkart123
2023-11-02 19:05:37 +11:00
parent 7b0fc29461
commit e332977e08
7 changed files with 55 additions and 22 deletions
+10 -4
View File
@@ -84,9 +84,14 @@ 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_", ""));
console.log("Themes in IndexedDB:", themes);
return {
themes: themes.filter((key) => key.startsWith("css_")).map((key) => key.replace("css_", "")),
selectedTheme: await localforage.getItem("selectedTheme")
};
};
export const downloadTheme = async (themeName, themeUrl) => {
@@ -101,14 +106,15 @@ export const setTheme = async (themeName, themeUrl) => {
await downloadTheme(themeName, themeUrl);
}
localforage.setItem("selectedTheme", themeName);
await localforage.setItem("selectedTheme", themeName);
await applyTheme(themeName).catch((error) => {
console.error(`Failed to apply theme: ${error}`);
});
};
export const enableCurrentTheme = async () => {
const currentTheme = localforage.getItem("selectedTheme");
console.log("Enabling current theme...");
const currentTheme = await localforage.getItem("selectedTheme");
if (currentTheme) {
console.log(`Enabling current theme: ${currentTheme}`);
@@ -136,7 +142,7 @@ export const disableTheme = async () => {
}
// Remove any applied image URLs from the root element
const currentTheme = localforage.getItem("selectedTheme");
const currentTheme = await localforage.getItem("selectedTheme");
if (currentTheme) {
const themeData = await localforage.getItem(`css_${currentTheme}`);
if (themeData && themeData.images) {
+4 -2
View File
@@ -14,6 +14,8 @@ export class MessageHandler {
case "EditSidebar":
this.editSidebar();
break;
/* Theme related */
case "SetTheme":
console.log(request);
setTheme(request.body.themeName, request.body.themeURL).then(() => {
@@ -26,8 +28,8 @@ export class MessageHandler {
});
return true;
case "ListThemes":
listThemes().then((themes) => {
sendResponse({ themes });
listThemes().then((response) => {
sendResponse(response);
});
return true;
case "DisableTheme":