mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
automatic theme deduplication on load
This commit is contained in:
+1
-26
@@ -2,8 +2,7 @@ import * as Sentry from "@sentry/browser";
|
|||||||
import browser from 'webextension-polyfill'
|
import browser from 'webextension-polyfill'
|
||||||
import { onError } from './seqta/utils/onError';
|
import { onError } from './seqta/utils/onError';
|
||||||
import { SettingsState } from "./types/storage";
|
import { SettingsState } from "./types/storage";
|
||||||
import DownloadTheme, { StoreDownloadTheme } from "./seqta/ui/themes/downloadTheme";
|
import DownloadTheme from "./seqta/ui/themes/downloadTheme";
|
||||||
import localforage from "localforage";
|
|
||||||
|
|
||||||
browser.storage.local.get([ "telemetry" ]).then((telemetry) => {
|
browser.storage.local.get([ "telemetry" ]).then((telemetry) => {
|
||||||
if (telemetry.telemetry === true) {
|
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 = () => {
|
export const openDB = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const request = indexedDB.open('MyDatabase', 1);
|
const request = indexedDB.open('MyDatabase', 1);
|
||||||
@@ -166,10 +145,6 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse:
|
|||||||
case 'DownloadTheme':
|
case 'DownloadTheme':
|
||||||
DownloadTheme(request.body.theme);
|
DownloadTheme(request.body.theme);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'DeleteDownloadedTheme':
|
|
||||||
DeleteDownloadedTheme(request.body);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unknown request type');
|
console.log('Unknown request type');
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { CustomTheme, DownloadedTheme } from '../types/CustomThemes';
|
|||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
import { ArrowUpOnSquareIcon, PencilIcon } from '@heroicons/react/24/outline';
|
import { ArrowUpOnSquareIcon, PencilIcon } from '@heroicons/react/24/outline';
|
||||||
import { sendThemeUpdate, setTheme } from '../hooks/ThemeManagment';
|
import { sendThemeUpdate, setTheme } from '../hooks/ThemeManagment';
|
||||||
|
import { DeleteDownloadedTheme } from '../pages/Store';
|
||||||
|
|
||||||
type ThemeCoverProps = {
|
type ThemeCoverProps = {
|
||||||
theme: Omit<CustomTheme, 'CustomImages'> | DownloadedTheme;
|
theme: Omit<CustomTheme, 'CustomImages'> | DownloadedTheme;
|
||||||
@@ -26,10 +27,7 @@ export const ThemeCover: React.FC<ThemeCoverProps> = ({
|
|||||||
if (isEditMode) return;
|
if (isEditMode) return;
|
||||||
if (downloaded) {
|
if (downloaded) {
|
||||||
await sendThemeUpdate(theme as DownloadedTheme, true)
|
await sendThemeUpdate(theme as DownloadedTheme, true)
|
||||||
await browser.runtime.sendMessage({
|
DeleteDownloadedTheme(theme.id);
|
||||||
type: 'DeleteDownloadedTheme',
|
|
||||||
body: theme.id
|
|
||||||
})
|
|
||||||
setTheme(theme.id);
|
setTheme(theme.id);
|
||||||
} else {
|
} else {
|
||||||
onThemeSelect(theme.id);
|
onThemeSelect(theme.id);
|
||||||
@@ -39,10 +37,7 @@ export const ThemeCover: React.FC<ThemeCoverProps> = ({
|
|||||||
const handleDeleteClick = (e: React.MouseEvent) => {
|
const handleDeleteClick = (e: React.MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (downloaded) {
|
if (downloaded) {
|
||||||
browser.runtime.sendMessage({
|
DeleteDownloadedTheme(theme.id);
|
||||||
type: 'DeleteDownloadedTheme',
|
|
||||||
body: theme.id
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
onThemeDelete(theme.id);
|
onThemeDelete(theme.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useEffect, useState, useCallback, forwardRef, useImperativeHandle, ForwardRefExoticComponent, RefAttributes } from 'react';
|
import React, { useEffect, useState, useCallback, forwardRef, useImperativeHandle, ForwardRefExoticComponent, RefAttributes } from 'react';
|
||||||
import { listThemes, deleteTheme, setTheme, disableTheme, getDownloadedThemes } from '../hooks/ThemeManagment';
|
import { listThemes, deleteTheme, setTheme, disableTheme, getDownloadedThemes } from '../hooks/ThemeManagment';
|
||||||
|
import { DeleteDownloadedTheme } from '../pages/Store';
|
||||||
import { ThemeCover } from './ThemeCover';
|
import { ThemeCover } from './ThemeCover';
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
import { CustomTheme, DownloadedTheme } from '../types/CustomThemes';
|
import { CustomTheme, DownloadedTheme } from '../types/CustomThemes';
|
||||||
@@ -56,21 +57,23 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
const fetchThemes = async () => {
|
const fetchThemes = async () => {
|
||||||
try {
|
try {
|
||||||
const { themes, selectedTheme } = await listThemes();
|
const { themes, selectedTheme } = await listThemes();
|
||||||
|
const tempDownloadedThemes = await getDownloadedThemes();
|
||||||
|
|
||||||
setThemes(themes);
|
setThemes(themes);
|
||||||
setDownloadedThemes(await getDownloadedThemes());
|
setDownloadedThemes(tempDownloadedThemes);
|
||||||
setSelectedTheme(selectedTheme ? selectedTheme : '');
|
setSelectedTheme(selectedTheme ? selectedTheme : '');
|
||||||
|
|
||||||
const matchingThemes = themes.filter(theme =>
|
const matchingThemes = themes.filter(theme =>
|
||||||
downloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id)
|
tempDownloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (matchingThemes.length > 0) {
|
if (matchingThemes.length > 0) {
|
||||||
matchingThemes.forEach((theme) => {
|
matchingThemes.forEach((theme) => {
|
||||||
browser.runtime.sendMessage({
|
DeleteDownloadedTheme(theme.id);
|
||||||
type: 'DeleteDownloadedTheme',
|
|
||||||
body: theme.id
|
setDownloadedThemes(
|
||||||
})
|
downloadedThemes.filter(downloadedTheme => downloadedTheme.id !== theme.id)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,10 +152,10 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<div
|
{ downloadedThemes.length + themes.length > 0 && <div
|
||||||
id="divider"
|
id="divider"
|
||||||
className="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"
|
className="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"
|
||||||
></div>
|
></div> }
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => browser.tabs.create({ url: browser.runtime.getURL('src/interface/index.html#store')})}
|
onClick={() => browser.tabs.create({ url: browser.runtime.getURL('src/interface/index.html#store')})}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ type ThemesResponse = {
|
|||||||
themes: Theme[];
|
themes: Theme[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const DeleteDownloadedTheme = async (themeID: string) => {
|
export const DeleteDownloadedTheme = async (themeID: string) => {
|
||||||
console.log('DeleteDownloaded Theme:', themeID)
|
console.debug('DeleteDownloaded Theme:', themeID)
|
||||||
await localforage.removeItem(themeID);
|
await localforage.removeItem(themeID);
|
||||||
|
|
||||||
const availableThemesList = await localforage.getItem('availableThemes') as string[];
|
const availableThemesList = await localforage.getItem('availableThemes') as string[];
|
||||||
|
|||||||
Reference in New Issue
Block a user