import { Component, createMemo, type JSX } from "solid-js" import { Select } from "@opencode-ai/ui/select" import { Switch } from "@opencode-ai/ui/switch" import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme" import { useLanguage } from "@/context/language" import { useSettings, monoFontFamily } from "@/context/settings" import { playSound, SOUND_OPTIONS } from "@/utils/sound" import { Link } from "./link" let demoSoundState = { cleanup: undefined as (() => void) | undefined, timeout: undefined as NodeJS.Timeout | undefined, } // To prevent audio from overlapping/playing very quickly when navigating the settings menus, // delay the playback by 100ms during quick selection changes and pause existing sounds. const playDemoSound = (src: string) => { if (demoSoundState.cleanup) { demoSoundState.cleanup() } clearTimeout(demoSoundState.timeout) demoSoundState.timeout = setTimeout(() => { demoSoundState.cleanup = playSound(src) }, 100) } export const SettingsGeneral: Component = () => { const theme = useTheme() const language = useLanguage() const settings = useSettings() const themeOptions = createMemo(() => Object.entries(theme.themes()).map(([id, def]) => ({ id, name: def.name ?? id })), ) const colorSchemeOptions = createMemo((): { value: ColorScheme; label: string }[] => [ { value: "system", label: language.t("theme.scheme.system") }, { value: "light", label: language.t("theme.scheme.light") }, { value: "dark", label: language.t("theme.scheme.dark") }, ]) const languageOptions = createMemo(() => language.locales.map((locale) => ({ value: locale, label: language.label(locale), })), ) const fontOptions = [ { value: "ibm-plex-mono", label: "font.option.ibmPlexMono" }, { value: "cascadia-code", label: "font.option.cascadiaCode" }, { value: "fira-code", label: "font.option.firaCode" }, { value: "hack", label: "font.option.hack" }, { value: "inconsolata", label: "font.option.inconsolata" }, { value: "intel-one-mono", label: "font.option.intelOneMono" }, { value: "iosevka", label: "font.option.iosevka" }, { value: "jetbrains-mono", label: "font.option.jetbrainsMono" }, { value: "meslo-lgs", label: "font.option.mesloLgs" }, { value: "roboto-mono", label: "font.option.robotoMono" }, { value: "source-code-pro", label: "font.option.sourceCodePro" }, { value: "ubuntu-mono", label: "font.option.ubuntuMono" }, ] as const const fontOptionsList = [...fontOptions] const soundOptions = [...SOUND_OPTIONS] return (
) } interface SettingsRowProps { title: string description: string | JSX.Element children: JSX.Element } const SettingsRow: Component