From 0cf89600c01da84409410ea0d1ccc5077b5f1307 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 25 Mar 2016 23:49:04 -0700 Subject: [PATCH 1/2] es6ify --- main/ipc.js | 2 +- main/menu.js | 14 +++++++------- main/shortcuts.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main/ipc.js b/main/ipc.js index 9439d973..8ec80b94 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -1,5 +1,5 @@ module.exports = { - init: init + init } var debug = require('debug')('webtorrent-app:ipcMain') diff --git a/main/menu.js b/main/menu.js index dc4eb038..6aa9583e 100644 --- a/main/menu.js +++ b/main/menu.js @@ -1,11 +1,11 @@ module.exports = { - init: init, - onToggleFullScreen: onToggleFullScreen, - onWindowHide: onWindowHide, - onWindowShow: onWindowShow, - showOpenTorrentFile: showOpenTorrentFile, - showCreateTorrent: showCreateTorrent, - toggleFullScreen: toggleFullScreen + init, + onToggleFullScreen, + onWindowHide, + onWindowShow, + showCreateTorrent, + showOpenTorrentFile, + toggleFullScreen } var debug = require('debug')('webtorrent-app:menu') diff --git a/main/shortcuts.js b/main/shortcuts.js index 589c9fa0..abe4698a 100644 --- a/main/shortcuts.js +++ b/main/shortcuts.js @@ -1,5 +1,5 @@ module.exports = { - init: init + init } var electron = require('electron') From 9ef1d0a6059b56e7a4910dcee8c32463eb3d3e49 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 26 Mar 2016 19:57:39 -0700 Subject: [PATCH 2/2] 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. --- main/ipc.js | 12 +++++------- main/menu.js | 39 +++++++++++++++++++++++++++++++++++++++ main/shortcuts.js | 4 ---- renderer/index.js | 36 ++++++++++++++++++++---------------- 4 files changed, 64 insertions(+), 27 deletions(-) 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'