added support for electron global keyboard shortcuts, copy contents to clipboard without having to refocus the app, supported shortcuts are: Ctrl+Alt+(c/b/u) (password/user/url)

This commit is contained in:
Tobias Baumhöver 2016-02-28 10:34:14 +01:00
parent b2bea6c234
commit 7e4c1f186d
2 changed files with 23 additions and 1 deletions

View File

@ -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);

View File

@ -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');
}
}