From 7eeda57b57af70e85ed1ca63140d8b30ea51dbf4 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 5 Mar 2016 17:05:41 -0800 Subject: [PATCH 1/2] =?UTF-8?q?Add=20alternate=20fullscreen=20shortcut=20?= =?UTF-8?q?=E2=8C=98+Shift+F=20(fix=20#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses https://npmjs.com/package/electron-localshortcut to workaround a bug in Electron (https://github.com/atom/electron/issues/1334). We can remove `electron-localshortcut` once that bug is fixed. --- main/index.js | 2 ++ main/ipc.js | 8 ++++---- main/menu.js | 5 +++-- main/shortcuts.js | 13 +++++++++++++ package.json | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 main/shortcuts.js diff --git a/main/index.js b/main/index.js index 709569dd..71adf749 100644 --- a/main/index.js +++ b/main/index.js @@ -4,6 +4,7 @@ var electron = require('electron') var ipc = require('./ipc') var menu = require('./menu') var windows = require('./windows') +var shortcuts = require('./shortcuts') var app = electron.app @@ -15,6 +16,7 @@ app.on('open-url', onOpen) app.on('ready', function () { electron.Menu.setApplicationMenu(menu.appMenu) windows.createMainWindow(menu) + shortcuts.init(menu) }) app.on('activate', function () { diff --git a/main/ipc.js b/main/ipc.js index 08e3259e..a61da263 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -1,12 +1,12 @@ +module.exports = { + init: init +} + var electron = require('electron') var debug = require('debug')('webtorrent-app:ipcMain') var ipcMain = electron.ipcMain var windows = require('./windows') -module.exports = { - init: init -} - function init () { ipcMain.on('addTorrentFromPaste', function (e) { addTorrentFromPaste() diff --git a/main/menu.js b/main/menu.js index 9a64d852..a4a62e92 100644 --- a/main/menu.js +++ b/main/menu.js @@ -18,7 +18,7 @@ function onWindowHide () { function toggleFullScreen () { debug('toggleFullScreen') - if (windows.main) { + if (windows.main && windows.main.isVisible()) { windows.main.setFullScreen(!windows.main.isFullScreen()) } } @@ -289,7 +289,8 @@ var menu = { appMenu: appMenu, onToggleFullScreen: onToggleFullScreen, onWindowHide: onWindowHide, - onWindowShow: onWindowShow + onWindowShow: onWindowShow, + toggleFullScreen: toggleFullScreen } module.exports = menu diff --git a/main/shortcuts.js b/main/shortcuts.js new file mode 100644 index 00000000..41491327 --- /dev/null +++ b/main/shortcuts.js @@ -0,0 +1,13 @@ +module.exports = { + init: init +} + +var electron = require('electron') +var localShortcut = require('electron-localshortcut') + +function init (menu) { + // ⌘+Shift+F is an alternative fullscreen shortcut to the one 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) +} diff --git a/package.json b/package.json index c1af0668..f701626f 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "create-torrent": "^3.22.1", "debug": "^2.2.0", "drag-drop": "^2.3.1", + "electron-localshortcut": "^0.6.0", "hyperx": "^2.0.0", "main-loop": "^3.2.0", "network-address": "^1.1.0", From beca43029d2dba279b969d533f71f4ad47cff25a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 5 Mar 2016 17:08:46 -0800 Subject: [PATCH 2/2] standard --- main/shortcuts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/main/shortcuts.js b/main/shortcuts.js index 41491327..d40849f1 100644 --- a/main/shortcuts.js +++ b/main/shortcuts.js @@ -2,7 +2,6 @@ module.exports = { init: init } -var electron = require('electron') var localShortcut = require('electron-localshortcut') function init (menu) {