Remove global shortcuts when player isn't active

This commit is contained in:
DC
2016-03-28 22:53:59 -07:00
parent 8ce7235c2b
commit 840966c7f0
3 changed files with 21 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ var powerSaveBlocker = electron.powerSaveBlocker
var log = require('./log')
var menu = require('./menu')
var windows = require('./windows')
var shortcuts = require('./shortcuts')
// has to be a number, not a boolean, and undefined throws an error
var powerSaveBlockID = 0
@@ -61,8 +62,14 @@ function init () {
ipcMain.on('blockPowerSave', blockPowerSave)
ipcMain.on('unblockPowerSave', unblockPowerSave)
ipcMain.on('onPlayerOpen', menu.onPlayerOpen)
ipcMain.on('onPlayerClose', menu.onPlayerClose)
ipcMain.on('onPlayerOpen', function () {
menu.onPlayerOpen()
shortcuts.registerPlayerShortcuts()
})
ipcMain.on('onPlayerClose', function () {
menu.onPlayerClose()
shortcuts.unregisterPlayerShortcuts()
})
}
function setBounds (bounds, maximize) {

View File

@@ -1,5 +1,7 @@
module.exports = {
init
init,
registerPlayerShortcuts,
unregisterPlayerShortcuts
}
var electron = require('electron')
@@ -11,11 +13,17 @@ var menu = require('./menu')
var windows = require('./windows')
function init () {
// Special "media key" for play/pause, available on some keyboards
globalShortcut.register('MediaPlayPause', () => windows.main.send('dispatch', 'playPause'))
// ⌘+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)
}
function registerPlayerShortcuts () {
// Special "media key" for play/pause, available on some keyboards
globalShortcut.register('MediaPlayPause', () => windows.main.send('dispatch', 'playPause'))
}
function unregisterPlayerShortcuts () {
globalShortcut.unregister('MediaPlayPause')
}

View File

@@ -286,12 +286,10 @@ function dispatch (action, ...args) {
}
if (action === 'mediaStalled') {
state.playing.isStalled = true
update()
}
if (action === 'mediaTimeUpdate') {
state.playing.lastTimeUpdate = new Date().getTime()
state.playing.isStalled = false
update()
}
if (action === 'toggleFullScreen') {
ipcRenderer.send('toggleFullScreen', args[0] /* optional bool */)
@@ -336,7 +334,6 @@ function playPause (isPaused) {
Cast.playPause()
}
state.playing.isPaused = !state.playing.isPaused
update()
}
function jumpToTime (time) {
@@ -344,7 +341,6 @@ function jumpToTime (time) {
Cast.seek(time)
} else {
state.playing.jumpToTime = time
update()
}
}
@@ -360,7 +356,6 @@ function setVolume (volume) {
Cast.setVolume(volume)
} else {
state.playing.setVolume = volume
update()
}
}