mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: add force theme option to custom themes
This commit is contained in:
@@ -4,7 +4,7 @@ import ColorPicker from 'react-best-gradient-color-picker';
|
|||||||
import Accordion from '../components/Accordian';
|
import Accordion from '../components/Accordian';
|
||||||
import Switch from '../components/Switch';
|
import Switch from '../components/Switch';
|
||||||
import { sendThemeUpdate } from '../hooks/ThemeManagment';
|
import { sendThemeUpdate } from '../hooks/ThemeManagment';
|
||||||
import { PlusIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
import { MoonIcon, PlusIcon, SunIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { CustomTheme, CustomThemeBase64 } from '../types/CustomThemes';
|
import { CustomTheme, CustomThemeBase64 } from '../types/CustomThemes';
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
@@ -23,6 +23,7 @@ function ThemeCreator() {
|
|||||||
coverImage: null,
|
coverImage: null,
|
||||||
isEditable: true,
|
isEditable: true,
|
||||||
hideThemeName: false,
|
hideThemeName: false,
|
||||||
|
forceDark: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -244,6 +245,29 @@ function ThemeCreator() {
|
|||||||
|
|
||||||
<Divider /> */}
|
<Divider /> */}
|
||||||
|
|
||||||
|
<div className='flex items-center justify-between'>
|
||||||
|
<div>
|
||||||
|
<div className='pr-2 text-sm font-semibold'>Force Theme</div>
|
||||||
|
<div className='pr-2 text-[11px]'>Force users to use either dark or light mode</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Switch state={theme.forceDark == undefined ? false : true} onChange={value => setTheme({ ...theme, forceDark: value ? false : undefined })} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{ theme.forceDark != undefined &&
|
||||||
|
<div className='flex items-center justify-between pt-4'>
|
||||||
|
<div>
|
||||||
|
<div className='pr-2 text-sm font-semibold'>Force {theme.forceDark ? 'Dark' : 'Light'} Mode</div>
|
||||||
|
<div className='pr-2 text-[11px]'>Force users to use {theme.forceDark ? 'dark' : 'light'} mode</div>
|
||||||
|
</div>
|
||||||
|
<button className='flex items-center justify-center p-2 transition rounded-lg bg-zinc-100 dark:bg-zinc-700' onClick={() => setTheme({ ...theme, forceDark: !theme.forceDark })}>
|
||||||
|
{theme.forceDark ? <MoonIcon className='w-6 h-6' /> : <SunIcon className='w-6 h-6' />}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<Divider />
|
||||||
|
|
||||||
<Accordion defaultOpened title='Default Theme Colour'>
|
<Accordion defaultOpened title='Default Theme Colour'>
|
||||||
<div className='p-2 mt-2 bg-white rounded-lg w-fit dark:bg-zinc-900'>
|
<div className='p-2 mt-2 bg-white rounded-lg w-fit dark:bg-zinc-900'>
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export type CustomTheme = {
|
|||||||
hideThemeName: boolean;
|
hideThemeName: boolean;
|
||||||
webURL?: string;
|
webURL?: string;
|
||||||
selectedColor?: string;
|
selectedColor?: string;
|
||||||
|
forceDark?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DownloadedTheme = CustomTheme & {
|
export type DownloadedTheme = CustomTheme & {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { CustomImage, CustomTheme } from '../../../interface/types/CustomThemes';
|
import { CustomImage, CustomTheme } from '../../../interface/types/CustomThemes';
|
||||||
|
import { settingsState } from '../../utils/listeners/SettingsState';
|
||||||
import { applyCustomCSS } from './Themes';
|
import { applyCustomCSS } from './Themes';
|
||||||
|
|
||||||
|
|
||||||
@@ -8,6 +9,10 @@ export const applyTheme = async (theme: CustomTheme) => {
|
|||||||
|
|
||||||
if (theme?.CustomCSS) CustomCSS = theme.CustomCSS;
|
if (theme?.CustomCSS) CustomCSS = theme.CustomCSS;
|
||||||
if (theme?.CustomImages) CustomImages = theme.CustomImages;
|
if (theme?.CustomImages) CustomImages = theme.CustomImages;
|
||||||
|
if (theme?.forceDark) {
|
||||||
|
settingsState.originalDarkMode = settingsState.DarkMode
|
||||||
|
settingsState.DarkMode = theme.forceDark
|
||||||
|
}
|
||||||
|
|
||||||
// Apply custom CSS
|
// Apply custom CSS
|
||||||
applyCustomCSS(CustomCSS);
|
applyCustomCSS(CustomCSS);
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ export const removeTheme = async (theme: CustomTheme) => {
|
|||||||
settingsState.selectedColor = settingsState.originalSelectedColor
|
settingsState.selectedColor = settingsState.originalSelectedColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settingsState.originalDarkMode !== undefined) {
|
||||||
|
settingsState.DarkMode = settingsState.originalDarkMode
|
||||||
|
settingsState.originalDarkMode = undefined
|
||||||
|
}
|
||||||
|
|
||||||
// Remove custom images
|
// Remove custom images
|
||||||
const customImageVariables = theme.CustomImages.map((image) => image.variableName);
|
const customImageVariables = theme.CustomImages.map((image) => image.variableName);
|
||||||
customImageVariables.forEach((variableName) => {
|
customImageVariables.forEach((variableName) => {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export interface SettingsState {
|
|||||||
animations: boolean;
|
animations: boolean;
|
||||||
defaultPage: string;
|
defaultPage: string;
|
||||||
devMode?: boolean;
|
devMode?: boolean;
|
||||||
|
originalDarkMode?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ToggleItem {
|
interface ToggleItem {
|
||||||
|
|||||||
Reference in New Issue
Block a user