mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
Disable Media Keys with MediaSession on Windows (#1207)
In f07393c8 we enabled the MediaSession API, which from Chromium's side
brings its own native way of handling Global Media Keys. However, it
turns out having this enabled seemingly conflicts with Windows 11's SMTC
implementation when we also bind the Media Keys using Electron's Global
Hotkeys API (Windows 10 is apparently fine, but now EOL).
Globally passing `HardwareMediaKeyHandling` to `disable-features` was
considered, however using the MediaSession API requires
`HardwareMediaKeyHandling` to be enabled, so this is not an option.
Instead, with MediaSession enabled we need to let Chromium handle the
Media Keys, while without MediaSession we bind our own Global Hot Keys
for users that have them enabled in the settings.
Co-authored-by: Xudong Zhou <godzmichael@outlook.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { BrowserWindow, globalShortcut, systemPreferences } from 'electron';
|
import { BrowserWindow, globalShortcut, systemPreferences } from 'electron';
|
||||||
|
|
||||||
import { isMacOS } from '../../../utils';
|
import { isMacOS, isWindows } from '../../../utils';
|
||||||
import { store } from '../settings';
|
import { store } from '../settings';
|
||||||
|
|
||||||
export const enableMediaKeys = (window: BrowserWindow | null) => {
|
export const enableMediaKeys = (window: BrowserWindow | null) => {
|
||||||
@@ -23,21 +23,24 @@ export const enableMediaKeys = (window: BrowserWindow | null) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
globalShortcut.register('MediaStop', () => {
|
const enableWindowsMediaSession = store.get('mediaSession', false) as boolean;
|
||||||
window?.webContents.send('renderer-player-stop');
|
if (!(enableWindowsMediaSession && isWindows())) {
|
||||||
});
|
globalShortcut.register('MediaStop', () => {
|
||||||
|
window?.webContents.send('renderer-player-stop');
|
||||||
|
});
|
||||||
|
|
||||||
globalShortcut.register('MediaPlayPause', () => {
|
globalShortcut.register('MediaPlayPause', () => {
|
||||||
window?.webContents.send('renderer-player-play-pause');
|
window?.webContents.send('renderer-player-play-pause');
|
||||||
});
|
});
|
||||||
|
|
||||||
globalShortcut.register('MediaNextTrack', () => {
|
globalShortcut.register('MediaNextTrack', () => {
|
||||||
window?.webContents.send('renderer-player-next');
|
window?.webContents.send('renderer-player-next');
|
||||||
});
|
});
|
||||||
|
|
||||||
globalShortcut.register('MediaPreviousTrack', () => {
|
globalShortcut.register('MediaPreviousTrack', () => {
|
||||||
window?.webContents.send('renderer-player-previous');
|
window?.webContents.send('renderer-player-previous');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const disableMediaKeys = () => {
|
export const disableMediaKeys = () => {
|
||||||
|
|||||||
+1
-1
@@ -549,7 +549,7 @@ async function createWindow(first = true): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const enableWindowsMediaSession = store.get('mediaSession', false) as boolean;
|
const enableWindowsMediaSession = store.get('mediaSession', false) as boolean;
|
||||||
const shouldDisableMediaFeatures = process.platform !== 'win32' || !enableWindowsMediaSession;
|
const shouldDisableMediaFeatures = !isWindows() || !enableWindowsMediaSession;
|
||||||
if (shouldDisableMediaFeatures) {
|
if (shouldDisableMediaFeatures) {
|
||||||
app.commandLine.appendSwitch(
|
app.commandLine.appendSwitch(
|
||||||
'disable-features',
|
'disable-features',
|
||||||
|
|||||||
@@ -5,22 +5,24 @@ import {
|
|||||||
SettingOption,
|
SettingOption,
|
||||||
SettingsSection,
|
SettingsSection,
|
||||||
} from '/@/renderer/features/settings/components/settings-section';
|
} 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';
|
import { Switch } from '/@/shared/components/switch/switch';
|
||||||
|
|
||||||
const localSettings = isElectron() ? window.api.localSettings : null;
|
const localSettings = isElectron() ? window.api.localSettings : null;
|
||||||
|
const isWindows = isElectron() ? window.api.utils.isWindows() : false;
|
||||||
|
|
||||||
export const WindowHotkeySettings = () => {
|
export const WindowHotkeySettings = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const settings = useHotkeySettings();
|
const settings = useHotkeySettings();
|
||||||
const { setSettings } = useSettingsStoreActions();
|
const { setSettings } = useSettingsStoreActions();
|
||||||
|
const { mediaSession: enableWindowsMediaSession } = usePlaybackSettings();
|
||||||
|
|
||||||
const options: SettingOption[] = [
|
const options: SettingOption[] = [
|
||||||
{
|
{
|
||||||
control: (
|
control: (
|
||||||
<Switch
|
<Switch
|
||||||
defaultChecked={settings.globalMediaHotkeys}
|
defaultChecked={settings.globalMediaHotkeys}
|
||||||
disabled={!isElectron()}
|
disabled={!isElectron() || (enableWindowsMediaSession && isWindows)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setSettings({
|
setSettings({
|
||||||
hotkeys: {
|
hotkeys: {
|
||||||
@@ -42,7 +44,7 @@ export const WindowHotkeySettings = () => {
|
|||||||
context: 'description',
|
context: 'description',
|
||||||
postProcess: 'sentenceCase',
|
postProcess: 'sentenceCase',
|
||||||
}),
|
}),
|
||||||
isHidden: !isElectron(),
|
isHidden: !isElectron() || (enableWindowsMediaSession && isWindows),
|
||||||
title: t('setting.globalMediaHotkeys', { postProcess: 'sentenceCase' }),
|
title: t('setting.globalMediaHotkeys', { postProcess: 'sentenceCase' }),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user