@@ -12,6 +12,7 @@ import * as Loader from "../elements/loader";
1212import { debounce } from "throttle-debounce" ;
1313import { ThemeName } from "@monkeytype/schemas/configs" ;
1414import { ThemesList } from "../constants/themes" ;
15+ import fileStorage from "../utils/file-storage" ;
1516
1617export let randomTheme : ThemeName | string | null = null ;
1718let isPreviewingTheme = false ;
@@ -376,12 +377,22 @@ function applyCustomBackgroundSize(): void {
376377 }
377378}
378379
379- function applyCustomBackground ( ) : void {
380+ export async function applyCustomBackground ( ) : Promise < void > {
380381 // $(".customBackground").css({
381382 // backgroundImage: `url(${Config.customBackground})`,
382383 // backgroundAttachment: "fixed",
383384 // });
384- if ( Config . customBackground === "" ) {
385+
386+ let backgroundUrl = Config . customBackground ;
387+
388+ //if there is a localBackgroundFile available, use it.
389+ const localBackgroundFile = await fileStorage . getFile ( "LocalBackgroundFile" ) ;
390+
391+ if ( localBackgroundFile !== undefined ) {
392+ backgroundUrl = localBackgroundFile ;
393+ }
394+
395+ if ( backgroundUrl === "" ) {
385396 $ ( "#words" ) . removeClass ( "noErrorBorder" ) ;
386397 $ ( "#resultWordsHistory" ) . removeClass ( "noErrorBorder" ) ;
387398 $ ( ".customBackground img" ) . remove ( ) ;
@@ -392,7 +403,8 @@ function applyCustomBackground(): void {
392403 //use setAttribute for possible unsafe customBackground value
393404 const container = document . querySelector ( ".customBackground" ) ;
394405 const img = document . createElement ( "img" ) ;
395- img . setAttribute ( "src" , Config . customBackground ) ;
406+
407+ img . setAttribute ( "src" , backgroundUrl ) ;
396408 img . setAttribute (
397409 "onError" ,
398410 "javascript:this.style.display='none'; window.dispatchEvent(new Event('customBackgroundFailed'))"
@@ -439,7 +451,7 @@ ConfigEvent.subscribe(async (eventKey, eventValue, nosave) => {
439451 await set ( Config . theme ) ;
440452 }
441453 }
442- applyCustomBackground ( ) ;
454+ await applyCustomBackground ( ) ;
443455 }
444456
445457 // this is here to prevent calling set / preview multiple times during a full config loading
@@ -461,7 +473,8 @@ ConfigEvent.subscribe(async (eventKey, eventValue, nosave) => {
461473 await set ( eventValue as string ) ;
462474 }
463475 if ( eventKey === "randomTheme" && eventValue === "off" ) await clearRandom ( ) ;
464- if ( eventKey === "customBackground" ) applyCustomBackground ( ) ;
476+ if ( eventKey === "customBackground" ) await applyCustomBackground ( ) ;
477+
465478 if ( eventKey === "customBackgroundSize" ) applyCustomBackgroundSize ( ) ;
466479 if ( eventKey === "autoSwitchTheme" ) {
467480 if ( eventValue as boolean ) {
0 commit comments