import { AnimatePresence, motion, Variants } from 'motion/react'; import { CSSProperties, memo, ReactNode, useEffect, useLayoutEffect, useRef, useState, } from 'react'; import { useTranslation } from 'react-i18next'; import { useLocation } from 'react-router'; import styles from './full-screen-player.module.css'; import { SONG_TABLE_COLUMNS } from '/@/renderer/components/item-list/item-table-list/default-columns'; import { FullScreenPlayerImage } from '/@/renderer/features/player/components/full-screen-player-image'; import { FullScreenPlayerQueue } from '/@/renderer/features/player/components/full-screen-player-queue'; import { ListConfigMenu } from '/@/renderer/features/shared/components/list-config-menu'; import { useFastAverageColor } from '/@/renderer/hooks'; import { useFullScreenPlayerStore, useFullScreenPlayerStoreActions, useLyricsSettings, usePlayerData, usePlayerSong, useSettingsStore, useSettingsStoreActions, useWindowSettings, } from '/@/renderer/store'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Divider } from '/@/shared/components/divider/divider'; import { Group } from '/@/shared/components/group/group'; import { NumberInput } from '/@/shared/components/number-input/number-input'; import { Option } from '/@/shared/components/option/option'; import { Popover } from '/@/shared/components/popover/popover'; import { Select } from '/@/shared/components/select/select'; import { Slider } from '/@/shared/components/slider/slider'; import { Switch } from '/@/shared/components/switch/switch'; import { useHotkeys } from '/@/shared/hooks/use-hotkeys'; import { ItemListKey, ListDisplayType, Platform } from '/@/shared/types/types'; const mainBackground = 'var(--theme-colors-background)'; const backgroundImageVariants: Variants = { closed: { opacity: 0, transition: { duration: 0.8, ease: 'linear', }, }, initial: { opacity: 0, }, open: (custom) => { const { isOpen } = custom; return { opacity: isOpen ? 1 : 0, transition: { duration: 0.4, ease: 'linear', }, }; }, }; interface BackgroundImageProps { dynamicBackground: boolean | undefined; dynamicIsImage: boolean | undefined; } const BackgroundImage = memo(({ dynamicBackground, dynamicIsImage }: BackgroundImageProps) => { const currentSong = usePlayerSong(); const { nextSong } = usePlayerData(); const [imageState, setImageState] = useState({ bottomImage: nextSong?.imageUrl ? nextSong.imageUrl.replace(/size=\d+/g, 'size=500') : undefined, current: 0, topImage: currentSong?.imageUrl ? currentSong.imageUrl.replace(/size=\d+/g, 'size=500') : undefined, }); const previousSongRef = useRef(currentSong?._uniqueId); const imageStateRef = useRef(imageState); // Keep ref in sync useEffect(() => { imageStateRef.current = imageState; }, [imageState]); // Update images when song changes useEffect(() => { if (currentSong?._uniqueId === previousSongRef.current) { return; } const isTop = imageStateRef.current.current === 0; const currentImageUrl = currentSong?.imageUrl ? currentSong.imageUrl.replace(/size=\d+/g, 'size=500') : undefined; const nextImageUrl = nextSong?.imageUrl ? nextSong.imageUrl.replace(/size=\d+/g, 'size=500') : undefined; setImageState({ bottomImage: isTop ? currentImageUrl : nextImageUrl, current: isTop ? 1 : 0, topImage: isTop ? nextImageUrl : currentImageUrl, }); previousSongRef.current = currentSong?._uniqueId; }, [currentSong?._uniqueId, currentSong?.imageUrl, nextSong?._uniqueId, nextSong?.imageUrl]); if (!dynamicBackground || !dynamicIsImage) { return null; } const getBackgroundImageUrl = ( imageUrl: string | undefined, songId: string | undefined, albumId: string | undefined, ) => { if (!imageUrl || !songId || !albumId) { return imageUrl; } return imageUrl.replace(songId, albumId); }; // Determine which song IDs to use for keys and image URLs const topSongId = imageState.current === 0 ? currentSong?._uniqueId : nextSong?._uniqueId; const bottomSongId = imageState.current === 0 ? nextSong?._uniqueId : currentSong?._uniqueId; const topSong = imageState.current === 0 ? currentSong : nextSong; const bottomSong = imageState.current === 0 ? nextSong : currentSong; return ( {imageState.current === 0 && imageState.topImage && ( )} {imageState.current === 1 && imageState.bottomImage && ( )} ); }); BackgroundImage.displayName = 'BackgroundImage'; interface BackgroundImageOverlayProps { dynamicBackground: boolean | undefined; dynamicImageBlur: number | undefined; } const BackgroundImageOverlay = memo( ({ dynamicBackground, dynamicImageBlur }: BackgroundImageOverlayProps) => { if (!dynamicBackground) { return null; } return (
); }, ); BackgroundImageOverlay.displayName = 'BackgroundImageOverlay'; interface ControlsProps { isPageHovered: boolean; } const Controls = ({ isPageHovered }: ControlsProps) => { const { t } = useTranslation(); const { dynamicBackground, dynamicImageBlur, dynamicIsImage, expanded, opacity, useImageAspectRatio, } = useFullScreenPlayerStore(); const { setStore } = useFullScreenPlayerStoreActions(); const { setSettings } = useSettingsStoreActions(); const lyricConfig = useLyricsSettings(); const handleToggleFullScreenPlayer = () => { setStore({ expanded: !expanded }); }; const handleLyricsSettings = (property: string, value: any) => { setSettings({ lyrics: { ...useSettingsStore.getState().lyrics, [property]: value, }, }); }; useHotkeys([['Escape', handleToggleFullScreenPlayer]]); return ( {dynamicBackground && ( )} {dynamicBackground && dynamicIsImage && ( )} {dynamicBackground && ( )}