mirror of https://github.com/keeweb/keeweb.git
focusdetector static
This commit is contained in:
parent
ddf5b39872
commit
3c105c6091
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue