mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
[enhancement]: Support disabling MPV entirely
Supports running Feishin solely using web audio (useful for clients with problems with MPV). Also moves save/restore queue to utils, as MPV object is now optional
This commit is contained in:
parent
ae8fc6df13
commit
f82da2e76b
10 changed files with 127 additions and 74 deletions
|
|
@ -1,23 +1,36 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import isElectron from 'is-electron';
|
||||
import { FileInput, Text, Button } from '/@/renderer/components';
|
||||
import { FileInput, Text, Button, Checkbox } from '/@/renderer/components';
|
||||
import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store';
|
||||
import { PlaybackType } from '/@/renderer/types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const localSettings = isElectron() ? window.electron.localSettings : null;
|
||||
|
||||
export const MpvRequired = () => {
|
||||
const [mpvPath, setMpvPath] = useState('');
|
||||
const settings = usePlaybackSettings();
|
||||
const { setSettings } = useSettingsStoreActions();
|
||||
const [disabled, setDisabled] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleSetMpvPath = (e: File) => {
|
||||
localSettings?.set('mpv_path', e.path);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const getMpvPath = async () => {
|
||||
if (!localSettings) return setMpvPath('');
|
||||
const mpvPath = localSettings.get('mpv_path') as string;
|
||||
return setMpvPath(mpvPath);
|
||||
};
|
||||
const handleSetDisableMpv = (disabled: boolean) => {
|
||||
setDisabled(disabled);
|
||||
localSettings?.set('disable_mpv', disabled);
|
||||
|
||||
getMpvPath();
|
||||
setSettings({
|
||||
playback: { ...settings, type: disabled ? PlaybackType.WEB : PlaybackType.LOCAL },
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!localSettings) return setMpvPath('');
|
||||
const mpvPath = localSettings.get('mpv_path') as string;
|
||||
return setMpvPath(mpvPath);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
|
@ -34,9 +47,15 @@ export const MpvRequired = () => {
|
|||
</a>
|
||||
</Text>
|
||||
<FileInput
|
||||
disabled={disabled}
|
||||
placeholder={mpvPath}
|
||||
onChange={handleSetMpvPath}
|
||||
/>
|
||||
<Text>{t('setting.disable_mpv', { context: 'description' })}</Text>
|
||||
<Checkbox
|
||||
label={t('setting.disableMpv')}
|
||||
onChange={(e) => handleSetDisableMpv(e.currentTarget.checked)}
|
||||
/>
|
||||
<Button onClick={() => localSettings?.restart()}>Restart</Button>
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue