From 090f7f0ec31bfda58cfb50401ced853fb5abfa7c Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 6 Jan 2023 10:31:54 +0100 Subject: [PATCH] Fix Next/Previous/Stop media keys --- CHANGELOG.md | 3 +++ src/electron/shortcuts.ts | 10 ++++++---- src/electron/typed_ipc.ts | 1 + src/lib/player.ts | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 687049f..a7d0794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Next +- Fix Next/Previous/Stop media key shortcuts + ## 0.16.3 - 2022 Nov 7 - Improve focus behavior diff --git a/src/electron/shortcuts.ts b/src/electron/shortcuts.ts index 90eda1b..06a4682 100644 --- a/src/electron/shortcuts.ts +++ b/src/electron/shortcuts.ts @@ -1,19 +1,21 @@ import { globalShortcut, dialog, systemPreferences, BrowserWindow } from 'electron' import is from './is' +import type { WebContents } from './typed_ipc' function tryRegistering(mainWindow: BrowserWindow) { + const webContents = mainWindow.webContents as WebContents const success1 = globalShortcut.register('MediaPlayPause', () => { - if (mainWindow !== null) mainWindow.webContents.send('playPause') + if (mainWindow !== null) webContents.send('playPause') }) if (!success1) return false globalShortcut.register('MediaNextTrack', () => { - if (mainWindow !== null) mainWindow.webContents.send('next') + if (mainWindow !== null) webContents.send('Next') }) globalShortcut.register('MediaPreviousTrack', () => { - if (mainWindow !== null) mainWindow.webContents.send('previous') + if (mainWindow !== null) webContents.send('Previous') }) globalShortcut.register('MediaStop', () => { - if (mainWindow !== null) mainWindow.webContents.send('stop') + if (mainWindow !== null) webContents.send('Stop') }) return true } diff --git a/src/electron/typed_ipc.ts b/src/electron/typed_ipc.ts index 9708fb4..c164553 100644 --- a/src/electron/typed_ipc.ts +++ b/src/electron/typed_ipc.ts @@ -100,6 +100,7 @@ type Events = { playPause: () => void Next: () => void Previous: () => void + Stop: () => void Shuffle: () => void Repeat: () => void volumeUp: () => void diff --git a/src/lib/player.ts b/src/lib/player.ts index e44b3db..657b4fa 100644 --- a/src/lib/player.ts +++ b/src/lib/player.ts @@ -274,3 +274,4 @@ if (navigator.mediaSession) { ipcRenderer.on('playPause', playPause) ipcRenderer.on('Next', next) ipcRenderer.on('Previous', previous) +ipcRenderer.on('Stop', stop) -- 2.51.2