import Dropdown from '@/Components/Dropdown/Dropdown' import { DropdownItem } from '@/Components/Dropdown/DropdownItem' import { usePremiumModal } from '@/Hooks/usePremiumModal' import HorizontalSeparator from '@/Components/Shared/HorizontalSeparator' import Switch from '@/Components/Switch/Switch' import { WebApplication } from '@/Application/WebApplication' import { PrefKey, FeatureStatus, naturalSort, PrefDefaults } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent, useEffect, useState } from 'react' import { Subtitle, Title, Text } from '@/Components/Preferences/PreferencesComponents/Content' import PreferencesPane from '../PreferencesComponents/PreferencesPane' import PreferencesGroup from '../PreferencesComponents/PreferencesGroup' import PreferencesSegment from '../PreferencesComponents/PreferencesSegment' import { PremiumFeatureIconName } from '@/Components/Icon/PremiumFeatureIcon' import EditorAppearance from './Appearance/EditorAppearance' import { GetAllThemesUseCase } from '@standardnotes/ui-services' type Props = { application: WebApplication } const Appearance: FunctionComponent = ({ application }) => { const premiumModal = usePremiumModal() const [themeItems, setThemeItems] = useState([]) const [autoLightTheme, setAutoLightTheme] = useState(() => application.getPreference(PrefKey.AutoLightThemeIdentifier, PrefDefaults[PrefKey.AutoLightThemeIdentifier]), ) const [autoDarkTheme, setAutoDarkTheme] = useState(() => application.getPreference(PrefKey.AutoDarkThemeIdentifier, PrefDefaults[PrefKey.AutoDarkThemeIdentifier]), ) const [useDeviceSettings, setUseDeviceSettings] = useState(() => application.getPreference(PrefKey.UseSystemColorScheme, PrefDefaults[PrefKey.UseSystemColorScheme]), ) useEffect(() => { const usecase = new GetAllThemesUseCase(application.items) const { thirdParty, native } = usecase.execute({ excludeLayerable: true }) const dropdownItems: DropdownItem[] = [] dropdownItems.push({ label: 'Default', value: 'Default', }) dropdownItems.push( ...native.map((theme) => { return { label: theme.displayName as string, value: theme.featureIdentifier, icon: application.features.getFeatureStatus(theme.uniqueIdentifier) !== FeatureStatus.Entitled ? PremiumFeatureIconName : undefined, } }), ) dropdownItems.push( ...thirdParty.map((theme) => { return { label: theme.displayName, value: theme.featureIdentifier, } }), ) setThemeItems(naturalSort(dropdownItems, 'label')) }, [application]) const toggleUseDeviceSettings = () => { application.setPreference(PrefKey.UseSystemColorScheme, !useDeviceSettings).catch(console.error) if (!application.getPreference(PrefKey.AutoLightThemeIdentifier)) { application.setPreference(PrefKey.AutoLightThemeIdentifier, autoLightTheme).catch(console.error) } if (!application.getPreference(PrefKey.AutoDarkThemeIdentifier)) { application.setPreference(PrefKey.AutoDarkThemeIdentifier, autoDarkTheme).catch(console.error) } setUseDeviceSettings(!useDeviceSettings) } const changeAutoLightTheme = (value: string) => { const item = themeItems.find((item) => item.value === value) if (item && item.icon === PremiumFeatureIconName) { premiumModal.activate(`${item.label} theme`) return } application.setPreference(PrefKey.AutoLightThemeIdentifier, value).catch(console.error) setAutoLightTheme(value) } const changeAutoDarkTheme = (value: string) => { const item = themeItems.find((item) => item.value === value) if (item && item.icon === PremiumFeatureIconName) { premiumModal.activate(`${item.label} theme`) return } application.setPreference(PrefKey.AutoDarkThemeIdentifier, value).catch(console.error) setAutoDarkTheme(value) } return ( Themes
Use system color scheme Automatically change active theme based on your system settings.
Automatic Light Theme Theme to be used for system light mode:
Automatic Dark Theme Theme to be used for system dark mode:
) } export default observer(Appearance)