Keyboard shortcuts: volume shortcuts should be local
`globalShortcut` will register the shortcut at the OS level, even when the app is not focused. Using `localShortcut` would work, but let's put it in the top menu instead, where all the other shortcuts are.
This commit is contained in:
12
main/ipc.js
12
main/ipc.js
@@ -23,13 +23,8 @@ function init () {
|
|||||||
app.emit('ipcReady')
|
app.emit('ipcReady')
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('showOpenTorrentFile', function (e) {
|
ipcMain.on('showOpenTorrentFile', menu.showOpenTorrentFile)
|
||||||
menu.showOpenTorrentFile()
|
ipcMain.on('showCreateTorrent', menu.showCreateTorrent)
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('showCreateTorrent', function (e) {
|
|
||||||
menu.showCreateTorrent()
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('setBounds', function (e, bounds, maximize) {
|
ipcMain.on('setBounds', function (e, bounds, maximize) {
|
||||||
setBounds(bounds, maximize)
|
setBounds(bounds, maximize)
|
||||||
@@ -62,6 +57,9 @@ function init () {
|
|||||||
|
|
||||||
ipcMain.on('blockPowerSave', blockPowerSave)
|
ipcMain.on('blockPowerSave', blockPowerSave)
|
||||||
ipcMain.on('unblockPowerSave', unblockPowerSave)
|
ipcMain.on('unblockPowerSave', unblockPowerSave)
|
||||||
|
|
||||||
|
ipcMain.on('onPlayerOpen', menu.onPlayerOpen)
|
||||||
|
ipcMain.on('onPlayerClose', menu.onPlayerClose)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBounds (bounds, maximize) {
|
function setBounds (bounds, maximize) {
|
||||||
|
|||||||
39
main/menu.js
39
main/menu.js
@@ -3,6 +3,8 @@ module.exports = {
|
|||||||
onToggleFullScreen,
|
onToggleFullScreen,
|
||||||
onWindowHide,
|
onWindowHide,
|
||||||
onWindowShow,
|
onWindowShow,
|
||||||
|
onPlayerOpen,
|
||||||
|
onPlayerClose,
|
||||||
showCreateTorrent,
|
showCreateTorrent,
|
||||||
showOpenTorrentFile,
|
showOpenTorrentFile,
|
||||||
toggleFullScreen
|
toggleFullScreen
|
||||||
@@ -44,6 +46,18 @@ function toggleFloatOnTop (flag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function increaseVolume () {
|
||||||
|
if (windows.main) {
|
||||||
|
windows.main.send('dispatch', 'changeVolume', 0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function decreaseVolume () {
|
||||||
|
if (windows.main) {
|
||||||
|
windows.main.send('dispatch', 'changeVolume', -0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function toggleDevTools () {
|
function toggleDevTools () {
|
||||||
debug('toggleDevTools')
|
debug('toggleDevTools')
|
||||||
if (windows.main) {
|
if (windows.main) {
|
||||||
@@ -75,6 +89,16 @@ function onWindowHide () {
|
|||||||
getMenuItem('Float on Top').enabled = false
|
getMenuItem('Float on Top').enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onPlayerOpen () {
|
||||||
|
getMenuItem('Increase Volume').enabled = true
|
||||||
|
getMenuItem('Decrease Volume').enabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPlayerClose () {
|
||||||
|
getMenuItem('Increase Volume').enabled = false
|
||||||
|
getMenuItem('Decrease Volume').enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
function onToggleFullScreen (isFullScreen) {
|
function onToggleFullScreen (isFullScreen) {
|
||||||
isFullScreen = isFullScreen != null ? isFullScreen : windows.main.isFullScreen()
|
isFullScreen = isFullScreen != null ? isFullScreen : windows.main.isFullScreen()
|
||||||
windows.main.setMenuBarVisibility(!isFullScreen)
|
windows.main.setMenuBarVisibility(!isFullScreen)
|
||||||
@@ -196,6 +220,21 @@ function getAppMenuTemplate () {
|
|||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Increase Volume',
|
||||||
|
accelerator: 'CmdOrCtrl+Up',
|
||||||
|
click: increaseVolume,
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Decrease Volume',
|
||||||
|
accelerator: 'CmdOrCtrl+Down',
|
||||||
|
click: decreaseVolume,
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Developer',
|
label: 'Developer',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
|||||||
@@ -18,8 +18,4 @@ function init () {
|
|||||||
// Electron does not support multiple accelerators for a single menu item, so this
|
// Electron does not support multiple accelerators for a single menu item, so this
|
||||||
// is registered separately here.
|
// is registered separately here.
|
||||||
localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen)
|
localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen)
|
||||||
|
|
||||||
// Control Volume
|
|
||||||
globalShortcut.register('CmdOrCtrl+Up', () => windows.main.send('dispatch', 'changeVolume', 0.1))
|
|
||||||
globalShortcut.register('CmdOrCtrl+Down', () => windows.main.send('dispatch', 'changeVolume', -0.1))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -716,10 +716,30 @@ function openPlayer (torrentSummary, index, cb) {
|
|||||||
// otherwise, play the video
|
// otherwise, play the video
|
||||||
state.window.title = torrentSummary.name
|
state.window.title = torrentSummary.name
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
ipcRenderer.send('onPlayerOpen')
|
||||||
|
|
||||||
cb()
|
cb()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closePlayer (cb) {
|
||||||
|
state.window.title = config.APP_WINDOW_TITLE
|
||||||
|
update()
|
||||||
|
|
||||||
|
if (state.window.isFullScreen) {
|
||||||
|
dispatch('toggleFullScreen', false)
|
||||||
|
}
|
||||||
|
restoreBounds()
|
||||||
|
stopServer()
|
||||||
|
update()
|
||||||
|
|
||||||
|
ipcRenderer.send('unblockPowerSave')
|
||||||
|
ipcRenderer.send('onPlayerClose')
|
||||||
|
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
function openFile (torrentSummary, index) {
|
function openFile (torrentSummary, index) {
|
||||||
var torrent = state.client.get(torrentSummary.infoHash)
|
var torrent = state.client.get(torrentSummary.infoHash)
|
||||||
if (!torrent) return
|
if (!torrent) return
|
||||||
@@ -743,22 +763,6 @@ function openFolder (torrentSummary) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function closePlayer (cb) {
|
|
||||||
state.window.title = config.APP_WINDOW_TITLE
|
|
||||||
update()
|
|
||||||
|
|
||||||
if (state.window.isFullScreen) {
|
|
||||||
dispatch('toggleFullScreen', false)
|
|
||||||
}
|
|
||||||
restoreBounds()
|
|
||||||
stopServer()
|
|
||||||
update()
|
|
||||||
|
|
||||||
ipcRenderer.send('unblockPowerSave')
|
|
||||||
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleTorrent (torrentSummary) {
|
function toggleTorrent (torrentSummary) {
|
||||||
if (torrentSummary.status === 'paused') {
|
if (torrentSummary.status === 'paused') {
|
||||||
torrentSummary.status = 'new'
|
torrentSummary.status = 'new'
|
||||||
|
|||||||
Reference in New Issue
Block a user