1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-21 07:06:39 +02:00

Only focuses input field when app or browser is active on lock. Fixes #423

This commit is contained in:
Dennis Ploeger 2019-01-13 19:39:37 +01:00 committed by antelle
parent da922d2216
commit 29a250d16f
2 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,11 @@
const BrowserFocus = function () {
this.isFocused = false;
window.onblur = function () { this.isFocused = false; }.bind(this);
window.onfocus = function () { this.isFocused = true; }.bind(this);
};
BrowserFocus.prototype.hasFocus = function () {
return this.isFocused;
};
module.exports = BrowserFocus;

View File

@ -15,6 +15,7 @@ const InputFx = require('../util/input-fx');
const Comparators = require('../util/comparators');
const Storage = require('../storage');
const Launcher = require('../comp/launcher');
const BrowserFocus = require('../util/browser-focus');
const logger = new Logger('open-view');
@ -69,6 +70,9 @@ const OpenView = Backbone.View.extend({
KeyHandler.onKey(Keys.DOM_VK_RETURN, this.enterKeyPress, this);
KeyHandler.onKey(Keys.DOM_VK_DOWN, this.moveOpenFileSelectionDown, this);
KeyHandler.onKey(Keys.DOM_VK_UP, this.moveOpenFileSelectionUp, this);
if (!FeatureDetector.isDesktop) {
this.browserFocus = new BrowserFocus();
}
},
render: function () {
@ -107,7 +111,12 @@ const OpenView = Backbone.View.extend({
focusInput: function() {
if (!FeatureDetector.isMobile) {
this.inputEl.focus();
if (
(FeatureDetector.isDesktop && Launcher.isAppFocused()) ||
(this.browserFocus.hasFocus())
) {
this.inputEl.focus();
}
}
},