mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
more robust theme selector
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* global chrome */
|
||||
|
||||
import { MenuOptionsOpen, OpenMenuOptions, closeSettings } from "../../SEQTA.js";
|
||||
import { downloadTheme, setTheme } from "../ui/Themes.js";
|
||||
import { downloadTheme, listThemes, setTheme } from "../ui/Themes.js";
|
||||
|
||||
export class MessageHandler {
|
||||
constructor() {
|
||||
chrome.runtime.onMessage.addListener(this.routeMessage.bind(this));
|
||||
}
|
||||
|
||||
routeMessage(request) {
|
||||
routeMessage(request, sender, sendResponse) {
|
||||
switch (request.info) {
|
||||
|
||||
case "EditSidebar":
|
||||
@@ -16,11 +16,20 @@ export class MessageHandler {
|
||||
break;
|
||||
case "SetTheme":
|
||||
console.log(request);
|
||||
setTheme(request.body.themeName, request.body.themeURL);
|
||||
break;
|
||||
setTheme(request.body.themeName, request.body.themeURL).then(() => {
|
||||
sendResponse({ status: "success" });
|
||||
});
|
||||
return true;
|
||||
case "DownloadTheme":
|
||||
downloadTheme(request.body.themeURL, request.body.themeName);
|
||||
break;
|
||||
downloadTheme(request.body.themeName, request.body.themeURL).then(() => {
|
||||
sendResponse({ status: "success" });
|
||||
});
|
||||
return true;
|
||||
case "ListThemes":
|
||||
listThemes().then((themes) => {
|
||||
sendResponse({ themes });
|
||||
});
|
||||
return true;
|
||||
|
||||
default:
|
||||
console.log("Unknown request info:", request.info);
|
||||
|
||||
Reference in New Issue
Block a user