save user preference theme color

This commit is contained in:
SethBurkart123
2024-05-08 17:34:12 +10:00
parent f077c13cf7
commit 533c684db8
3 changed files with 11 additions and 3 deletions
+9
View File
@@ -1,3 +1,4 @@
import localforage from 'localforage';
import { CustomTheme } from '../../../interface/types/CustomThemes';
import browser from 'webextension-polyfill';
@@ -8,6 +9,14 @@ export const removeTheme = async (theme: CustomTheme) => {
styleElement.parentNode?.removeChild(styleElement);
}
const themeSelectedColor = await browser.storage.local.get('selectedColor') as { selectedColor: string; };
const selectedTheme = await localforage.getItem(theme.id) as CustomTheme;
localforage.setItem(theme.id, {
...selectedTheme,
selectedColor: themeSelectedColor.selectedColor
})
// Reset default color
const originalSelectedColor = await browser.storage.local.get('originalSelectedColor') as { originalSelectedColor: string; };
if (originalSelectedColor.originalSelectedColor !== '') {
+1 -3
View File
@@ -10,8 +10,6 @@ export const setTheme = async (themeId: string) => {
const enabledTheme = await browser.storage.local.get('selectedTheme') as { selectedTheme: string; };
const theme = await localforage.getItem(themeId) as CustomTheme;
console.log(enabledTheme, theme)
console.debug('Loading theme', theme);
let originalSelectedColor = { selectedColor: '' };
@@ -34,7 +32,7 @@ export const setTheme = async (themeId: string) => {
await browser.storage.local.set({
selectedTheme: themeId,
selectedColor: theme.defaultColour !== '' ? theme.defaultColour : '#007bff',
selectedColor: theme.selectedColor ? theme.selectedColor : (theme.defaultColour !== '' ? theme.defaultColour : '#007bff'),
originalSelectedColor: originalSelectedColor.selectedColor
});