Skip to content

Commit

Permalink
Add alternate fullscreen shortcut ⌘+Shift+F (fix #26)
Browse files Browse the repository at this point in the history
Uses https://npmjs.com/package/electron-localshortcut to workaround a
bug in Electron (electron/electron#1334).

We can remove `electron-localshortcut` once that bug is fixed.
  • Loading branch information
feross committed Mar 6, 2016
1 parent a38b278 commit f6c9750
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 () {
Expand Down
8 changes: 4 additions & 4 deletions main/ipc.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
5 changes: 3 additions & 2 deletions main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var app = electron.app

function toggleFullScreen () {
debug('toggleFullScreen')
if (windows.main) {
if (windows.main && windows.main.isVisible()) {
windows.main.setFullScreen(!windows.main.isFullScreen())
}
}
Expand Down Expand Up @@ -275,7 +275,8 @@ var appMenu = electron.Menu.buildFromTemplate(getMenuTemplate())

var menu = {
appMenu: appMenu,
onToggleFullScreen: onToggleFullScreen
onToggleFullScreen: onToggleFullScreen,
toggleFullScreen: toggleFullScreen
}

module.exports = menu
13 changes: 13 additions & 0 deletions main/shortcuts.js
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f6c9750

Please sign in to comment.