import { SelectItem } from '@mantine/core'; import isElectron from 'is-electron'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Select, Slider, Switch, toast } from '/@/renderer/components'; import { SettingOption, SettingsSection, } from '/@/renderer/features/settings/components/settings-section'; import { useCurrentStatus, usePlayerStore } from '/@/renderer/store'; import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store'; import { CrossfadeStyle, PlaybackStyle, PlaybackType, PlayerStatus } from '/@/renderer/types'; import { setQueue } from '/@/renderer/utils/set-transcoded-queue-data'; const getAudioDevice = async () => { const devices = await navigator.mediaDevices.enumerateDevices(); return (devices || []).filter((dev: MediaDeviceInfo) => dev.kind === 'audiooutput'); }; export const AudioSettings = ({ hasFancyAudio }: { hasFancyAudio: boolean }) => { const { t } = useTranslation(); const settings = usePlaybackSettings(); const { setSettings } = useSettingsStoreActions(); const status = useCurrentStatus(); const [audioDevices, setAudioDevices] = useState([]); useEffect(() => { const getAudioDevices = () => { getAudioDevice() .then((dev) => setAudioDevices(dev.map((d) => ({ label: d.label, value: d.deviceId }))), ) .catch(() => toast.error({ message: t('error.audioDeviceFetchError', { postProcess: 'sentenceCase' }), }), ); }; if (settings.type === PlaybackType.WEB) { getAudioDevices(); } }, [settings.type, t]); const audioOptions: SettingOption[] = [ { control: ( setSettings({ playback: { ...settings, audioDeviceId: e } })} /> ), description: t('setting.audioDevice', { context: 'description', postProcess: 'sentenceCase', }), isHidden: !isElectron() || settings.type !== PlaybackType.WEB, title: t('setting.audioDevice', { postProcess: 'sentenceCase' }), }, { control: ( { if (!e) return; setSettings({ playback: { ...settings, crossfadeStyle: e as CrossfadeStyle }, }); }} width={200} /> ), description: t('setting.crossfadeStyle', { context: 'description', postProcess: 'sentenceCase', }), isHidden: settings.type !== PlaybackType.WEB, note: status === PlayerStatus.PLAYING ? 'Player must be paused' : undefined, title: t('setting.crossfadeStyle', { postProcess: 'sentenceCase' }), }, ]; return ( ); };