diff --git a/src/main/features/core/player/media-keys.ts b/src/main/features/core/player/media-keys.ts index dfed0c88..815944da 100644 --- a/src/main/features/core/player/media-keys.ts +++ b/src/main/features/core/player/media-keys.ts @@ -1,6 +1,6 @@ import { BrowserWindow, globalShortcut, systemPreferences } from 'electron'; -import { isMacOS } from '../../../utils'; +import { isMacOS, isWindows } from '../../../utils'; import { store } from '../settings'; export const enableMediaKeys = (window: BrowserWindow | null) => { @@ -23,21 +23,24 @@ export const enableMediaKeys = (window: BrowserWindow | null) => { } } - globalShortcut.register('MediaStop', () => { - window?.webContents.send('renderer-player-stop'); - }); + const enableWindowsMediaSession = store.get('mediaSession', false) as boolean; + if (!(enableWindowsMediaSession && isWindows())) { + globalShortcut.register('MediaStop', () => { + window?.webContents.send('renderer-player-stop'); + }); - globalShortcut.register('MediaPlayPause', () => { - window?.webContents.send('renderer-player-play-pause'); - }); + globalShortcut.register('MediaPlayPause', () => { + window?.webContents.send('renderer-player-play-pause'); + }); - globalShortcut.register('MediaNextTrack', () => { - window?.webContents.send('renderer-player-next'); - }); + globalShortcut.register('MediaNextTrack', () => { + window?.webContents.send('renderer-player-next'); + }); - globalShortcut.register('MediaPreviousTrack', () => { - window?.webContents.send('renderer-player-previous'); - }); + globalShortcut.register('MediaPreviousTrack', () => { + window?.webContents.send('renderer-player-previous'); + }); + } }; export const disableMediaKeys = () => { diff --git a/src/main/index.ts b/src/main/index.ts index 24ddd934..3eabbf73 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -549,7 +549,7 @@ async function createWindow(first = true): Promise { } const enableWindowsMediaSession = store.get('mediaSession', false) as boolean; -const shouldDisableMediaFeatures = process.platform !== 'win32' || !enableWindowsMediaSession; +const shouldDisableMediaFeatures = !isWindows() || !enableWindowsMediaSession; if (shouldDisableMediaFeatures) { app.commandLine.appendSwitch( 'disable-features', diff --git a/src/renderer/features/settings/components/hotkeys/window-hotkey-settings.tsx b/src/renderer/features/settings/components/hotkeys/window-hotkey-settings.tsx index 2a307232..a93edfdc 100644 --- a/src/renderer/features/settings/components/hotkeys/window-hotkey-settings.tsx +++ b/src/renderer/features/settings/components/hotkeys/window-hotkey-settings.tsx @@ -5,22 +5,24 @@ import { SettingOption, SettingsSection, } from '/@/renderer/features/settings/components/settings-section'; -import { useHotkeySettings, useSettingsStoreActions } from '/@/renderer/store'; +import { useHotkeySettings, usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store'; import { Switch } from '/@/shared/components/switch/switch'; const localSettings = isElectron() ? window.api.localSettings : null; +const isWindows = isElectron() ? window.api.utils.isWindows() : false; export const WindowHotkeySettings = () => { const { t } = useTranslation(); const settings = useHotkeySettings(); const { setSettings } = useSettingsStoreActions(); + const { mediaSession: enableWindowsMediaSession } = usePlaybackSettings(); const options: SettingOption[] = [ { control: ( { setSettings({ hotkeys: { @@ -42,7 +44,7 @@ export const WindowHotkeySettings = () => { context: 'description', postProcess: 'sentenceCase', }), - isHidden: !isElectron(), + isHidden: !isElectron() || (enableWindowsMediaSession && isWindows), title: t('setting.globalMediaHotkeys', { postProcess: 'sentenceCase' }), }, ];