99 getFiles
1010} from "./font" ;
1111import { callTypeX , showReloadAnimation } from "./popup" ;
12+ import { defaultFonts } from "./recursive-fonts.js" ;
1213
1314const localFonts : Record < string , FontFile > = { } ;
1415
@@ -308,6 +309,7 @@ async function getFont(id: string): Promise<Font | null> {
308309 console . error ( "Couldn't find font with ID" , id ) ;
309310 return null ;
310311 }
312+ await updateFont ( font ) ;
311313 return font ;
312314}
313315
@@ -324,6 +326,11 @@ async function applyNamedInstance(e: Event) {
324326
325327 font . inherit = sel . value == "--inherit--" ;
326328
329+ sliders . querySelectorAll ( ".variable-slider" ) . forEach ( slider => {
330+ let input = slider . querySelector ( "input" ) ;
331+ input . disabled = font . inherit ;
332+ } ) ;
333+
327334 if ( font . inherit ) {
328335 sliders . classList . add ( "mute" ) ;
329336 await updateFont ( font ) ;
@@ -357,6 +364,10 @@ async function addVariableSliders(font: Font, el: HTMLElement) {
357364 }
358365 container . classList . add ( "show" ) ;
359366 }
367+ // If we start with inherit, we start muted
368+ if ( font . inherit ) {
369+ container . classList . add ( "mute" ) ;
370+ }
360371}
361372
362373function addSlider ( font : Font , axis : Axis , parent : HTMLElement ) {
@@ -369,6 +380,8 @@ function addSlider(font: Font, axis: Axis, parent: HTMLElement) {
369380 const label : HTMLLabelElement = el . querySelector ( "label" ) ;
370381 const value : HTMLSpanElement = el . querySelector ( ".slider-value" ) ;
371382
383+ input . disabled = font . inherit ;
384+
372385 label . innerText = axis . name ;
373386
374387 input . name = `var-${ axis . id } ` ;
@@ -415,7 +428,24 @@ function unhighlight(e: Event) {
415428 e . stopPropagation ( ) ;
416429}
417430
431+ async function setStorageKeyIfNotFound ( key : string , defaultValue : Font [ ] ) {
432+ try {
433+ const result = await chrome . storage . local . get ( key ) ;
434+ if ( result [ key ] === undefined ) {
435+ // Value not found, set it
436+ await chrome . storage . local . set ( { [ key ] : defaultValue } ) ;
437+ console . log ( `${ key } set to:` , defaultValue ) ;
438+ } else {
439+ // Value already exists
440+ console . log ( `${ key } already exists with value:` , result [ key ] ) ;
441+ }
442+ } catch ( error ) {
443+ console . error ( "Error accessing chrome.storage.local:" , error ) ;
444+ }
445+ }
446+
418447async function updateFont ( font : Font ) {
448+ setStorageKeyIfNotFound ( "fonts" , defaultFonts ) ;
419449 let { fonts } = await chrome . storage . local . get ( "fonts" ) ;
420450 let fontId = font . id ;
421451 fonts = fonts . map ( ( f : Font ) => ( f . id === fontId ? font : f ) ) ;
0 commit comments