@@ -14,7 +14,7 @@ import {
1414 Upload ,
1515 X ,
1616} from "lucide-react" ;
17- import { useCallback , useEffect , useRef , useState } from "react" ;
17+ import { useCallback , useMemo , useRef , useState } from "react" ;
1818import { toast } from "sonner" ;
1919import {
2020 Accordion ,
@@ -34,11 +34,11 @@ import { Slider } from "@/components/ui/slider";
3434import { Switch } from "@/components/ui/switch" ;
3535import { Tabs , TabsContent , TabsList , TabsTrigger } from "@/components/ui/tabs" ;
3636import { useScopedT } from "@/contexts/I18nContext" ;
37- import { getAssetPath } from "@/lib/assetPath" ;
3837import { WEBCAM_LAYOUT_PRESETS } from "@/lib/compositeLayout" ;
3938import type { ExportFormat , ExportQuality , GifFrameRate , GifSizePreset } from "@/lib/exporter" ;
4039import { GIF_FRAME_RATES , GIF_SIZE_PRESETS } from "@/lib/exporter" ;
4140import { cn } from "@/lib/utils" ;
41+ import { resolveImageWallpaperUrl , WALLPAPER_PATHS } from "@/lib/wallpaper" ;
4242import { type AspectRatio , isPortraitAspectRatio } from "@/utils/aspectRatioUtils" ;
4343import { getTestId } from "@/utils/getTestId" ;
4444import { AnnotationSettingsPanel } from "./AnnotationSettingsPanel" ;
@@ -123,11 +123,6 @@ function CustomSpeedInput({
123123 ) ;
124124}
125125
126- const WALLPAPER_COUNT = 18 ;
127- const WALLPAPER_RELATIVE = Array . from (
128- { length : WALLPAPER_COUNT } ,
129- ( _ , i ) => `wallpapers/wallpaper${ i + 1 } .jpg` ,
130- ) ;
131126const GRADIENTS = [
132127 "linear-gradient( 111.6deg, rgba(114,167,232,1) 9.4%, rgba(253,129,82,1) 43.9%, rgba(253,129,82,1) 54.8%, rgba(249,202,86,1) 86.3% )" ,
133128 "linear-gradient(120deg, #d4fc79 0%, #96e6a1 100%)" ,
@@ -326,24 +321,12 @@ export function SettingsPanel({
326321 onWebcamSizePresetCommit,
327322} : SettingsPanelProps ) {
328323 const t = useScopedT ( "settings" ) ;
329- const [ wallpaperPaths , setWallpaperPaths ] = useState < string [ ] > ( [ ] ) ;
324+ // Resolved URLs are for DOM rendering only (backgroundImage). The canonical
325+ // `/wallpapers/wallpaperN.jpg` form in WALLPAPER_PATHS is what gets persisted
326+ // on click — never the machine-specific file:// URL.
327+ const wallpaperPreviewUrls = useMemo ( ( ) => WALLPAPER_PATHS . map ( resolveImageWallpaperUrl ) , [ ] ) ;
330328 const [ customImages , setCustomImages ] = useState < string [ ] > ( [ ] ) ;
331329 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
332-
333- useEffect ( ( ) => {
334- let mounted = true ;
335- ( async ( ) => {
336- try {
337- const resolved = await Promise . all ( WALLPAPER_RELATIVE . map ( ( p ) => getAssetPath ( p ) ) ) ;
338- if ( mounted ) setWallpaperPaths ( resolved ) ;
339- } catch ( _err ) {
340- if ( mounted ) setWallpaperPaths ( WALLPAPER_RELATIVE . map ( ( p ) => `/${ p } ` ) ) ;
341- }
342- } ) ( ) ;
343- return ( ) => {
344- mounted = false ;
345- } ;
346- } , [ ] ) ;
347330 const colorPalette = [
348331 "#FF0000" ,
349332 "#FFD700" ,
@@ -526,7 +509,7 @@ export function SettingsPanel({
526509 setCustomImages ( ( prev ) => prev . filter ( ( img ) => img !== imageUrl ) ) ;
527510 // If the removed image was selected, clear selection
528511 if ( selected === imageUrl ) {
529- onWallpaperChange ( wallpaperPaths [ 0 ] || WALLPAPER_RELATIVE [ 0 ] ) ;
512+ onWallpaperChange ( WALLPAPER_PATHS [ 0 ] ) ;
530513 }
531514 } ;
532515
@@ -1146,38 +1129,24 @@ export function SettingsPanel({
11461129 ) ;
11471130 } ) }
11481131
1149- { ( wallpaperPaths . length > 0
1150- ? wallpaperPaths
1151- : WALLPAPER_RELATIVE . map ( ( p ) => `/${ p } ` )
1152- ) . map ( ( path ) => {
1153- const isSelected = ( ( ) => {
1154- if ( ! selected ) return false ;
1155- if ( selected === path ) return true ;
1156- try {
1157- const clean = ( s : string ) =>
1158- s . replace ( / ^ f i l e : \/ \/ / , "" ) . replace ( / ^ \/ / , "" ) ;
1159- if ( clean ( selected ) . endsWith ( clean ( path ) ) ) return true ;
1160- if ( clean ( path ) . endsWith ( clean ( selected ) ) ) return true ;
1161- } catch {
1162- // Best-effort comparison; fallback to strict match.
1163- }
1164- return false ;
1165- } ) ( ) ;
1132+ { WALLPAPER_PATHS . map ( ( canonicalPath , i ) => {
1133+ const previewUrl = wallpaperPreviewUrls [ i ] ?? canonicalPath ;
1134+ const isSelected = selected === canonicalPath ;
11661135 return (
11671136 < div
1168- key = { path }
1137+ key = { canonicalPath }
11691138 className = { cn (
11701139 "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 shadow-sm" ,
11711140 isSelected
11721141 ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
11731142 : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5" ,
11741143 ) }
11751144 style = { {
1176- backgroundImage : `url(${ path } )` ,
1145+ backgroundImage : `url(${ previewUrl } )` ,
11771146 backgroundSize : "cover" ,
11781147 backgroundPosition : "center" ,
11791148 } }
1180- onClick = { ( ) => onWallpaperChange ( path ) }
1149+ onClick = { ( ) => onWallpaperChange ( canonicalPath ) }
11811150 role = "button"
11821151 />
11831152 ) ;
0 commit comments