1- import { Component , Show , createMemo , createResource , onMount , type JSX } from "solid-js"
1+ import { Component , Show , createMemo , createResource , type JSX } from "solid-js"
22import { createStore } from "solid-js/store"
33import { Button } from "@opencode-ai/ui/button"
44import { Icon } from "@opencode-ai/ui/icon"
55import { Select } from "@opencode-ai/ui/select"
66import { Switch } from "@opencode-ai/ui/switch"
77import { Tooltip } from "@opencode-ai/ui/tooltip"
8- import { useTheme , type ColorScheme } from "@opencode-ai/ui/theme/context "
8+ import { useTheme , type ColorScheme } from "@opencode-ai/ui/theme"
99import { showToast } from "@opencode-ai/ui/toast"
1010import { useLanguage } from "@/context/language"
1111import { usePlatform } from "@/context/platform"
1212import { useSettings , monoFontFamily } from "@/context/settings"
13- import { playSoundById , SOUND_OPTIONS } from "@/utils/sound"
13+ import { playSound , SOUND_OPTIONS } from "@/utils/sound"
1414import { Link } from "./link"
1515import { SettingsList } from "./settings-list"
1616
1717let demoSoundState = {
1818 cleanup : undefined as ( ( ) => void ) | undefined ,
1919 timeout : undefined as NodeJS . Timeout | undefined ,
20- run : 0 ,
21- }
22-
23- type ThemeOption = {
24- id : string
25- name : string
26- }
27-
28- let font : Promise < typeof import ( "@opencode-ai/ui/font-loader" ) > | undefined
29-
30- function loadFont ( ) {
31- font ??= import ( "@opencode-ai/ui/font-loader" )
32- return font
3320}
3421
3522// To prevent audio from overlapping/playing very quickly when navigating the settings menus,
3623// delay the playback by 100ms during quick selection changes and pause existing sounds.
3724const stopDemoSound = ( ) => {
38- demoSoundState . run += 1
3925 if ( demoSoundState . cleanup ) {
4026 demoSoundState . cleanup ( )
4127 }
4228 clearTimeout ( demoSoundState . timeout )
4329 demoSoundState . cleanup = undefined
4430}
4531
46- const playDemoSound = ( id : string | undefined ) => {
32+ const playDemoSound = ( src : string | undefined ) => {
4733 stopDemoSound ( )
48- if ( ! id ) return
34+ if ( ! src ) return
4935
50- const run = ++ demoSoundState . run
5136 demoSoundState . timeout = setTimeout ( ( ) => {
52- void playSoundById ( id ) . then ( ( cleanup ) => {
53- if ( demoSoundState . run !== run ) {
54- cleanup ?.( )
55- return
56- }
57- demoSoundState . cleanup = cleanup
58- } )
37+ demoSoundState . cleanup = playSound ( src )
5938 } , 100 )
6039}
6140
@@ -65,10 +44,6 @@ export const SettingsGeneral: Component = () => {
6544 const platform = usePlatform ( )
6645 const settings = useSettings ( )
6746
68- onMount ( ( ) => {
69- void theme . loadThemes ( )
70- } )
71-
7247 const [ store , setStore ] = createStore ( {
7348 checking : false ,
7449 } )
@@ -129,7 +104,9 @@ export const SettingsGeneral: Component = () => {
129104 . finally ( ( ) => setStore ( "checking" , false ) )
130105 }
131106
132- const themeOptions = createMemo < ThemeOption [ ] > ( ( ) => theme . ids ( ) . map ( ( id ) => ( { id, name : theme . name ( id ) } ) ) )
107+ const themeOptions = createMemo ( ( ) =>
108+ Object . entries ( theme . themes ( ) ) . map ( ( [ id , def ] ) => ( { id, name : def . name ?? id } ) ) ,
109+ )
133110
134111 const colorSchemeOptions = createMemo ( ( ) : { value : ColorScheme ; label : string } [ ] => [
135112 { value : "system" , label : language . t ( "theme.scheme.system" ) } ,
@@ -166,7 +143,7 @@ export const SettingsGeneral: Component = () => {
166143 ] as const
167144 const fontOptionsList = [ ...fontOptions ]
168145
169- const noneSound = { id : "none" , label : "sound.option.none" } as const
146+ const noneSound = { id : "none" , label : "sound.option.none" , src : undefined } as const
170147 const soundOptions = [ noneSound , ...SOUND_OPTIONS ]
171148
172149 const soundSelectProps = (
@@ -181,7 +158,7 @@ export const SettingsGeneral: Component = () => {
181158 label : ( o : ( typeof soundOptions ) [ number ] ) => language . t ( o . label ) ,
182159 onHighlight : ( option : ( typeof soundOptions ) [ number ] | undefined ) => {
183160 if ( ! option ) return
184- playDemoSound ( option . id === "none" ? undefined : option . id )
161+ playDemoSound ( option . src )
185162 } ,
186163 onSelect : ( option : ( typeof soundOptions ) [ number ] | undefined ) => {
187164 if ( ! option ) return
@@ -192,7 +169,7 @@ export const SettingsGeneral: Component = () => {
192169 }
193170 setEnabled ( true )
194171 set ( option . id )
195- playDemoSound ( option . id )
172+ playDemoSound ( option . src )
196173 } ,
197174 variant : "secondary" as const ,
198175 size : "small" as const ,
@@ -344,9 +321,6 @@ export const SettingsGeneral: Component = () => {
344321 current = { fontOptionsList . find ( ( o ) => o . value === settings . appearance . font ( ) ) }
345322 value = { ( o ) => o . value }
346323 label = { ( o ) => language . t ( o . label ) }
347- onHighlight = { ( option ) => {
348- void loadFont ( ) . then ( ( x ) => x . ensureMonoFont ( option ?. value ) )
349- } }
350324 onSelect = { ( option ) => option && settings . appearance . setFont ( option . value ) }
351325 variant = "secondary"
352326 size = "small"
0 commit comments