Playback menu: Add "Play/Pause" item
The goal here is to remove shortcut handling from the renderer and unify it all in menu.js and shortcuts.ks (for alternate shortcuts). I would rather name it "Play" and change to "Pause" when video is playing, but Electron doesn't support this (yet).
This commit is contained in:
50
main/menu.js
50
main/menu.js
@@ -49,18 +49,6 @@ 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 () {
|
||||||
log('toggleDevTools')
|
log('toggleDevTools')
|
||||||
if (windows.main) {
|
if (windows.main) {
|
||||||
@@ -73,6 +61,24 @@ function showWebTorrentWindow () {
|
|||||||
windows.webtorrent.webContents.openDevTools({ detach: true })
|
windows.webtorrent.webContents.openDevTools({ detach: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function playPause () {
|
||||||
|
if (windows.main) {
|
||||||
|
windows.main.send('dispatch', 'playPause')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 onWindowShow () {
|
function onWindowShow () {
|
||||||
log('onWindowShow')
|
log('onWindowShow')
|
||||||
getMenuItem('Full Screen').enabled = true
|
getMenuItem('Full Screen').enabled = true
|
||||||
@@ -86,11 +92,15 @@ function onWindowHide () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onPlayerOpen () {
|
function onPlayerOpen () {
|
||||||
|
log('onPlayerOpen')
|
||||||
|
getMenuItem('Play/Pause').enabled = true
|
||||||
getMenuItem('Increase Volume').enabled = true
|
getMenuItem('Increase Volume').enabled = true
|
||||||
getMenuItem('Decrease Volume').enabled = true
|
getMenuItem('Decrease Volume').enabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPlayerClose () {
|
function onPlayerClose () {
|
||||||
|
log('onPlayerClose')
|
||||||
|
getMenuItem('Play/Pause').enabled = false
|
||||||
getMenuItem('Increase Volume').enabled = false
|
getMenuItem('Increase Volume').enabled = false
|
||||||
getMenuItem('Decrease Volume').enabled = false
|
getMenuItem('Decrease Volume').enabled = false
|
||||||
}
|
}
|
||||||
@@ -182,7 +192,9 @@ function getAppMenuTemplate () {
|
|||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: process.platform === 'windows' ? 'Close' : 'Close Window',
|
label: process.platform === 'windows'
|
||||||
|
? 'Close'
|
||||||
|
: 'Close Window',
|
||||||
accelerator: 'CmdOrCtrl+W',
|
accelerator: 'CmdOrCtrl+W',
|
||||||
role: 'close'
|
role: 'close'
|
||||||
}
|
}
|
||||||
@@ -256,6 +268,15 @@ function getAppMenuTemplate () {
|
|||||||
{
|
{
|
||||||
label: 'Playback',
|
label: 'Playback',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Play/Pause',
|
||||||
|
accelerator: 'CmdOrCtrl+P',
|
||||||
|
click: playPause,
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Increase Volume',
|
label: 'Increase Volume',
|
||||||
accelerator: 'CmdOrCtrl+Up',
|
accelerator: 'CmdOrCtrl+Up',
|
||||||
@@ -378,7 +399,8 @@ function getAppMenuTemplate () {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Add "File > Quit" menu item for Linux distros where the system tray is broken
|
// Add "File > Quit" menu item so Linux distros where the system tray icon is missing
|
||||||
|
// will have a way to quit the app.
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
// File menu (Linux)
|
// File menu (Linux)
|
||||||
template[0].push({
|
template[0].push({
|
||||||
|
|||||||
@@ -13,17 +13,17 @@ var menu = require('./menu')
|
|||||||
var windows = require('./windows')
|
var windows = require('./windows')
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
// ⌘+Shift+F is an alternative fullscreen shortcut to the ones defined in menu.js.
|
// Register alternate shortcuts here. Most shortcuts are registered in menu,js, but Electron does not support multiple shortcuts for a single menu item.
|
||||||
// Electron does not support multiple accelerators for a single menu item, so this
|
|
||||||
// is registered separately here.
|
|
||||||
localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen)
|
localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen)
|
||||||
|
localShortcut.register('Space', () => windows.main.send('dispatch', 'playPause'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPlayerOpen () {
|
function onPlayerOpen () {
|
||||||
// Register special "media key" for play/pause, available on some keyboards
|
// Register special "media key" for play/pause, available on some keyboards
|
||||||
globalShortcut.register('MediaPlayPause', function () {
|
globalShortcut.register(
|
||||||
windows.main.send('dispatch', 'playPause')
|
'MediaPlayPause',
|
||||||
})
|
() => windows.main.send('dispatch', 'playPause')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPlayerClose () {
|
function onPlayerClose () {
|
||||||
|
|||||||
@@ -1155,8 +1155,6 @@ function onKeyDown (e) {
|
|||||||
} else {
|
} else {
|
||||||
dispatch('back')
|
dispatch('back')
|
||||||
}
|
}
|
||||||
} else if (e.which === 32) { /* spacebar pauses or plays the video */
|
|
||||||
dispatch('playPause')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user