import isElectron from 'is-electron'; import { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { useAudioDevices } from '/@/renderer/features/settings/components/playback/audio-settings'; import { ListConfigTable } from '/@/renderer/features/shared/components/list-config-menu'; import { usePlaybackType, usePlayerActions, usePlayerProperties, usePlayerSongProperties, usePlayerSpeed, usePlayerStatus, } from '/@/renderer/store'; import { useCombinedLyricsAndVisualizer, usePlaybackSettings, useSettingsStore, useSettingsStoreActions, useShowLyricsInSidebar, useShowVisualizerInSidebar, } from '/@/renderer/store/settings.store'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Popover } from '/@/shared/components/popover/popover'; import { SegmentedControl } from '/@/shared/components/segmented-control/segmented-control'; import { Select } from '/@/shared/components/select/select'; import { Slider } from '/@/shared/components/slider/slider'; import { Switch } from '/@/shared/components/switch/switch'; import { CrossfadeStyle, PlayerStatus, PlayerStyle, PlayerType } from '/@/shared/types/types'; const ipc = isElectron() ? window.api.ipc : null; export const PlayerConfig = () => { const { t } = useTranslation(); const preservePitch = useSettingsStore((state) => state.playback.preservePitch); const showLyricsInSidebar = useShowLyricsInSidebar(); const showVisualizerInSidebar = useShowVisualizerInSidebar(); const combinedLyricsAndVisualizer = useCombinedLyricsAndVisualizer(); const playbackSettings = usePlaybackSettings(); const { setSettings } = useSettingsStoreActions(); const setPreservePitch = useCallback( (value: boolean) => { setSettings({ playback: { ...playbackSettings, preservePitch: value }, }); }, [playbackSettings, setSettings], ); const options = useMemo(() => { const allOptions = [ { component: , id: 'audioPlayerType', label: t('setting.audioPlayer', { postProcess: 'titleCase' }), }, { component: , id: 'audioDevice', label: t('setting.audioDevice', { postProcess: 'titleCase' }), }, { component: null, id: 'divider-1', isDivider: true, label: '', }, { component: , id: 'transitionType', label: t('setting.playbackStyle', { postProcess: 'titleCase', }), }, { component: , id: 'crossfadeStyle', label: t('setting.crossfadeStyle', { postProcess: 'titleCase', }), }, { component: , id: 'crossfadeDuration', label: t('setting.crossfadeDuration', { postProcess: 'titleCase', }), }, { component: null, id: 'divider-2', isDivider: true, label: '', }, { component: , id: 'playbackSpeed', label: t('player.playbackSpeed', { postProcess: 'titleCase' }), }, { component: ( setPreservePitch(e.currentTarget.checked)} /> ), id: 'preservePitch', label: t('setting.preservePitch', { postProcess: 'titleCase' }), }, { component: null, id: 'divider-3', isDivider: true, label: '', }, { component: ( { setSettings({ general: { showLyricsInSidebar: e.currentTarget.checked, }, }); }} /> ), id: 'showLyricsInSidebar', label: t('setting.showLyricsInSidebar', { postProcess: 'titleCase' }), }, { component: ( { setSettings({ general: { showVisualizerInSidebar: e.currentTarget.checked, }, }); }} /> ), id: 'showVisualizerInSidebar', label: t('setting.showVisualizerInSidebar', { postProcess: 'titleCase' }), }, { component: ( { setSettings({ general: { combinedLyricsAndVisualizer: e.currentTarget.checked, }, }); }} /> ), id: 'combinedLyricsAndVisualizer', label: t('setting.combinedLyricsAndVisualizer', { postProcess: 'titleCase' }), }, ]; return allOptions; }, [ t, preservePitch, setSettings, setPreservePitch, showLyricsInSidebar, showVisualizerInSidebar, combinedLyricsAndVisualizer, ]); return ( ); }; const AudioPlayerTypeConfig = () => { const status = usePlayerStatus(); const playbackSettings = usePlaybackSettings(); const { setSettings } = useSettingsStoreActions(); return ( { setSettings({ playback: { ...playbackSettings, ...(playbackType === PlayerType.LOCAL ? { mpvAudioDeviceId: e } : { audioDeviceId: e }), }, }); }} width="100%" /> ); }; const TransitionTypeConfig = () => { const { t } = useTranslation(); const status = usePlayerStatus(); const playbackSettings = usePlaybackSettings(); const { transitionType } = usePlayerProperties(); const { setTransitionType } = usePlayerActions(); return ( setTransitionType(value as PlayerStyle)} size="sm" value={transitionType} w="100%" /> ); }; const CrossfadeStyleConfig = () => { const status = usePlayerStatus(); const playbackSettings = usePlaybackSettings(); const { crossfadeStyle, transitionType } = usePlayerProperties(); const { setCrossfadeStyle } = usePlayerActions(); return (