-
-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathmedia-session-settings.tsx
More file actions
67 lines (59 loc) · 2.41 KB
/
Copy pathmedia-session-settings.tsx
File metadata and controls
67 lines (59 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import isElectron from 'is-electron';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import {
SettingOption,
SettingsSection,
} from '/@/renderer/features/settings/components/settings-section';
import { openRestartRequiredToast } from '/@/renderer/features/settings/restart-toast';
import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store';
import { Switch } from '/@/shared/components/switch/switch';
import { PlayerType } from '/@/shared/types/types';
const isLinux = isElectron() ? window.api.utils.isLinux() : false;
const isWindows = isElectron() ? window.api.utils.isWindows() : false;
const isDesktop = isElectron();
const localSettings = isElectron() ? window.api.localSettings : null;
export const MediaSessionSettings = memo(() => {
const { t } = useTranslation();
const { mediaSession, type: playbackType } = usePlaybackSettings();
const { setSettings } = useSettingsStoreActions();
function handleMediaSessionChange(e: boolean) {
// If media session is enabled, disable global media hotkeys
if (e) {
localSettings!.set('global_media_hotkeys', false);
setSettings({
hotkeys: {
globalMediaHotkeys: false,
},
});
}
localSettings!.set('mediaSession', e);
setSettings({
playback: {
mediaSession: e,
},
});
// Restart is always required because the media session is a startup setting
openRestartRequiredToast();
}
const mediaSessionOptions: SettingOption[] = [
{
control: (
<Switch
aria-label="Toggle media Session"
checked={mediaSession}
disabled={isLinux || !isDesktop || playbackType !== PlayerType.WEB}
onChange={(e) => handleMediaSessionChange(e.currentTarget.checked)}
/>
),
description: t('setting.mediaSession', {
context: 'description',
postProcess: 'sentenceCase',
}),
isHidden: !isWindows,
note: t('common.restartRequired', { postProcess: 'sentenceCase' }),
title: t('setting.mediaSession', { postProcess: 'sentenceCase' }),
},
];
return <SettingsSection options={mediaSessionOptions} />;
});