import { useEffect, useState } from 'react'; import { SelectItem, Stack } from '@mantine/core'; import isElectron from 'is-electron'; import { Select, FileInput, Slider, Textarea, Text, toast } from '/@/renderer/components'; import { SettingsSection, SettingOption, } from '/@/renderer/features/settings/components/settings-section'; import { useCurrentStatus, usePlayerStore } from '/@/renderer/store'; import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store'; import { PlaybackType, PlayerStatus, PlaybackStyle, CrossfadeStyle } from '/@/renderer/types'; const localSettings = isElectron() ? window.electron.localSettings : null; const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null; const getAudioDevice = async () => { const devices = await navigator.mediaDevices.enumerateDevices(); return (devices || []).filter((dev: MediaDeviceInfo) => dev.kind === 'audiooutput'); }; export const AudioSettings = () => { const settings = usePlaybackSettings(); const { setSettings } = useSettingsStoreActions(); const status = useCurrentStatus(); const [audioDevices, setAudioDevices] = useState([]); const [mpvPath, setMpvPath] = useState(''); const [mpvParameters, setMpvParameters] = useState(''); const handleSetMpvPath = (e: File) => { localSettings.set('mpv_path', e.path); }; useEffect(() => { const getMpvPath = async () => { if (!isElectron()) return setMpvPath(''); const mpvPath = (await localSettings.get('mpv_path')) as string; return setMpvPath(mpvPath); }; const getMpvParameters = async () => { if (!isElectron()) return setMpvPath(''); const mpvParametersFromSettings = (await localSettings.get('mpv_parameters')) as string[]; const mpvParameters = mpvParametersFromSettings?.join('\n'); return setMpvParameters(mpvParameters); }; getMpvPath(); getMpvParameters(); }, []); useEffect(() => { const getAudioDevices = () => { getAudioDevice() .then((dev) => setAudioDevices(dev.map((d) => ({ label: d.label, value: d.deviceId })))) .catch(() => toast.error({ message: 'Error fetching audio devices' })); }; if (settings.type === PlaybackType.WEB) { getAudioDevices(); } }, [settings.type]); const audioOptions: SettingOption[] = [ { control: (