focusdetector static

This commit is contained in:
antelle 2019-01-21 20:52:40 +01:00
parent 44528a40b7
commit 8cc80dbd69
3 changed files with 22 additions and 17 deletions

View File

@ -18,6 +18,7 @@ const SettingsManager = require('./comp/settings-manager');
const PluginManager = require('./plugins/plugin-manager');
const Launcher = require('./comp/launcher');
const FeatureTester = require('./comp/feature-tester');
const FocusDetector = require('./comp/focus-detector');
const Timeouts = require('./const/timeouts');
const FeatureDetector = require('./util/feature-detector');
const KdbxwebInit = require('./util/kdbxweb-init');
@ -76,6 +77,7 @@ ready(() => {
IdleTracker.init();
PopupNotifier.init();
KdbxwebInit.init();
FocusDetector.init();
window.kw = ExportApi;
return PluginManager.init();
}

View File

@ -1,22 +1,24 @@
const FeatureDetector = require('../util/feature-detector');
const Launcher = require('../comp/launcher');
const FocusDetector = function () {
this.isFocused = true;
this.detectsFocusWithEvents = !FeatureDetector.isDesktop && !FeatureDetector.isMobile;
if (this.detectsFocusWithEvents) {
window.onblur = () => { this.isFocused = false; };
window.onfocus = () => { this.isFocused = true; };
}
};
const FocusDetector = {
init() {
this.isFocused = true;
this.detectsFocusWithEvents = !FeatureDetector.isDesktop && !FeatureDetector.isMobile;
if (this.detectsFocusWithEvents) {
window.onblur = () => { this.isFocused = false; };
window.onfocus = () => { this.isFocused = true; };
}
},
FocusDetector.prototype.hasFocus = function () {
if (this.detectsFocusWithEvents) {
return this.isFocused;
} else if (Launcher) {
return Launcher.isAppFocused();
} else {
return true;
hasFocus() {
if (this.detectsFocusWithEvents) {
return this.isFocused;
} else if (Launcher) {
return Launcher.isAppFocused();
} else {
return true;
}
}
};

View File

@ -69,7 +69,6 @@ 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);
this.focusDetector = new FocusDetector();
},
render: function () {
@ -107,7 +106,9 @@ const OpenView = Backbone.View.extend({
},
focusInput: function() {
if (this.focusDetector.hasFocus()) {
console.log('focus');
if (FocusDetector.hasFocus()) {
console.log('hasFocus');
this.inputEl.focus();
}
},