Skip to content
Permalink
Browse files

FIX: change focus when application resumes in android

Per new lifecycle https://developers.google.com/web/updates/2018/07/page-lifecycle-api

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.
  • Loading branch information...
SamSaffron committed Oct 1, 2019
1 parent 5cfbe19 commit 499472b6a0e9bd0cef4539287e9845476938cf01
Showing with 4 additions and 0 deletions.
  1. +4 −0 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;
}

2 comments on commit 499472b

@discoursebot

This comment has been minimized.

Copy link

replied Oct 1, 2019

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

https://meta.discourse.org/t/topics-incorrectly-stuck-in-unread-state-on-android-in-chrome-77/129907/1

@discoursebot

This comment has been minimized.

Copy link

replied Oct 7, 2019

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

https://meta.discourse.org/t/unread-read-messages-not-stored-correctly-on-android-chrome/130435/2

Please sign in to comment.
You can’t perform that action at this time.