diff --git a/main/menu.js b/main/menu.js index f8054ab0..be02e166 100644 --- a/main/menu.js +++ b/main/menu.js @@ -57,6 +57,7 @@ function toggleDevTools () { } function showWebTorrentWindow () { + log('showWebTorrentWindow') windows.webtorrent.show() windows.webtorrent.webContents.openDevTools({ detach: true }) } diff --git a/main/shortcuts.js b/main/shortcuts.js index 552ce5e0..739f72eb 100644 --- a/main/shortcuts.js +++ b/main/shortcuts.js @@ -13,9 +13,13 @@ var menu = require('./menu') var windows = require('./windows') function init () { - // Register alternate shortcuts here. Most shortcuts are registered in menu,js, but Electron does not support multiple shortcuts for a single menu item. + // Alternate shortcuts. Most shortcuts are registered in menu,js, but Electron does not + // support multiple shortcuts for a single menu item. localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen) localShortcut.register('Space', () => windows.main.send('dispatch', 'playPause')) + + // Hidden shortcuts, i.e. not shown in the menu + localShortcut.register('Esc', () => windows.main.send('dispatch', 'escapeBack')) } function onPlayerOpen () { diff --git a/renderer/index.js b/renderer/index.js index 16cb6a3a..1e35e07f 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -96,9 +96,6 @@ function init () { // ...same thing if you paste a torrent document.addEventListener('paste', onPaste) - // ...keyboard shortcuts - document.addEventListener('keydown', onKeyDown) - // ...focus and blur. Needed to show correct dock icon text ("badge") in OSX window.addEventListener('focus', onFocus) window.addEventListener('blur', onBlur) @@ -256,6 +253,15 @@ function dispatch (action, ...args) { var mediaTag = document.querySelector('video,audio') if (mediaTag) mediaTag.pause() } + if (action === 'escapeBack') { + if (state.modal) { + dispatch('exitModal') + } else if (state.window.isFullScreen) { + dispatch('toggleFullScreen') + } else { + dispatch('back') + } + } if (action === 'back') { state.location.back() } @@ -1146,18 +1152,6 @@ function onPaste (e) { }) } -function onKeyDown (e) { - if (e.which === 27) { /* ESC means either exit fullscreen or go back */ - if (state.modal) { - dispatch('exitModal') - } else if (state.window.isFullScreen) { - dispatch('toggleFullScreen') - } else { - dispatch('back') - } - } -} - function onFocus (e) { state.window.isFocused = true state.dock.badge = 0