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
+1
View File
@@ -11,6 +11,7 @@ export type CustomTheme = {
isEditable: boolean; isEditable: boolean;
hideThemeName: boolean; hideThemeName: boolean;
webURL?: string; webURL?: string;
selectedColor?: string;
} }
export type DownloadedTheme = CustomTheme & { export type DownloadedTheme = CustomTheme & {
+9
View File
@@ -1,3 +1,4 @@
import localforage from 'localforage';
import { CustomTheme } from '../../../interface/types/CustomThemes'; import { CustomTheme } from '../../../interface/types/CustomThemes';
import browser from 'webextension-polyfill'; import browser from 'webextension-polyfill';
@@ -8,6 +9,14 @@ export const removeTheme = async (theme: CustomTheme) => {
styleElement.parentNode?.removeChild(styleElement); 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 // Reset default color
const originalSelectedColor = await browser.storage.local.get('originalSelectedColor') as { originalSelectedColor: string; }; const originalSelectedColor = await browser.storage.local.get('originalSelectedColor') as { originalSelectedColor: string; };
if (originalSelectedColor.originalSelectedColor !== '') { 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 enabledTheme = await browser.storage.local.get('selectedTheme') as { selectedTheme: string; };
const theme = await localforage.getItem(themeId) as CustomTheme; const theme = await localforage.getItem(themeId) as CustomTheme;
console.log(enabledTheme, theme)
console.debug('Loading theme', theme); console.debug('Loading theme', theme);
let originalSelectedColor = { selectedColor: '' }; let originalSelectedColor = { selectedColor: '' };
@@ -34,7 +32,7 @@ export const setTheme = async (themeId: string) => {
await browser.storage.local.set({ await browser.storage.local.set({
selectedTheme: themeId, selectedTheme: themeId,
selectedColor: theme.defaultColour !== '' ? theme.defaultColour : '#007bff', selectedColor: theme.selectedColor ? theme.selectedColor : (theme.defaultColour !== '' ? theme.defaultColour : '#007bff'),
originalSelectedColor: originalSelectedColor.selectedColor originalSelectedColor: originalSelectedColor.selectedColor
}); });