diff --git a/app/scripts/views/details/details-view.js b/app/scripts/views/details/details-view.js index bca21d99..9c655c6b 100644 --- a/app/scripts/views/details/details-view.js +++ b/app/scripts/views/details/details-view.js @@ -57,6 +57,9 @@ var DetailsView = Backbone.View.extend({ this.views = {}; this.initScroll(); this.listenTo(Backbone, 'select-entry', this.showEntry); + this.listenTo(Backbone, 'copy-password', this.copyKeyPress); + this.listenTo(Backbone, 'copy-user', this.copyUserKeyPress); + this.listenTo(Backbone, 'copy-url', this.copyUrlKeyPress); KeyHandler.onKey(Keys.DOM_VK_C, this.copyKeyPress, this, KeyHandler.SHORTCUT_ACTION, false, true); KeyHandler.onKey(Keys.DOM_VK_B, this.copyUserKeyPress, this, KeyHandler.SHORTCUT_ACTION, false, true); KeyHandler.onKey(Keys.DOM_VK_U, this.copyUrlKeyPress, this, KeyHandler.SHORTCUT_ACTION, false, true); diff --git a/electron/app.js b/electron/app.js index 7bc0042c..3cae41f0 100644 --- a/electron/app.js +++ b/electron/app.js @@ -8,7 +8,8 @@ var app = require('app'), fs = require('fs'), BrowserWindow = require('browser-window'), Menu = require('menu'), - Tray = require('tray'); + Tray = require('tray'), + globalShortcut = require('electron').globalShortcut; var mainWindow = null, appIcon = null, @@ -29,6 +30,7 @@ process.argv.forEach(function(arg) { app.on('window-all-closed', function() { if (restartPending) { // unbind all handlers, load new app.js module and pass control to it + globalShortcut.unregisterAll(); app.removeAllListeners('window-all-closed'); app.removeAllListeners('ready'); app.removeAllListeners('open-file'); @@ -44,6 +46,9 @@ app.on('window-all-closed', function() { } }); app.on('ready', function() { + createGlobalShortcut('Ctrl+Alt+B', 'copy-user'); + createGlobalShortcut('Ctrl+Alt+C', 'copy-password'); + createGlobalShortcut('Ctrl+Alt+U', 'copy-url'); createMainWindow(); }); app.on('open-file', function(e, path) { @@ -58,6 +63,9 @@ app.on('activate', function() { } } }); +app.on('will-quit', function() { + globalShortcut.unregisterAll(); +}); app.restartApp = function() { restartPending = true; mainWindow.close(); @@ -235,3 +243,14 @@ function notifyOpenFile() { openFile = null; } } + +function createGlobalShortcut(shortcut, backboneEventname) +{ + var ret = globalShortcut.register(shortcut, function() { + emitBackboneEvent(backboneEventname); + }); + + if (!ret) { + console.log('registration failed'); + } +}