@@ -20,12 +20,17 @@ let demoSoundState = {
2020
2121// To prevent audio from overlapping/playing very quickly when navigating the settings menus,
2222// delay the playback by 100ms during quick selection changes and pause existing sounds.
23- const playDemoSound = ( src : string ) => {
23+ const stopDemoSound = ( ) => {
2424 if ( demoSoundState . cleanup ) {
2525 demoSoundState . cleanup ( )
2626 }
27-
2827 clearTimeout ( demoSoundState . timeout )
28+ demoSoundState . cleanup = undefined
29+ }
30+
31+ const playDemoSound = ( src : string | undefined ) => {
32+ stopDemoSound ( )
33+ if ( ! src ) return
2934
3035 demoSoundState . timeout = setTimeout ( ( ) => {
3136 demoSoundState . cleanup = playSound ( src )
@@ -132,11 +137,17 @@ export const SettingsGeneral: Component = () => {
132137 ] as const
133138 const fontOptionsList = [ ...fontOptions ]
134139
135- const soundOptions = [ ...SOUND_OPTIONS ]
140+ const noneSound = { id : "none" , label : "sound.option.none" , src : undefined } as const
141+ const soundOptions = [ noneSound , ...SOUND_OPTIONS ]
136142
137- const soundSelectProps = ( current : ( ) => string , set : ( id : string ) => void ) => ( {
143+ const soundSelectProps = (
144+ enabled : ( ) => boolean ,
145+ current : ( ) => string ,
146+ setEnabled : ( value : boolean ) => void ,
147+ set : ( id : string ) => void ,
148+ ) => ( {
138149 options : soundOptions ,
139- current : soundOptions . find ( ( o ) => o . id === current ( ) ) ,
150+ current : enabled ( ) ? ( soundOptions . find ( ( o ) => o . id === current ( ) ) ?? noneSound ) : noneSound ,
140151 value : ( o : ( typeof soundOptions ) [ number ] ) => o . id ,
141152 label : ( o : ( typeof soundOptions ) [ number ] ) => language . t ( o . label ) ,
142153 onHighlight : ( option : ( typeof soundOptions ) [ number ] | undefined ) => {
@@ -145,6 +156,12 @@ export const SettingsGeneral: Component = () => {
145156 } ,
146157 onSelect : ( option : ( typeof soundOptions ) [ number ] | undefined ) => {
147158 if ( ! option ) return
159+ if ( option . id === "none" ) {
160+ setEnabled ( false )
161+ stopDemoSound ( )
162+ return
163+ }
164+ setEnabled ( true )
148165 set ( option . id )
149166 playDemoSound ( option . src )
150167 } ,
@@ -319,66 +336,45 @@ export const SettingsGeneral: Component = () => {
319336 title = { language . t ( "settings.general.sounds.agent.title" ) }
320337 description = { language . t ( "settings.general.sounds.agent.description" ) }
321338 >
322- < div class = "flex items-center gap-2" >
323- < div data-action = "settings-sounds-agent-enabled" >
324- < Switch
325- checked = { settings . sounds . agentEnabled ( ) }
326- onChange = { ( checked ) => settings . sounds . setAgentEnabled ( checked ) }
327- />
328- </ div >
329- < Select
330- disabled = { ! settings . sounds . agentEnabled ( ) }
331- data-action = "settings-sounds-agent"
332- { ...soundSelectProps (
333- ( ) => settings . sounds . agent ( ) ,
334- ( id ) => settings . sounds . setAgent ( id ) ,
335- ) }
336- />
337- </ div >
339+ < Select
340+ data-action = "settings-sounds-agent"
341+ { ...soundSelectProps (
342+ ( ) => settings . sounds . agentEnabled ( ) ,
343+ ( ) => settings . sounds . agent ( ) ,
344+ ( value ) => settings . sounds . setAgentEnabled ( value ) ,
345+ ( id ) => settings . sounds . setAgent ( id ) ,
346+ ) }
347+ />
338348 </ SettingsRow >
339349
340350 < SettingsRow
341351 title = { language . t ( "settings.general.sounds.permissions.title" ) }
342352 description = { language . t ( "settings.general.sounds.permissions.description" ) }
343353 >
344- < div class = "flex items-center gap-2" >
345- < div data-action = "settings-sounds-permissions-enabled" >
346- < Switch
347- checked = { settings . sounds . permissionsEnabled ( ) }
348- onChange = { ( checked ) => settings . sounds . setPermissionsEnabled ( checked ) }
349- />
350- </ div >
351- < Select
352- disabled = { ! settings . sounds . permissionsEnabled ( ) }
353- data-action = "settings-sounds-permissions"
354- { ...soundSelectProps (
355- ( ) => settings . sounds . permissions ( ) ,
356- ( id ) => settings . sounds . setPermissions ( id ) ,
357- ) }
358- />
359- </ div >
354+ < Select
355+ data-action = "settings-sounds-permissions"
356+ { ...soundSelectProps (
357+ ( ) => settings . sounds . permissionsEnabled ( ) ,
358+ ( ) => settings . sounds . permissions ( ) ,
359+ ( value ) => settings . sounds . setPermissionsEnabled ( value ) ,
360+ ( id ) => settings . sounds . setPermissions ( id ) ,
361+ ) }
362+ />
360363 </ SettingsRow >
361364
362365 < SettingsRow
363366 title = { language . t ( "settings.general.sounds.errors.title" ) }
364367 description = { language . t ( "settings.general.sounds.errors.description" ) }
365368 >
366- < div class = "flex items-center gap-2" >
367- < div data-action = "settings-sounds-errors-enabled" >
368- < Switch
369- checked = { settings . sounds . errorsEnabled ( ) }
370- onChange = { ( checked ) => settings . sounds . setErrorsEnabled ( checked ) }
371- />
372- </ div >
373- < Select
374- disabled = { ! settings . sounds . errorsEnabled ( ) }
375- data-action = "settings-sounds-errors"
376- { ...soundSelectProps (
377- ( ) => settings . sounds . errors ( ) ,
378- ( id ) => settings . sounds . setErrors ( id ) ,
379- ) }
380- />
381- </ div >
369+ < Select
370+ data-action = "settings-sounds-errors"
371+ { ...soundSelectProps (
372+ ( ) => settings . sounds . errorsEnabled ( ) ,
373+ ( ) => settings . sounds . errors ( ) ,
374+ ( value ) => settings . sounds . setErrorsEnabled ( value ) ,
375+ ( id ) => settings . sounds . setErrors ( id ) ,
376+ ) }
377+ />
382378 </ SettingsRow >
383379 </ div >
384380 </ div >
0 commit comments