mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00: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:
parent
877f286f43
commit
a9af1e91d4
3 changed files with 22 additions and 17 deletions
|
|
@ -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,6 +23,8 @@ export const enableMediaKeys = (window: BrowserWindow | null) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const enableWindowsMediaSession = store.get('mediaSession', false) as boolean;
|
||||||
|
if (!(enableWindowsMediaSession && isWindows())) {
|
||||||
globalShortcut.register('MediaStop', () => {
|
globalShortcut.register('MediaStop', () => {
|
||||||
window?.webContents.send('renderer-player-stop');
|
window?.webContents.send('renderer-player-stop');
|
||||||
});
|
});
|
||||||
|
|
@ -38,6 +40,7 @@ export const enableMediaKeys = (window: BrowserWindow | null) => {
|
||||||
globalShortcut.register('MediaPreviousTrack', () => {
|
globalShortcut.register('MediaPreviousTrack', () => {
|
||||||
window?.webContents.send('renderer-player-previous');
|
window?.webContents.send('renderer-player-previous');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const disableMediaKeys = () => {
|
export const disableMediaKeys = () => {
|
||||||
|
|
|
||||||
|
|
@ -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' }),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue