okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a1cc285fa
main
1import { tr } from '../lib/i18n' ; 2/** Settings panels share the existing preference controls. */ 3import { useRef , type ReactNode } from 'react' ; 4import { Btn , Field , Icon , Select , type IconName } from '../components/ui' ; 5import { Brand } from '../components/Brand' ; 6import { SettingsModels } from '../components/SettingsModels' ; 7import { SettingsTools } from '../components/SettingsTools' ; 8import { SettingsStorage } from '../components/SettingsStorage' ; 9import { PrivacyNotes } from '../components/PrivacyNotes' ; 10import { AboutVersions , SettingsUpdates } from '../components/SettingsUpdates' ; 11import { NativeOperations } from '../components/NativeOperations' ; 12import { FontChoice } from '../components/FontChoice' ; 13import { ElectricityPrice } from '../components/ElectricityPrice' ; 14import { ApprovalNotifySetting , DoneSoundSetting , PortSetting , TraySetting , useShellState } from '../components/ShellSettings' ; 15import { LANGUAGES } from '../lib/i18n' ; 16import { setLanguage , setWhileBusy } from '../lib/store' ; 17import { CONTENT_FONT_RANGE , setContentFontSize , setDensity , setFocus , setMotion , setShortcuts , setTheme , setTransparency , setUiScale , UI_SCALES , useStore , setSettingsSection } from '../lib/store' ; 18const PANELS = [{ name :'Appearance' , icon :'sun' , sections :[ 'General' , 'Reading & focus' ] }, { name :'Models' , icon :'models' , sections :[] }, { name :'Tools' , icon :'tool' , sections :[] }, { name :'Storage' , icon :'disk' , sections :[ 'Storage' ] }, { name :'Engine' , icon :'engine' , sections :[] }, { name :'About' , icon :'info' , sections :[ 'About' , 'Update' , 'Privacy' ] }] as const ; 19export function SettingsScreen () { 20const prefs = useStore ( s => s ); 21const [ shell , saveShell ] = useShellState (); 22const active = prefs . settingsSection ; 23const scrollRef = useRef < HTMLDivElement >( null ); 24const fields :{ 25section :string ; 26label :string ; 27hint :string ; 28aliases ?:string ; 29control :ReactNode ; 30}[] = [ 31{ section :'General' , label :'Language' , hint :'Choose the language used throughout Strata.' , control :< Select translateLabels = { false } ariaLabel = { tr ( "Language" )} value = { prefs . language } options = {[ ...LANGUAGES ]} onChange = { value => setLanguage ( value as typeof prefs . language )}/> }, 32{ section :'General' , label :'While an answer is being written' , hint :'What Enter does when you send a message while the assistant is still answering.' , aliases :'interrupt wait queue interject busy send after stop enter' , control :< Select value = { prefs . whileBusy } ariaLabel = { tr ( "While an answer is being written" )} options = {[{ value :'wait' , label :'Wait for the answer' }, { value :'queue' , label :'Send after the answer' }, { value :'interject' , label :'Interrupt the answer' }]} onChange = { value => setWhileBusy ( value as typeof prefs . whileBusy )}/> }, 33{ section :'General' , label :'Sound when work finishes' , hint :'Plays a short sound when an answer or task that took a while is finished, or when Strata is in the background.' , aliases :'audio chime done complete notification' , control :< DoneSoundSetting /> }, 34{ section :'General' , label :'Notify me when Strata needs an answer' , hint :'In Manual mode, shows a desktop notification when the assistant waits for your approval and Strata is in the background.' , aliases :'approval permission alert notification manual' , control :< ApprovalNotifySetting /> }, 35 ...( shell ?. tray ?[{ section :'General' , label :'Minimise to tray' , hint :'Closing the window keeps Strata running in the tray, next to the clock. Choose Quit in the tray menu to stop it. Applies the next time Strata starts.' , aliases :'tray background close notification area' , control :< TraySetting shell = { shell } save = { saveShell } /> }] :[]), 36 ...( shell ?. desktop ?[{ section :'General' , label :'App port' , hint :'The port Strata’s window and local address use. Leave it empty to let Strata choose (47831 when it is free). Applies the next time Strata starts.' , aliases :'network address 47831 localhost api' , control :< PortSetting shell = { shell } save = { saveShell } /> }] :[]), 37{ section :'General' , label :'Electricity price' , hint :'Price of one kilowatt-hour. The Monitor then shows what your graphics card has cost since Strata started. Leave it empty to hide the cost.' , aliases :'cost power energy kwh currency money' , control :< ElectricityPrice /> }, 38{ section :'Reading & focus' , label :'Font' , hint :'Choose an installed font for the interface and conversations.' , control :< FontChoice /> }, 39{ section :'General' , label :'Keyboard shortcuts' , hint :'Set the key combinations that feel natural to you.' , aliases :'command keys hotkeys' , control :< Btn size = "sm" onClick = {() => setShortcuts ( true )}>{ tr ( "Edit shortcuts" )}</ Btn > }, 40{ section :'Reading & focus' , label :'Appearance' , hint :'System follows your computer by default.' , aliases :'theme light dark system automatic' , control :< Select value = { prefs . theme } ariaLabel = { tr ( "Appearance" )} options = {[{ value :'light' , label :'Light' }, { value :'dark' , label :'Dark' }, { value :'system' , label :'System' }]} onChange = { setTheme }/> }, 41{ section :'Reading & focus' , label :'Reading size' , hint :'Conversation text size. Interface controls stay separate.' , aliases :'font text zoom' , control :< label className = "row" >< input aria-label = { tr ( "Reading text size" )} type = "range" className = "st-slider" min = { CONTENT_FONT_RANGE . min } max = { CONTENT_FONT_RANGE . max } value = { prefs . contentFontSize } onChange = { e => setContentFontSize ( Number ( e . target . value ))}/>< output >{ tr ( prefs . contentFontSize )}{ tr ( " px" )}</ output ></ label > }, 42{ section :'Reading & focus' , label :'Interface size' , hint :'Makes all text, buttons and menus in Strata larger or smaller.' , aliases :'zoom scale font text size bigger smaller 4k 90% 100% 110% 125% 150% 175% 200%' , control :< Select value = { String ( prefs . uiScale )} ariaLabel = { tr ( "Interface size" )} options = { UI_SCALES . map ( v => ({ value :String ( v ), label :` ${ Math . round ( v * 100 )} %` }))} onChange = { v => setUiScale ( Number ( v ))}/> }, 43{ section :'Reading & focus' , label :'Spacing' , hint :'Comfortable spacing by default.' , aliases :'density comfortable compact' , control :< Select value = { prefs . density } ariaLabel = { tr ( "Interface spacing" )} options = {[{ value :'comfortable' , label :'Comfortable' }, { value :'compact' , label :'Compact' }]} onChange = { setDensity }/> }, 44{ section :'Reading & focus' , label :'Motion' , hint :'Reduced motion also disables smooth scrolling.' , aliases :'animation system full reduced' , control :< Select value = { prefs . motion } ariaLabel = { tr ( "Motion" )} options = {[{ value :'system' , label :'Follow system' }, { value :'full' , label :'Full' }, { value :'reduced' , label :'Reduced' }]} onChange = { setMotion }/> }, 45{ section :'Reading & focus' , label :'Transparency' , hint :'Translucent controls or solid surfaces. Text stays opaque.' , aliases :'blur glass liquid opaque translucent' , control :< Select value = { prefs . transparency } ariaLabel = { tr ( "Transparency" )} options = {[{ value :'translucent' , label :'Translucent' }, { value :'opaque' , label :'Opaque' }]} onChange = { setTransparency }/> }, 46{ section :'Reading & focus' , label :'Focus reading' , hint :'Hides navigation in chat. Settings stays open above the conversation.' , aliases :'distraction quiet' , control :< button className = "st-toggle" role = "switch" aria-checked = { prefs . focus } aria-label = { tr ( "Focus reading" )} onClick = {() => setFocus ( ! prefs . focus )}/> }, 47]; 48function activate ( name :typeof PANELS [ number ][ 'name' ]) { 49setSettingsSection ( name ); 50scrollRef . current ?. scrollTo ({ top :0 }); 51} 52return < div className = "settings-layout" > 53< nav className = "settingsindex" role = "tablist" aria-label = { tr ( "Settings sections" )} onKeyDown = { e => { 54if ( ! [ 'ArrowUp' , 'ArrowDown' , 'ArrowLeft' , 'ArrowRight' , 'Home' , 'End' ]. includes ( e . key )) 55return ; 56e . preventDefault (); 57const index = PANELS . findIndex ( p => p . name === active ); 58const next = e . key === 'Home' ?0 :e . key === 'End' ?PANELS . length - 1 :( index + ([ 'ArrowDown' , 'ArrowRight' ]. includes ( e . key ) ?1 :- 1 ) + PANELS . length ) % PANELS . length ; 59activate ( PANELS [ next ]. name ); 60document . getElementById ( `settings-tab- ${ PANELS [ next ]. name } ` )?. focus (); 61}}> 62{ tr ( PANELS . map ( panel => < button key = { panel . name } role = "tab" id = { `settings-tab- ${ panel . name } ` } aria-controls = { `settings-panel- ${ panel . name } ` } aria-selected = { active === panel . name } tabIndex = { active === panel . name ?0 :- 1 } className = "settingsindex__item" onClick = {() => activate ( panel . name )}>< Icon name = { panel . icon as IconName } size = { 17 }/>{ tr ( panel . name )}</ button >))} 63</ nav > 64< div className = "settings-pane" ref = { scrollRef }> 65{ tr ( PANELS . map ( panel => < div key = { panel . name } role = "tabpanel" tabIndex = { 0 } id = { `settings-panel- ${ panel . name } ` } aria-labelledby = { `settings-tab- ${ panel . name } ` } hidden = { active !== panel . name }> 66{ tr ( panel . name === 'Models' ?< SettingsModels /> :panel . name === 'Tools' ?( active === panel . name ?< SettingsTools /> :null ) :panel . name === 'Engine' && active === panel . name ?< div className = "stack stack--lg settings-body" >< section className = "settings-section" >< h2 className = "h3" style = {{ marginBottom :14 }}>{ tr ( "Engine" )}</ h2 >< NativeOperations /></ section ></ div > :active === panel . name ?< div className = "stack stack--lg settings-body" > 67{ tr ( panel . sections . map ( section => < section className = "settings-section" key = { section }> 68< h2 className = "h3" style = {{ marginBottom :14 }}>{ tr ( section )}</ h2 > 69< div className = "st-card st-card--flush" > 70{ tr ( section === 'About' ?< div className = "settings-about-brand" >< Brand variant = "lockup" height = { 28 }/>< AboutVersions /></ div > :null )} 71{ tr ( section === 'Storage' ?< SettingsStorage /> :null )} 72{ tr ( section === 'Privacy' ?< PrivacyNotes /> :null )} 73{ tr ( section === 'Update' ?< SettingsUpdates /> :null )} 74{ tr ( fields . filter ( f => f . section === section ). map ( f => < Field key = { f . label } label = { tr ( f . label )} hint = { tr ( f . hint )}>{ tr ( f . control )}</ Field >))} 75</ div > 76</ section >))} 77</ div > :null )} 78</ div >))} 79</ div > 80</ div >; 81}