keeweb/app/scripts/comp/focus-detector.js

24 lines
691 B
JavaScript
Raw Normal View History

2019-01-14 19:05:16 +01:00
const FeatureDetector = require('../util/feature-detector');
const Launcher = require('../comp/launcher');
const FocusDetector = function () {
2019-01-14 19:05:16 +01:00
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 () {
2019-01-14 19:05:16 +01:00
if (this.detectsFocusWithEvents) {
return this.isFocused;
2019-01-14 19:05:16 +01:00
} else if (Launcher) {
return Launcher.isAppFocused();
2019-01-14 19:05:16 +01:00
} else {
return true;
}
};
module.exports = FocusDetector;