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