@@ -33,6 +33,7 @@ import { migrateConfig } from "./utils/config";
3333import { roundTo1 } from "@monkeytype/util/numbers" ;
3434import { getDefaultConfig } from "./constants/default-config" ;
3535import { parseWithSchema as parseJsonWithSchema } from "@monkeytype/util/json" ;
36+ import * as TestState from "./test/test-state" ;
3637
3738const configLS = new LocalStorageWithSchema ( {
3839 key : "config" ,
@@ -91,8 +92,20 @@ export function saveFullConfigToLocalStorage(noDbCheck = false): void {
9192 ConfigEvent . dispatch ( "saveToLocalStorage" , stringified ) ;
9293}
9394
95+ function isConfigChangeBlocked ( ) : boolean {
96+ if ( TestState . isActive && config . funbox . includes ( "no_quit" ) ) {
97+ Notifications . add ( "No quit funbox is active. Please finish the test." , 0 , {
98+ important : true ,
99+ } ) ;
100+ return true ;
101+ }
102+ return false ;
103+ }
104+
94105//numbers
95106export function setNumbers ( numb : boolean , nosave ?: boolean ) : boolean {
107+ if ( isConfigChangeBlocked ( ) ) return false ;
108+
96109 if ( ! isConfigValueValidBoolean ( "numbers" , numb ) ) return false ;
97110
98111 if ( ! canSetConfigWithCurrentFunboxes ( "numbers" , numb , config . funbox ) ) {
@@ -111,6 +124,8 @@ export function setNumbers(numb: boolean, nosave?: boolean): boolean {
111124
112125//punctuation
113126export function setPunctuation ( punc : boolean , nosave ?: boolean ) : boolean {
127+ if ( isConfigChangeBlocked ( ) ) return false ;
128+
114129 if ( ! isConfigValueValidBoolean ( "punctuation" , punc ) ) return false ;
115130
116131 if ( ! canSetConfigWithCurrentFunboxes ( "punctuation" , punc , config . funbox ) ) {
@@ -128,6 +143,8 @@ export function setPunctuation(punc: boolean, nosave?: boolean): boolean {
128143}
129144
130145export function setMode ( mode : Mode , nosave ?: boolean ) : boolean {
146+ if ( isConfigChangeBlocked ( ) ) return false ;
147+
131148 if ( ! isConfigValueValid ( "mode" , mode , ModeSchema ) ) {
132149 return false ;
133150 }
@@ -224,6 +241,8 @@ export function setDifficulty(
224241 diff : ConfigSchemas . Difficulty ,
225242 nosave ?: boolean
226243) : boolean {
244+ if ( isConfigChangeBlocked ( ) ) return false ;
245+
227246 if ( ! isConfigValueValid ( "difficulty" , diff , ConfigSchemas . DifficultySchema ) ) {
228247 return false ;
229248 }
@@ -260,6 +279,8 @@ export function setFunbox(
260279 funbox : ConfigSchemas . Funbox ,
261280 nosave ?: boolean
262281) : boolean {
282+ if ( isConfigChangeBlocked ( ) ) return false ;
283+
263284 if ( ! isConfigValueValid ( "funbox" , funbox , ConfigSchemas . FunboxSchema ) )
264285 return false ;
265286
@@ -277,6 +298,8 @@ export function setFunbox(
277298}
278299
279300export function toggleFunbox ( funbox : FunboxName , nosave ?: boolean ) : boolean {
301+ if ( isConfigChangeBlocked ( ) ) return false ;
302+
280303 if ( ! canSetFunboxWithConfig ( funbox , config ) ) {
281304 return false ;
282305 }
@@ -346,6 +369,8 @@ export function setStopOnError(
346369 soe : ConfigSchemas . StopOnError ,
347370 nosave ?: boolean
348371) : boolean {
372+ if ( isConfigChangeBlocked ( ) ) return false ;
373+
349374 if (
350375 ! isConfigValueValid ( "stop on error" , soe , ConfigSchemas . StopOnErrorSchema )
351376 ) {
@@ -484,6 +509,8 @@ export function setMinWpm(
484509 minwpm : ConfigSchemas . MinimumWordsPerMinute ,
485510 nosave ?: boolean
486511) : boolean {
512+ if ( isConfigChangeBlocked ( ) ) return false ;
513+
487514 if (
488515 ! isConfigValueValid (
489516 "min speed" ,
@@ -505,6 +532,8 @@ export function setMinWpmCustomSpeed(
505532 val : ConfigSchemas . MinWpmCustomSpeed ,
506533 nosave ?: boolean
507534) : boolean {
535+ if ( isConfigChangeBlocked ( ) ) return false ;
536+
508537 if (
509538 ! isConfigValueValid (
510539 "min speed custom" ,
@@ -527,6 +556,8 @@ export function setMinAcc(
527556 min : ConfigSchemas . MinimumAccuracy ,
528557 nosave ?: boolean
529558) : boolean {
559+ if ( isConfigChangeBlocked ( ) ) return false ;
560+
530561 if ( ! isConfigValueValid ( "min acc" , min , ConfigSchemas . MinimumAccuracySchema ) )
531562 return false ;
532563
@@ -541,6 +572,8 @@ export function setMinAccCustom(
541572 val : ConfigSchemas . MinimumAccuracyCustom ,
542573 nosave ?: boolean
543574) : boolean {
575+ if ( isConfigChangeBlocked ( ) ) return false ;
576+
544577 //migrate legacy configs
545578 if ( val > 100 ) val = 100 ;
546579 if (
@@ -564,6 +597,8 @@ export function setMinBurst(
564597 min : ConfigSchemas . MinimumBurst ,
565598 nosave ?: boolean
566599) : boolean {
600+ if ( isConfigChangeBlocked ( ) ) return false ;
601+
567602 if ( ! isConfigValueValid ( "min burst" , min , ConfigSchemas . MinimumBurstSchema ) ) {
568603 return false ;
569604 }
@@ -579,6 +614,8 @@ export function setMinBurstCustomSpeed(
579614 val : ConfigSchemas . MinimumBurstCustomSpeed ,
580615 nosave ?: boolean
581616) : boolean {
617+ if ( isConfigChangeBlocked ( ) ) return false ;
618+
582619 if (
583620 ! isConfigValueValid (
584621 "min burst custom speed" ,
@@ -732,6 +769,8 @@ export function setColorfulMode(extra: boolean, nosave?: boolean): boolean {
732769
733770//strict space
734771export function setStrictSpace ( val : boolean , nosave ?: boolean ) : boolean {
772+ if ( isConfigChangeBlocked ( ) ) return false ;
773+
735774 if ( ! isConfigValueValidBoolean ( "strict space" , val ) ) return false ;
736775
737776 config . strictSpace = val ;
@@ -1087,6 +1126,8 @@ export function setTimeConfig(
10871126 time : ConfigSchemas . TimeConfig ,
10881127 nosave ?: boolean
10891128) : boolean {
1129+ if ( isConfigChangeBlocked ( ) ) return false ;
1130+
10901131 time = isNaN ( time ) || time < 0 ? getDefaultConfig ( ) . time : time ;
10911132 if ( ! isConfigValueValid ( "time" , time , ConfigSchemas . TimeConfigSchema ) )
10921133 return false ;
@@ -1107,6 +1148,8 @@ export function setQuoteLength(
11071148 nosave ?: boolean ,
11081149 multipleMode ?: boolean
11091150) : boolean {
1151+ if ( isConfigChangeBlocked ( ) ) return false ;
1152+
11101153 if ( Array . isArray ( len ) ) {
11111154 if (
11121155 ! isConfigValueValid (
@@ -1159,6 +1202,8 @@ export function setWordCount(
11591202 wordCount : ConfigSchemas . WordCount ,
11601203 nosave ?: boolean
11611204) : boolean {
1205+ if ( isConfigChangeBlocked ( ) ) return false ;
1206+
11621207 wordCount =
11631208 wordCount < 0 || wordCount > 100000 ? getDefaultConfig ( ) . words : wordCount ;
11641209
@@ -1501,6 +1546,8 @@ export function setRandomTheme(
15011546}
15021547
15031548export function setBritishEnglish ( val : boolean , nosave ?: boolean ) : boolean {
1549+ if ( isConfigChangeBlocked ( ) ) return false ;
1550+
15041551 if ( ! isConfigValueValidBoolean ( "british english" , val ) ) return false ;
15051552
15061553 if ( ! val ) {
@@ -1514,6 +1561,8 @@ export function setBritishEnglish(val: boolean, nosave?: boolean): boolean {
15141561}
15151562
15161563export function setLazyMode ( val : boolean , nosave ?: boolean ) : boolean {
1564+ if ( isConfigChangeBlocked ( ) ) return false ;
1565+
15171566 if ( ! isConfigValueValidBoolean ( "lazy mode" , val ) ) return false ;
15181567
15191568 if ( ! val ) {
@@ -1566,6 +1615,8 @@ export function setCustomThemeColors(
15661615}
15671616
15681617export function setLanguage ( language : Language , nosave ?: boolean ) : boolean {
1618+ if ( isConfigChangeBlocked ( ) ) return false ;
1619+
15691620 if ( ! isConfigValueValid ( "language" , language , LanguageSchema ) ) return false ;
15701621
15711622 config . language = language ;
@@ -1743,6 +1794,8 @@ export function setLayout(
17431794 layout : ConfigSchemas . Layout ,
17441795 nosave ?: boolean
17451796) : boolean {
1797+ if ( isConfigChangeBlocked ( ) ) return false ;
1798+
17461799 if ( ! isConfigValueValid ( "layout" , layout , ConfigSchemas . LayoutSchema ) )
17471800 return false ;
17481801
@@ -1850,6 +1903,8 @@ export function setCustomLayoutfluid(
18501903 value : ConfigSchemas . CustomLayoutFluid ,
18511904 nosave ?: boolean
18521905) : boolean {
1906+ if ( isConfigChangeBlocked ( ) ) return false ;
1907+
18531908 // Remove duplicates
18541909 const deduped = Array . from ( new Set ( value ) ) ;
18551910 if (
@@ -1873,6 +1928,8 @@ export function setCustomPolyglot(
18731928 value : ConfigSchemas . CustomPolyglot ,
18741929 nosave ?: boolean
18751930) : boolean {
1931+ if ( isConfigChangeBlocked ( ) ) return false ;
1932+
18761933 // remove duplicates
18771934 const deduped = Array . from ( new Set ( value ) ) ;
18781935 if (
0 commit comments