Files
BetterSEQTA-Plus/src/seqta/ui/themes/applyTheme.ts
T
2024-08-21 17:36:21 +10:00

27 lines
888 B
TypeScript

import { CustomImage, CustomTheme } from '../../../interface/types/CustomThemes';
import { settingsState } from '../../utils/listeners/SettingsState';
import { applyCustomCSS } from './Themes';
export const applyTheme = async (theme: CustomTheme, reEnable?: boolean) => {
let CustomCSS = '';
let CustomImages: CustomImage[] = [];
if (theme?.CustomCSS) CustomCSS = theme.CustomCSS;
if (theme?.CustomImages) CustomImages = theme.CustomImages;
if (theme?.forceDark != undefined) {
if (!reEnable) settingsState.originalDarkMode = settingsState.DarkMode
settingsState.DarkMode = theme.forceDark
}
// Apply custom CSS
applyCustomCSS(CustomCSS);
// Apply custom images
CustomImages.forEach((image) => {
const imageUrl = URL.createObjectURL(image.blob);
document.documentElement.style.setProperty('--' + image.variableName, `url(${imageUrl})`);
});
};