save selectedColor for non-destructive theme viewing

This commit is contained in:
SethBurkart123
2024-04-05 10:30:23 +11:00
parent 6937ca6660
commit ea6282460d
4 changed files with 14 additions and 4 deletions
+1
View File
@@ -173,6 +173,7 @@ const DefaultValues: SettingsState = {
subjectfilters: {},
selectedTheme: '',
selectedColor: 'linear-gradient(40deg, rgba(201,61,0,1) 0%, RGBA(170, 5, 58, 1) 100%)',
originalSelectedColor: '',
DarkMode: true,
shortcuts: [
{
+5 -3
View File
@@ -1,7 +1,7 @@
import { CustomTheme } from '../../../interface/types/CustomThemes';
import browser from 'webextension-polyfill';
export const removeTheme = (theme: CustomTheme) => {
export const removeTheme = async (theme: CustomTheme) => {
// Remove custom CSS
const styleElement = document.getElementById('custom-theme');
if (styleElement) {
@@ -9,7 +9,9 @@ export const removeTheme = (theme: CustomTheme) => {
}
// Reset default color
//browser.storage.local.set({ selectedColor: '' });
const originalSelectedColor = await browser.storage.local.get('originalSelectedColor') as { originalSelectedColor: string; };
await browser.storage.local.set({ selectedColor: originalSelectedColor.originalSelectedColor });
// Remove custom images
const customImageVariables = theme.CustomImages.map((image) => image.variableName);
customImageVariables.forEach((variableName) => {
+7 -1
View File
@@ -20,8 +20,14 @@ export const setTheme = async (themeId: string) => {
}
}
const originalSelectedColor = await browser.storage.local.get('selectedColor') as { selectedColor: string; };
await applyTheme(theme);
await browser.storage.local.set({ selectedTheme: themeId });
await browser.storage.local.set({
selectedTheme: themeId,
selectedColor: theme.defaultColour,
originalSelectedColor: originalSelectedColor.selectedColor
});
} catch (error) {
console.error('Error setting theme:', error);
+1
View File
@@ -29,6 +29,7 @@ export interface SettingsState {
telemetry: boolean;
onoff: boolean;
selectedColor: string;
originalSelectedColor: string;
shortcuts: Shortcut[];
subjectfilters: Record<string, any>;
transparencyEffects: boolean;