mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
refactor: reduce browser storage dependence, remove unused code
This commit is contained in:
@@ -3,11 +3,11 @@ import localforage from 'localforage';
|
||||
import { CustomTheme } from '../../../interface/types/CustomThemes';
|
||||
import { applyTheme } from './applyTheme';
|
||||
import { removeTheme } from './removeTheme';
|
||||
import { settingsState } from '../../utils/listeners/SettingsState';
|
||||
|
||||
|
||||
export const setTheme = async (themeId: string) => {
|
||||
try {
|
||||
const enabledTheme = await browser.storage.local.get('selectedTheme') as { selectedTheme: string; };
|
||||
const theme = await localforage.getItem(themeId) as CustomTheme;
|
||||
|
||||
console.debug('Loading theme', theme);
|
||||
@@ -17,25 +17,21 @@ export const setTheme = async (themeId: string) => {
|
||||
const styleElement = document.getElementById('custom-theme');
|
||||
|
||||
// Remove the currently enabled theme
|
||||
if (enabledTheme.selectedTheme || styleElement) {
|
||||
const currentTheme = await localforage.getItem(enabledTheme.selectedTheme) as CustomTheme;
|
||||
if (settingsState.selectedTheme || styleElement) {
|
||||
const currentTheme = await localforage.getItem(settingsState.selectedTheme) as CustomTheme;
|
||||
if (currentTheme) {
|
||||
await removeTheme(currentTheme);
|
||||
}
|
||||
const color = await browser.storage.local.get('originalSelectedColor') as { originalSelectedColor: string; };
|
||||
originalSelectedColor = { selectedColor: color.originalSelectedColor };
|
||||
originalSelectedColor = { selectedColor: settingsState.originalSelectedColor };
|
||||
} else {
|
||||
originalSelectedColor = await browser.storage.local.get('selectedColor') as { selectedColor: string; };
|
||||
originalSelectedColor = { selectedColor: settingsState.selectedColor };
|
||||
}
|
||||
|
||||
await applyTheme(theme);
|
||||
|
||||
await browser.storage.local.set({
|
||||
selectedTheme: themeId,
|
||||
selectedColor: theme.selectedColor ? theme.selectedColor : (theme.defaultColour !== '' ? theme.defaultColour : '#007bff'),
|
||||
originalSelectedColor: originalSelectedColor.selectedColor
|
||||
});
|
||||
|
||||
settingsState.selectedTheme = themeId
|
||||
settingsState.selectedColor = theme.selectedColor ? theme.selectedColor : (theme.defaultColour !== '' ? theme.defaultColour : '#007bff')
|
||||
settingsState.originalSelectedColor = originalSelectedColor.selectedColor
|
||||
} catch (error) {
|
||||
console.error('Error setting theme:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user