2019-02-04 19:20:12 +01:00
|
|
|
const Backbone = require('backbone');
|
2019-09-15 08:47:57 +02:00
|
|
|
const Features = require('../../util/features');
|
|
|
|
const Launcher = require('../launcher');
|
2019-01-14 08:56:33 +01:00
|
|
|
|
2019-01-21 20:52:40 +01:00
|
|
|
const FocusDetector = {
|
|
|
|
init() {
|
|
|
|
this.isFocused = true;
|
2019-09-15 08:11:11 +02:00
|
|
|
this.detectsFocusWithEvents = !Features.isDesktop && !Features.isMobile;
|
2019-02-09 12:11:32 +01:00
|
|
|
if (this.detectsFocusWithEvents) {
|
|
|
|
window.addEventListener('focus', () => {
|
|
|
|
if (!FocusDetector.isFocused) {
|
|
|
|
FocusDetector.isFocused = true;
|
|
|
|
Backbone.trigger('main-window-focus');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
window.addEventListener('blur', () => {
|
|
|
|
if (FocusDetector.isFocused) {
|
|
|
|
FocusDetector.isFocused = false;
|
|
|
|
Backbone.trigger('main-window-blur');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-01-21 20:52:40 +01:00
|
|
|
},
|
2019-01-14 08:56:33 +01:00
|
|
|
|
2019-01-21 20:52:40 +01:00
|
|
|
hasFocus() {
|
|
|
|
if (this.detectsFocusWithEvents) {
|
|
|
|
return this.isFocused;
|
|
|
|
} else if (Launcher) {
|
|
|
|
return Launcher.isAppFocused();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-14 08:56:33 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = FocusDetector;
|