diff --git a/src/background.ts b/src/background.ts index c1462f3e..2084324e 100644 --- a/src/background.ts +++ b/src/background.ts @@ -2,8 +2,7 @@ import * as Sentry from "@sentry/browser"; import browser from 'webextension-polyfill' import { onError } from './seqta/utils/onError'; import { SettingsState } from "./types/storage"; -import DownloadTheme, { StoreDownloadTheme } from "./seqta/ui/themes/downloadTheme"; -import localforage from "localforage"; +import DownloadTheme from "./seqta/ui/themes/downloadTheme"; browser.storage.local.get([ "telemetry" ]).then((telemetry) => { if (telemetry.telemetry === true) { @@ -18,26 +17,6 @@ browser.storage.local.get([ "telemetry" ]).then((telemetry) => { } }) -const DeleteDownloadedTheme = async (themeID: string) => { - console.log('DeleteDownloaded Theme:', themeID) - await localforage.removeItem(themeID); - - const availableThemesList = await localforage.getItem('availableThemes') as string[]; - const updatedThemesList = availableThemesList.filter(theme => theme !== themeID); - - await localforage.setItem('availableThemes', updatedThemesList); - - browser.tabs.query({}).then(function (tabs) { - for (let tab of tabs) { - if (tab.url?.includes('chrome-extension://')) { - browser.tabs.sendMessage(tab.id!, { - info: 'themeChanged' - }); - } - } - }); -} - export const openDB = () => { return new Promise((resolve, reject) => { const request = indexedDB.open('MyDatabase', 1); @@ -166,10 +145,6 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse: case 'DownloadTheme': DownloadTheme(request.body.theme); break; - - case 'DeleteDownloadedTheme': - DeleteDownloadedTheme(request.body); - break; default: console.log('Unknown request type'); diff --git a/src/interface/components/ThemeCover.tsx b/src/interface/components/ThemeCover.tsx index 1b1e362f..335e1189 100644 --- a/src/interface/components/ThemeCover.tsx +++ b/src/interface/components/ThemeCover.tsx @@ -3,6 +3,7 @@ import { CustomTheme, DownloadedTheme } from '../types/CustomThemes'; import browser from 'webextension-polyfill'; import { ArrowUpOnSquareIcon, PencilIcon } from '@heroicons/react/24/outline'; import { sendThemeUpdate, setTheme } from '../hooks/ThemeManagment'; +import { DeleteDownloadedTheme } from '../pages/Store'; type ThemeCoverProps = { theme: Omit | DownloadedTheme; @@ -26,10 +27,7 @@ export const ThemeCover: React.FC = ({ if (isEditMode) return; if (downloaded) { await sendThemeUpdate(theme as DownloadedTheme, true) - await browser.runtime.sendMessage({ - type: 'DeleteDownloadedTheme', - body: theme.id - }) + DeleteDownloadedTheme(theme.id); setTheme(theme.id); } else { onThemeSelect(theme.id); @@ -39,10 +37,7 @@ export const ThemeCover: React.FC = ({ const handleDeleteClick = (e: React.MouseEvent) => { e.stopPropagation(); if (downloaded) { - browser.runtime.sendMessage({ - type: 'DeleteDownloadedTheme', - body: theme.id - }) + DeleteDownloadedTheme(theme.id); } else { onThemeDelete(theme.id); } diff --git a/src/interface/components/ThemeSelector.tsx b/src/interface/components/ThemeSelector.tsx index 8dba3ee3..09a8b1f0 100644 --- a/src/interface/components/ThemeSelector.tsx +++ b/src/interface/components/ThemeSelector.tsx @@ -1,5 +1,6 @@ import React, { useEffect, useState, useCallback, forwardRef, useImperativeHandle, ForwardRefExoticComponent, RefAttributes } from 'react'; import { listThemes, deleteTheme, setTheme, disableTheme, getDownloadedThemes } from '../hooks/ThemeManagment'; +import { DeleteDownloadedTheme } from '../pages/Store'; import { ThemeCover } from './ThemeCover'; import browser from 'webextension-polyfill'; import { CustomTheme, DownloadedTheme } from '../types/CustomThemes'; @@ -56,21 +57,23 @@ const ThemeSelector: ForwardRefExoticComponent & const fetchThemes = async () => { try { const { themes, selectedTheme } = await listThemes(); - + const tempDownloadedThemes = await getDownloadedThemes(); + setThemes(themes); - setDownloadedThemes(await getDownloadedThemes()); + setDownloadedThemes(tempDownloadedThemes); setSelectedTheme(selectedTheme ? selectedTheme : ''); - + const matchingThemes = themes.filter(theme => - downloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id) + tempDownloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id) ); if (matchingThemes.length > 0) { matchingThemes.forEach((theme) => { - browser.runtime.sendMessage({ - type: 'DeleteDownloadedTheme', - body: theme.id - }) + DeleteDownloadedTheme(theme.id); + + setDownloadedThemes( + downloadedThemes.filter(downloadedTheme => downloadedTheme.id !== theme.id) + ) }) } @@ -149,10 +152,10 @@ const ThemeSelector: ForwardRefExoticComponent & /> ))} -
0 &&
+ >
}