mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 10:03:33 +00:00
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>
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { BrowserWindow, globalShortcut, systemPreferences } from 'electron';
|
|
|
|
import { isMacOS, isWindows } from '../../../utils';
|
|
import { store } from '../settings';
|
|
|
|
export const enableMediaKeys = (window: BrowserWindow | null) => {
|
|
if (isMacOS()) {
|
|
const shouldPrompt = store.get('should_prompt_accessibility', true) as boolean;
|
|
const shownWarning = store.get('shown_accessibility_warning', false) as boolean;
|
|
const trusted = systemPreferences.isTrustedAccessibilityClient(shouldPrompt);
|
|
|
|
if (shouldPrompt) {
|
|
store.set('should_prompt_accessibility', false);
|
|
}
|
|
|
|
if (!trusted && !shownWarning) {
|
|
window?.webContents.send('toast-from-main', {
|
|
message:
|
|
'Feishin is not a trusted accessibility client. Media keys will not work until this setting is changed',
|
|
type: 'warning',
|
|
});
|
|
store.set('shown_accessibility_warning', true);
|
|
}
|
|
}
|
|
|
|
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('MediaNextTrack', () => {
|
|
window?.webContents.send('renderer-player-next');
|
|
});
|
|
|
|
globalShortcut.register('MediaPreviousTrack', () => {
|
|
window?.webContents.send('renderer-player-previous');
|
|
});
|
|
}
|
|
};
|
|
|
|
export const disableMediaKeys = () => {
|
|
globalShortcut.unregister('MediaStop');
|
|
globalShortcut.unregister('MediaPlayPause');
|
|
globalShortcut.unregister('MediaNextTrack');
|
|
globalShortcut.unregister('MediaPreviousTrack');
|
|
};
|