2025-05-18 14:03:18 -07:00
|
|
|
import isElectron from 'is-electron';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
|
|
import { languages } from '/@/i18n/i18n';
|
|
|
|
|
import { LyricSource } from '/@/renderer/api/types';
|
2023-05-28 14:31:49 -07:00
|
|
|
import {
|
2024-09-24 11:25:17 +08:00
|
|
|
MultiSelect,
|
|
|
|
|
MultiSelectProps,
|
|
|
|
|
NumberInput,
|
2025-05-18 14:03:18 -07:00
|
|
|
Select,
|
2024-09-24 11:25:17 +08:00
|
|
|
Switch,
|
2025-05-18 14:03:18 -07:00
|
|
|
TextInput,
|
2024-09-24 11:25:17 +08:00
|
|
|
} from '/@/renderer/components';
|
2025-05-18 14:03:18 -07:00
|
|
|
import {
|
|
|
|
|
SettingOption,
|
|
|
|
|
SettingsSection,
|
|
|
|
|
} from '/@/renderer/features/settings/components/settings-section';
|
|
|
|
|
import { useLyricsSettings, useSettingsStoreActions } from '/@/renderer/store';
|
2023-05-28 14:31:49 -07:00
|
|
|
|
2025-05-18 14:03:18 -07:00
|
|
|
const localSettings = isElectron() ? window.api.localSettings : null;
|
2023-05-28 14:31:49 -07:00
|
|
|
|
|
|
|
|
const WorkingButtonSelect = styled(MultiSelect)<MultiSelectProps>`
|
2023-07-01 19:10:05 -07:00
|
|
|
& button {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
2023-05-28 14:31:49 -07:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const LyricSettings = () => {
|
2023-10-30 19:22:45 -07:00
|
|
|
const { t } = useTranslation();
|
2023-07-01 19:10:05 -07:00
|
|
|
const settings = useLyricsSettings();
|
|
|
|
|
const { setSettings } = useSettingsStoreActions();
|
2023-05-28 14:31:49 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const lyricOptions: SettingOption[] = [
|
|
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<Switch
|
|
|
|
|
aria-label="Follow lyrics"
|
|
|
|
|
defaultChecked={settings.follow}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSettings({
|
|
|
|
|
lyrics: {
|
|
|
|
|
...settings,
|
|
|
|
|
follow: e.currentTarget.checked,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
),
|
2023-10-30 19:22:45 -07:00
|
|
|
description: t('setting.followLyric', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
|
|
|
|
title: t('setting.followLyric', { postProcess: 'sentenceCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<Switch
|
|
|
|
|
aria-label="Enable fetching lyrics"
|
|
|
|
|
defaultChecked={settings.fetch}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSettings({
|
|
|
|
|
lyrics: {
|
|
|
|
|
...settings,
|
|
|
|
|
fetch: e.currentTarget.checked,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
),
|
2023-10-30 19:22:45 -07:00
|
|
|
description: t('setting.lyricFetch', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
2023-07-01 19:10:05 -07:00
|
|
|
isHidden: !isElectron(),
|
2023-10-30 19:22:45 -07:00
|
|
|
title: t('setting.lyricFetch', { postProcess: 'sentenceCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<WorkingButtonSelect
|
|
|
|
|
aria-label="Lyric providers"
|
2025-05-18 14:03:18 -07:00
|
|
|
clearable
|
2023-07-01 19:10:05 -07:00
|
|
|
data={Object.values(LyricSource)}
|
|
|
|
|
defaultValue={settings.sources}
|
|
|
|
|
onChange={(e: LyricSource[]) => {
|
|
|
|
|
localSettings?.set('lyrics', e);
|
|
|
|
|
setSettings({
|
|
|
|
|
lyrics: {
|
|
|
|
|
...settings,
|
|
|
|
|
sources: e,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
2025-05-18 14:03:18 -07:00
|
|
|
width={300}
|
2023-07-01 19:10:05 -07:00
|
|
|
/>
|
|
|
|
|
),
|
2023-10-30 19:22:45 -07:00
|
|
|
description: t('setting.lyricFetchProvider', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
2023-07-01 19:10:05 -07:00
|
|
|
isHidden: !isElectron(),
|
2023-10-30 19:22:45 -07:00
|
|
|
title: t('setting.lyricFetchProvider', { postProcess: 'sentenceCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<NumberInput
|
|
|
|
|
defaultValue={settings.delayMs}
|
|
|
|
|
onBlur={(e) => {
|
|
|
|
|
const value = Number(e.currentTarget.value);
|
|
|
|
|
setSettings({
|
|
|
|
|
lyrics: {
|
|
|
|
|
...settings,
|
|
|
|
|
delayMs: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
2025-05-18 14:03:18 -07:00
|
|
|
step={10}
|
|
|
|
|
width={100}
|
2023-07-01 19:10:05 -07:00
|
|
|
/>
|
|
|
|
|
),
|
2023-10-30 19:22:45 -07:00
|
|
|
description: t('setting.lyricOffset', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
2023-07-01 19:10:05 -07:00
|
|
|
isHidden: !isElectron(),
|
2023-10-30 19:22:45 -07:00
|
|
|
title: t('setting.lyricOffset', { postProcess: 'sentenceCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
2024-09-24 11:25:17 +08:00
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<Select
|
|
|
|
|
data={languages}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
setSettings({ lyrics: { ...settings, translationTargetLanguage: value } });
|
|
|
|
|
}}
|
2025-05-18 14:03:18 -07:00
|
|
|
value={settings.translationTargetLanguage}
|
2024-09-24 11:25:17 +08:00
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
description: t('setting.translationTargetLanguage', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
|
|
|
|
isHidden: !isElectron(),
|
|
|
|
|
title: t('setting.translationTargetLanguage', { postProcess: 'sentenceCase' }),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<Select
|
|
|
|
|
data={['Microsoft Azure', 'Google Cloud']}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
setSettings({ lyrics: { ...settings, translationApiProvider: value } });
|
|
|
|
|
}}
|
2025-05-18 14:03:18 -07:00
|
|
|
value={settings.translationApiProvider}
|
2024-09-24 11:25:17 +08:00
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
description: t('setting.translationApiProvider', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
|
|
|
|
isHidden: !isElectron(),
|
|
|
|
|
title: t('setting.translationApiProvider', { postProcess: 'sentenceCase' }),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
control: (
|
|
|
|
|
<TextInput
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSettings({
|
|
|
|
|
lyrics: { ...settings, translationApiKey: e.currentTarget.value },
|
|
|
|
|
});
|
|
|
|
|
}}
|
2025-05-18 14:03:18 -07:00
|
|
|
value={settings.translationApiKey}
|
2024-09-24 11:25:17 +08:00
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
description: t('setting.translationApiKey', {
|
|
|
|
|
context: 'description',
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
}),
|
|
|
|
|
isHidden: !isElectron(),
|
|
|
|
|
title: t('setting.translationApiKey', { postProcess: 'sentenceCase' }),
|
|
|
|
|
},
|
2023-07-01 19:10:05 -07:00
|
|
|
];
|
2023-05-28 14:31:49 -07:00
|
|
|
|
2024-05-05 13:25:05 -07:00
|
|
|
return (
|
|
|
|
|
<SettingsSection
|
|
|
|
|
divider={false}
|
|
|
|
|
options={lyricOptions}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2023-05-28 14:31:49 -07:00
|
|
|
};
|