diff --git a/main/ipc.js b/main/ipc.js index 8ec80b94..075c9ed1 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -23,13 +23,8 @@ function init () { app.emit('ipcReady') }) - ipcMain.on('showOpenTorrentFile', function (e) { - menu.showOpenTorrentFile() - }) - - ipcMain.on('showCreateTorrent', function (e) { - menu.showCreateTorrent() - }) + ipcMain.on('showOpenTorrentFile', menu.showOpenTorrentFile) + ipcMain.on('showCreateTorrent', menu.showCreateTorrent) ipcMain.on('setBounds', function (e, bounds, maximize) { setBounds(bounds, maximize) @@ -62,6 +57,9 @@ function init () { ipcMain.on('blockPowerSave', blockPowerSave) ipcMain.on('unblockPowerSave', unblockPowerSave) + + ipcMain.on('onPlayerOpen', menu.onPlayerOpen) + ipcMain.on('onPlayerClose', menu.onPlayerClose) } function setBounds (bounds, maximize) { diff --git a/main/menu.js b/main/menu.js index 6aa9583e..853812cc 100644 --- a/main/menu.js +++ b/main/menu.js @@ -3,6 +3,8 @@ module.exports = { onToggleFullScreen, onWindowHide, onWindowShow, + onPlayerOpen, + onPlayerClose, showCreateTorrent, showOpenTorrentFile, 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 () { debug('toggleDevTools') if (windows.main) { @@ -75,6 +89,16 @@ function onWindowHide () { 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) { isFullScreen = isFullScreen != null ? isFullScreen : windows.main.isFullScreen() windows.main.setMenuBarVisibility(!isFullScreen) @@ -196,6 +220,21 @@ function getAppMenuTemplate () { { 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', submenu: [ diff --git a/main/shortcuts.js b/main/shortcuts.js index abe4698a..7af1f6ff 100644 --- a/main/shortcuts.js +++ b/main/shortcuts.js @@ -18,8 +18,4 @@ function init () { // Electron does not support multiple accelerators for a single menu item, so this // is registered separately here. 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)) } diff --git a/renderer/index.js b/renderer/index.js index 0dd9b3ee..dc177cf3 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -716,10 +716,30 @@ function openPlayer (torrentSummary, index, cb) { // otherwise, play the video state.window.title = torrentSummary.name update() + + ipcRenderer.send('onPlayerOpen') + 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) { var torrent = state.client.get(torrentSummary.infoHash) 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) { if (torrentSummary.status === 'paused') { torrentSummary.status = 'new'