Prevent Media Session Handling on MPV (#1212)

* Remove MediaSession Handling on MPV

* Add playbackType to config.json for Main Thread Access

* Disabling settings without Hiding
This commit is contained in:
Xudong Zhou 2025-11-02 09:26:16 +08:00 committed by GitHub
parent 0ca9eb0fcd
commit 829c27a5e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 7 deletions

View file

@ -3,6 +3,8 @@ import { BrowserWindow, globalShortcut, systemPreferences } from 'electron';
import { isMacOS, isWindows } from '../../../utils';
import { store } from '../settings';
import { PlaybackType } from '/@/shared/types/types';
export const enableMediaKeys = (window: BrowserWindow | null) => {
if (isMacOS()) {
const shouldPrompt = store.get('should_prompt_accessibility', true) as boolean;
@ -24,7 +26,9 @@ export const enableMediaKeys = (window: BrowserWindow | null) => {
}
const enableWindowsMediaSession = store.get('mediaSession', false) as boolean;
if (!(enableWindowsMediaSession && isWindows())) {
const playbackType = store.get('playbackType', PlaybackType.WEB) as PlaybackType;
if (!enableWindowsMediaSession || !isWindows() || playbackType !== PlaybackType.WEB) {
globalShortcut.register('MediaStop', () => {
window?.webContents.send('renderer-player-stop');
});

View file

@ -38,7 +38,7 @@ import {
} from './utils';
import './features';
import { TitleTheme } from '/@/shared/types/types';
import { PlaybackType, TitleTheme } from '/@/shared/types/types';
export default class AppUpdater {
constructor() {
@ -549,7 +549,9 @@ async function createWindow(first = true): Promise<void> {
}
const enableWindowsMediaSession = store.get('mediaSession', false) as boolean;
const shouldDisableMediaFeatures = !isWindows() || !enableWindowsMediaSession;
const playbackType = store.get('playbackType', PlaybackType.WEB) as PlaybackType;
const shouldDisableMediaFeatures =
!isWindows() || !enableWindowsMediaSession || playbackType !== PlaybackType.WEB;
if (shouldDisableMediaFeatures) {
app.commandLine.appendSwitch(
'disable-features',

View file

@ -7,6 +7,7 @@ import {
} from '/@/renderer/features/settings/components/settings-section';
import { useHotkeySettings, usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store';
import { Switch } from '/@/shared/components/switch/switch';
import { PlaybackType } from '/@/shared/types/types';
const localSettings = isElectron() ? window.api.localSettings : null;
const isWindows = isElectron() ? window.api.utils.isWindows() : false;
@ -15,14 +16,19 @@ export const WindowHotkeySettings = () => {
const { t } = useTranslation();
const settings = useHotkeySettings();
const { setSettings } = useSettingsStoreActions();
const { mediaSession: enableWindowsMediaSession } = usePlaybackSettings();
const { mediaSession: enableWindowsMediaSession, type: playbackType } = usePlaybackSettings();
const options: SettingOption[] = [
{
control: (
<Switch
defaultChecked={settings.globalMediaHotkeys}
disabled={!isElectron() || (enableWindowsMediaSession && isWindows)}
disabled={
!isElectron() ||
(enableWindowsMediaSession &&
isWindows &&
playbackType === PlaybackType.WEB)
}
onChange={(e) => {
setSettings({
hotkeys: {
@ -44,7 +50,7 @@ export const WindowHotkeySettings = () => {
context: 'description',
postProcess: 'sentenceCase',
}),
isHidden: !isElectron() || (enableWindowsMediaSession && isWindows),
isHidden: !isElectron(),
title: t('setting.globalMediaHotkeys', { postProcess: 'sentenceCase' }),
},
];

View file

@ -15,6 +15,8 @@ import { Switch } from '/@/shared/components/switch/switch';
import { toast } from '/@/shared/components/toast/toast';
import { CrossfadeStyle, PlaybackStyle, PlaybackType, PlayerStatus } from '/@/shared/types/types';
const ipc = isElectron() ? window.api.ipc : null;
const getAudioDevice = async () => {
const devices = await navigator.mediaDevices.enumerateDevices();
return (devices || []).filter((dev: MediaDeviceInfo) => dev.kind === 'audiooutput');
@ -62,6 +64,7 @@ export const AudioSettings = ({ hasFancyAudio }: { hasFancyAudio: boolean }) =>
disabled={status === PlayerStatus.PLAYING}
onChange={(e) => {
setSettings({ playback: { ...settings, type: e as PlaybackType } });
ipc?.send('settings-set', { property: 'playbackType', value: e });
if (isElectron() && e === PlaybackType.LOCAL) {
const queueData = usePlayerStore.getState().actions.getPlayerData();
setQueue(queueData);

View file

@ -7,6 +7,7 @@ import {
} from '/@/renderer/features/settings/components/settings-section';
import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store';
import { Switch } from '/@/shared/components/switch/switch';
import { PlaybackType } from '/@/shared/types/types';
const isWindows = isElectron() ? window.api.utils.isWindows() : null;
const isDesktop = isElectron();
@ -14,7 +15,7 @@ const ipc = isElectron() ? window.api.ipc : null;
export const MediaSessionSettings = () => {
const { t } = useTranslation();
const { mediaSession } = usePlaybackSettings();
const { mediaSession, type: playbackType } = usePlaybackSettings();
const { toggleMediaSession } = useSettingsStoreActions();
function handleMediaSessionChange() {
@ -29,6 +30,7 @@ export const MediaSessionSettings = () => {
<Switch
aria-label="Toggle media Session"
defaultChecked={mediaSession}
disabled={!isWindows || !isDesktop || playbackType !== PlaybackType.WEB}
onChange={handleMediaSessionChange}
/>
),