From b2bea6c234f6200f85c70c6f48ef43fed8e8c791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baumho=CC=88ver?= Date: Sun, 28 Feb 2016 09:41:16 +0100 Subject: [PATCH 1/6] added support for copying url with cmd/ctrl+u --- app/scripts/views/details/details-view.js | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/scripts/views/details/details-view.js b/app/scripts/views/details/details-view.js index d41e7109..bca21d99 100644 --- a/app/scripts/views/details/details-view.js +++ b/app/scripts/views/details/details-view.js @@ -34,6 +34,7 @@ var DetailsView = Backbone.View.extend({ views: null, passEditView: null, userEditView: null, + urlEditView: null, addNewFieldView: null, fieldCopyTip: null, @@ -58,6 +59,7 @@ var DetailsView = Backbone.View.extend({ this.listenTo(Backbone, 'select-entry', this.showEntry); 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); KeyHandler.onKey(Keys.DOM_VK_DELETE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); KeyHandler.onKey(Keys.DOM_VK_BACK_SPACE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); }, @@ -124,8 +126,9 @@ var DetailsView = Backbone.View.extend({ this.passEditView = new FieldViewText({ model: { name: '$Password', title: Locale.detPassword, canGen: true, value: function() { return model.password; } } }); this.fieldViews.push(this.passEditView); - this.fieldViews.push(new FieldViewUrl({ model: { name: '$URL', title: Locale.detWebsite, - value: function() { return model.url; } } })); + this.urlEditView = new FieldViewUrl({ model: { name: '$URL', title: Locale.detWebsite, + value: function() { return model.url; } } }); + this.fieldViews.push(this.urlEditView); this.fieldViews.push(new FieldViewText({ model: { name: '$Notes', title: Locale.detNotes, multiline: 'true', value: function() { return model.notes; } } })); this.fieldViews.push(new FieldViewTags({ model: { name: 'Tags', title: Locale.detTags, tags: this.appModel.tags, @@ -307,6 +310,23 @@ var DetailsView = Backbone.View.extend({ } } }, + + copyUrlKeyPress: function() { + if (!window.getSelection().toString()) { + var urlField = this.model.url; + var url = urlField.isProtected ? urlField.getText() : urlField; + if (!url) { + return; + } + if (!CopyPaste.simpleCopy) { + CopyPaste.createHiddenInput(url); + } + var copyRes = CopyPaste.copy(url); + if (copyRes) { + this.fieldCopied({ source: this.urlEditView, copyRes: copyRes }); + } + } + }, showCopyTip: function() { if (this.helpTipCopyShown) { From 7e4c1f186d4a6c185f8b48fd244f549110ac1dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baumho=CC=88ver?= Date: Sun, 28 Feb 2016 10:34:14 +0100 Subject: [PATCH 2/6] 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) --- app/scripts/views/details/details-view.js | 3 +++ electron/app.js | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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'); + } +} From cc8b1ef92b3aa6f02ff0bf36d7ece0464b74ac0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baumho=CC=88ver?= Date: Sun, 28 Feb 2016 12:47:47 +0100 Subject: [PATCH 3/6] support for electron global keyboard shortcuts on non OSX platforms: Shift+Alt+(c/b/u) --- electron/app.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/electron/app.js b/electron/app.js index 3cae41f0..efeb80d7 100644 --- a/electron/app.js +++ b/electron/app.js @@ -46,9 +46,17 @@ 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'); + if (process.platform === 'darwin') { + createGlobalShortcut('Ctrl+Alt+B', 'copy-user'); + createGlobalShortcut('Ctrl+Alt+C', 'copy-password'); + createGlobalShortcut('Ctrl+Alt+U', 'copy-url'); + } + else + { + createGlobalShortcut('Shift+Alt+B', 'copy-user'); + createGlobalShortcut('Shift+Alt+C', 'copy-password'); + createGlobalShortcut('Shift+Alt+U', 'copy-url'); + } createMainWindow(); }); app.on('open-file', function(e, path) { From b3e1d0fd709d37940a300344fc68857cb7deacd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baumho=CC=88ver?= Date: Sun, 28 Feb 2016 13:14:26 +0100 Subject: [PATCH 4/6] url keyboardshortcut deregister on remove --- app/scripts/views/details/details-view.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/scripts/views/details/details-view.js b/app/scripts/views/details/details-view.js index bca21d99..23cd0dd0 100644 --- a/app/scripts/views/details/details-view.js +++ b/app/scripts/views/details/details-view.js @@ -67,6 +67,7 @@ var DetailsView = Backbone.View.extend({ remove: function() { KeyHandler.offKey(Keys.DOM_VK_C, this.copyKeyPress, this); KeyHandler.offKey(Keys.DOM_VK_B, this.copyUserKeyPress, this); + KeyHandler.offKey(Keys.DOM_VK_U, this.copyUrlKeyPress, this); KeyHandler.offKey(Keys.DOM_VK_DELETE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); KeyHandler.offKey(Keys.DOM_VK_BACK_SPACE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); this.removeFieldViews(); From a7d00f8cfab8bca3a08400be119a4d24f5bf58ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baumho=CC=88ver?= Date: Sun, 28 Feb 2016 15:08:49 +0100 Subject: [PATCH 5/6] - refactored 3 copyKeyPress functions into one - added additional shortcut keys to settings-shortcuts.hbs - added locales for new shortcut keys - fixed code formatting issue --- app/scripts/util/locale.js | 4 ++ app/scripts/views/details/details-view.js | 60 ++++--------------- app/templates/settings/settings-shortcuts.hbs | 4 ++ electron/app.js | 15 ++--- 4 files changed, 25 insertions(+), 58 deletions(-) diff --git a/app/scripts/util/locale.js b/app/scripts/util/locale.js index 2a6159bf..ee0ddb0f 100644 --- a/app/scripts/util/locale.js +++ b/app/scripts/util/locale.js @@ -289,6 +289,7 @@ var Locale = { setShEntry: 'go to entry', setShCopyPass: 'copy password or selected field', setShCopyUser: 'copy username', + setShCopyUrl: 'copy url', setShPrev: 'go to previous item', setShNext: 'go to next item', setShCreateEntry: 'create entry', @@ -296,6 +297,9 @@ var Locale = { setShSave: 'save all files', setShGen: 'generate password', setShSet: 'app settings', + setShCopyPassGlobal: 'copy password global (works when app is in background)', + setShCopyUserGlobal: 'copy username global (works when app is in background)', + setShCopyUrlGlobal: 'copy url global (works when app is in background)', setAboutTitle: 'About', setAboutBuilt: 'This app is built with these awesome tools', diff --git a/app/scripts/views/details/details-view.js b/app/scripts/views/details/details-view.js index f7edd16d..936aff14 100644 --- a/app/scripts/views/details/details-view.js +++ b/app/scripts/views/details/details-view.js @@ -57,12 +57,12 @@ 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); + this.listenTo(Backbone, 'copy-password', function() { this.copyKeyPress(this.passEditView); } ); + this.listenTo(Backbone, 'copy-user', function() { this.copyKeyPress(this.userEditView); } ); + this.listenTo(Backbone, 'copy-url', function() { this.copyKeyPress(this.urlEditView); } ); + KeyHandler.onKey(Keys.DOM_VK_C, function() { this.copyKeyPress(this.passEditView); }, this, KeyHandler.SHORTCUT_ACTION, false, true); + KeyHandler.onKey(Keys.DOM_VK_B, function() { this.copyKeyPress(this.userEditView); }, this, KeyHandler.SHORTCUT_ACTION, false, true); + KeyHandler.onKey(Keys.DOM_VK_U, function() { this.copyKeyPress(this.urlEditView); }, this, KeyHandler.SHORTCUT_ACTION, false, true); KeyHandler.onKey(Keys.DOM_VK_DELETE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); KeyHandler.onKey(Keys.DOM_VK_BACK_SPACE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); }, @@ -281,57 +281,23 @@ var DetailsView = Backbone.View.extend({ } }, - copyKeyPress: function() { // TODO: fix this in Safari + copyKeyPress: function(editView) { if (!window.getSelection().toString()) { - var pw = this.model.password; - var password = pw.isProtected ? pw.getText() : pw; - if (!password) { + var field = editView.value; + var fieldText = field.isProtected ? field.getText() : field; + if (!fieldText) { return; } if (!CopyPaste.simpleCopy) { - CopyPaste.createHiddenInput(password); + CopyPaste.createHiddenInput(fieldText); } - var copyRes = CopyPaste.copy(password); + var copyRes = CopyPaste.copy(fieldText); if (copyRes) { - this.fieldCopied({ source: this.passEditView, copyRes: copyRes }); - } - } - }, - - copyUserKeyPress: function() { - if (!window.getSelection().toString()) { - var userField = this.model.user; - var user = userField.isProtected ? userField.getText() : userField; - if (!user) { - return; - } - if (!CopyPaste.simpleCopy) { - CopyPaste.createHiddenInput(user); - } - var copyRes = CopyPaste.copy(user); - if (copyRes) { - this.fieldCopied({ source: this.userEditView, copyRes: copyRes }); + this.fieldCopied({ source: editView, copyRes: copyRes }); } } }, - copyUrlKeyPress: function() { - if (!window.getSelection().toString()) { - var urlField = this.model.url; - var url = urlField.isProtected ? urlField.getText() : urlField; - if (!url) { - return; - } - if (!CopyPaste.simpleCopy) { - CopyPaste.createHiddenInput(url); - } - var copyRes = CopyPaste.copy(url); - if (copyRes) { - this.fieldCopied({ source: this.urlEditView, copyRes: copyRes }); - } - } - }, - showCopyTip: function() { if (this.helpTipCopyShown) { return; diff --git a/app/templates/settings/settings-shortcuts.hbs b/app/templates/settings/settings-shortcuts.hbs index 52e7ae0f..968b681b 100644 --- a/app/templates/settings/settings-shortcuts.hbs +++ b/app/templates/settings/settings-shortcuts.hbs @@ -8,6 +8,7 @@
{{res 'setShEntry'}}
{{{cmd}}}C {{res 'setShCopyPass'}}
{{{cmd}}}B {{res 'setShCopyUser'}}
+
{{{cmd}}}U {{res 'setShCopyUrl'}}
{{res 'setShPrev'}}
{{res 'setShNext'}}
{{{alt}}}N {{res 'setShCreateEntry'}}
@@ -15,4 +16,7 @@
{{{cmd}}}S {{res 'setShSave'}}
{{{cmd}}}G {{res 'setShGen'}}
{{{cmd}}}, {{res 'setShSet'}}
+
{{{ctrl}}}{{{alt}}}C {{res 'setShCopyPassGlobal'}}
+
{{{ctrl}}}{{{alt}}}B {{res 'setShCopyUserGlobal'}}
+
{{{ctrl}}}{{{alt}}}U {{res 'setShCopyUrlGlobal'}}
diff --git a/electron/app.js b/electron/app.js index efeb80d7..5c60ebfd 100644 --- a/electron/app.js +++ b/electron/app.js @@ -50,9 +50,7 @@ app.on('ready', function() { createGlobalShortcut('Ctrl+Alt+B', 'copy-user'); createGlobalShortcut('Ctrl+Alt+C', 'copy-password'); createGlobalShortcut('Ctrl+Alt+U', 'copy-url'); - } - else - { + } else { createGlobalShortcut('Shift+Alt+B', 'copy-user'); createGlobalShortcut('Shift+Alt+C', 'copy-password'); createGlobalShortcut('Shift+Alt+U', 'copy-url'); @@ -72,7 +70,7 @@ app.on('activate', function() { } }); app.on('will-quit', function() { - globalShortcut.unregisterAll(); + globalShortcut.unregisterAll(); }); app.restartApp = function() { restartPending = true; @@ -252,13 +250,8 @@ function notifyOpenFile() { } } -function createGlobalShortcut(shortcut, backboneEventname) -{ - var ret = globalShortcut.register(shortcut, function() { +function createGlobalShortcut(shortcut, backboneEventname) { + globalShortcut.register(shortcut, function() { emitBackboneEvent(backboneEventname); }); - - if (!ret) { - console.log('registration failed'); - } } From 73c334191b15b0698d2a2e2bb6988d7bcb07f81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baumho=CC=88ver?= Date: Sun, 28 Feb 2016 16:15:28 +0100 Subject: [PATCH 6/6] fixed unsubscribe offkey calls --- app/scripts/views/details/details-view.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/views/details/details-view.js b/app/scripts/views/details/details-view.js index 936aff14..3a42e63e 100644 --- a/app/scripts/views/details/details-view.js +++ b/app/scripts/views/details/details-view.js @@ -68,9 +68,9 @@ var DetailsView = Backbone.View.extend({ }, remove: function() { - KeyHandler.offKey(Keys.DOM_VK_C, this.copyKeyPress, this); - KeyHandler.offKey(Keys.DOM_VK_B, this.copyUserKeyPress, this); - KeyHandler.offKey(Keys.DOM_VK_U, this.copyUrlKeyPress, this); + KeyHandler.offKey(Keys.DOM_VK_C, function() { this.copyKeyPress(this.passEditView); }, this); + KeyHandler.offKey(Keys.DOM_VK_B, function() { this.copyKeyPress(this.userEditView); }, this); + KeyHandler.offKey(Keys.DOM_VK_U, function() { this.copyKeyPress(this.urlEditView); }, this); KeyHandler.offKey(Keys.DOM_VK_DELETE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); KeyHandler.offKey(Keys.DOM_VK_BACK_SPACE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION); this.removeFieldViews();