+ {themes.map((theme) => (
+
+ ))}
+
+ );
+};
+
+export default ThemeSelector;
\ No newline at end of file
diff --git a/src/background.js b/src/background.js
index 518fa3f8..f9671182 100644
--- a/src/background.js
+++ b/src/background.js
@@ -104,7 +104,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
case "currentTab":
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, request, function (response) {
- // send response from current tab to popup
sendResponse(response);
});
});
diff --git a/src/seqta/ui/Themes.js b/src/seqta/ui/Themes.js
index 2ad5d8ff..c97d6ecf 100644
--- a/src/seqta/ui/Themes.js
+++ b/src/seqta/ui/Themes.js
@@ -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);
}
diff --git a/src/seqta/utils/MessageListener.js b/src/seqta/utils/MessageListener.js
index 00ad3172..a80727dc 100644
--- a/src/seqta/utils/MessageListener.js
+++ b/src/seqta/utils/MessageListener.js
@@ -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);