mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-18 09:24:19 +02:00
fix mediasession controls
This commit is contained in:
@@ -5,23 +5,48 @@ import {
|
||||
SettingOption,
|
||||
SettingsSection,
|
||||
} from '/@/renderer/features/settings/components/settings-section';
|
||||
import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store';
|
||||
import { openRestartRequiredToast } from '/@/renderer/features/settings/restart-toast';
|
||||
import {
|
||||
useHotkeySettings,
|
||||
usePlaybackSettings,
|
||||
useSettingsStoreActions,
|
||||
} from '/@/renderer/store/settings.store';
|
||||
import { Switch } from '/@/shared/components/switch/switch';
|
||||
import { PlayerType } from '/@/shared/types/types';
|
||||
|
||||
const isWindows = isElectron() ? window.api.utils.isWindows() : null;
|
||||
const isLinux = isElectron() ? window.api.utils.isLinux() : false;
|
||||
const isDesktop = isElectron();
|
||||
const ipc = isElectron() ? window.api.ipc : null;
|
||||
const localSettings = isElectron() ? window.api.localSettings : null;
|
||||
|
||||
export const MediaSessionSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
const { mediaSession, type: playbackType } = usePlaybackSettings();
|
||||
const { toggleMediaSession } = useSettingsStoreActions();
|
||||
const playbackSettings = usePlaybackSettings();
|
||||
const hotkeySettings = useHotkeySettings();
|
||||
const { setSettings } = useSettingsStoreActions();
|
||||
|
||||
function handleMediaSessionChange() {
|
||||
const current = mediaSession;
|
||||
toggleMediaSession();
|
||||
ipc?.send('settings-set', { property: 'mediaSession', value: !current });
|
||||
function handleMediaSessionChange(e: boolean) {
|
||||
// If media session is enabled, disable global media hotkeys
|
||||
if (e) {
|
||||
localSettings!.set('global_media_hotkeys', false);
|
||||
setSettings({
|
||||
hotkeys: {
|
||||
...hotkeySettings,
|
||||
globalMediaHotkeys: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
localSettings!.set('mediaSession', e);
|
||||
setSettings({
|
||||
playback: {
|
||||
...playbackSettings,
|
||||
mediaSession: e,
|
||||
},
|
||||
});
|
||||
|
||||
// Restart is always required because the media session is a startup setting
|
||||
openRestartRequiredToast();
|
||||
}
|
||||
|
||||
const mediaSessionOptions: SettingOption[] = [
|
||||
@@ -29,16 +54,16 @@ export const MediaSessionSettings = () => {
|
||||
control: (
|
||||
<Switch
|
||||
aria-label="Toggle media Session"
|
||||
defaultChecked={mediaSession}
|
||||
disabled={!isWindows || !isDesktop || playbackType !== PlayerType.WEB}
|
||||
onChange={handleMediaSessionChange}
|
||||
checked={mediaSession}
|
||||
disabled={isLinux || !isDesktop || playbackType !== PlayerType.WEB}
|
||||
onChange={(e) => handleMediaSessionChange(e.currentTarget.checked)}
|
||||
/>
|
||||
),
|
||||
description: t('setting.mediaSession', {
|
||||
context: 'description',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
isHidden: !isWindows || !isDesktop,
|
||||
isHidden: isLinux || !isDesktop,
|
||||
note: t('common.restartRequired', { postProcess: 'sentenceCase' }),
|
||||
title: t('setting.mediaSession', { postProcess: 'sentenceCase' }),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user