FIX: change focus when application resumes in android

FIX: change focus when application resumes in android

Per new lifecycle Page Lifecycle API  |  Web  |  Google Developers

On Android and latest Chrome when an app transitions from “frozen” to active the new “resume” event fires with no accompanying “visibilitychange” event.

This means that often background tabs may be stuck thinking that discourse has no focus when, indeed, it has.

This leads to cases where no posts are marked read anymore.

diff --git a/app/assets/javascripts/discourse-common/mixins/focus-event.js.es6 b/app/assets/javascripts/discourse-common/mixins/focus-event.js.es6
index e9e5690..7aafebd 100644
--- a/app/assets/javascripts/discourse-common/mixins/focus-event.js.es6
+++ b/app/assets/javascripts/discourse-common/mixins/focus-event.js.es6
@@ -24,12 +24,16 @@ export default Ember.Mixin.create({
     Discourse.set("hasFocus", true);
 
     document.addEventListener("visibilitychange", onchange);
+    document.addEventListener("resume", onchange);
+    document.addEventListener("freeze", onchange);
   },
 
   reset() {
     this._super(...arguments);
 
     document.removeEventListener("visibilitychange", onchange);
+    document.removeEventListener("resume", onchange);
+    document.removeEventListener("freeze", onchange);
 
     onchange = undefined;
   }

GitHub sha: 67e8fbc4

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: