From 29298a10742a55e9597763f1ae924b67cb91837c Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 9 Mar 2016 03:08:21 -0800 Subject: [PATCH] Register "media key" for play/pause --- main/index.js | 2 +- main/shortcuts.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main/index.js b/main/index.js index 906d7995..a1ac8a7e 100644 --- a/main/index.js +++ b/main/index.js @@ -16,7 +16,7 @@ app.on('open-url', onOpen) app.on('ready', function () { electron.Menu.setApplicationMenu(menu.appMenu) windows.createMainWindow(menu) - shortcuts.init(menu) + shortcuts.init(menu, windows) }) app.on('activate', function () { diff --git a/main/shortcuts.js b/main/shortcuts.js index 009e93ec..8db37ed1 100644 --- a/main/shortcuts.js +++ b/main/shortcuts.js @@ -2,11 +2,16 @@ module.exports = { init: init } +var electron = require('electron') +var globalShortcut = electron.globalShortcut var localShortcut = require('electron-localshortcut') -function init (menu) { +function init (menu, windows) { // ⌘+Shift+F is an alternative fullscreen shortcut to the ones defined in menu.js. // Electron does not support multiple accelerators for a single menu item, so this // is registered separately here. localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen) + + // Special "media key" for play/pause, available on some keyboards + globalShortcut.register('MediaPlayPause', () => windows.main.send('dispatch', 'playPause')) }