Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fallback for the time tracking in the web #927

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

CryZe
Copy link
Collaborator

@CryZe CryZe commented Jun 9, 2024

Every browser's performance.now() implementation is not spec compliant, unless the browser is running on Windows. On every other operating system, performance.now() does not properly keep ticking while the operating system is suspended / sleeping. There isn't much that we can do. What we can do is we calculate the initial difference between performance.now() and Date.now() and store it in a thread local. Later, when the phone gets locked, performance.now() starts to break. However, we can detect when the phone gets unlocked again by listening to the visibilitychange event. This is where we can update the difference again. This of course isn't ideal, as Date.now() gets adjusted by NTP synchronizations, but it's the best we can do.

More information:
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#ticking_during_sleep https://www.igvita.com/2015/11/20/dont-lose-user-and-app-state-use-page-visibility/

Every browser's `performance.now()` implementation is not spec
compliant, unless the browser is running on Windows. On every other
operating system, `performance.now()` does not properly keep ticking
while the operating system is suspended / sleeping. There isn't much
that we can do. What we can do is we calculate the initial difference
between `performance.now()` and `Date.now()` and store it in a thread
local. Later, when the phone gets locked, `performance.now()` starts to
break. However, we can detect when the phone gets unlocked again by
listening to the `visibilitychange` event. This is where we can update
the difference again. This of course isn't ideal, as `Date.now()` gets
adjusted by NTP synchronizations, but it's the best we can do.

More information:
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#ticking_during_sleep
https://www.igvita.com/2015/11/20/dont-lose-user-and-app-state-use-page-visibility/
@CryZe CryZe added bug There's a bug in LiveSplit One. enhancement A new feature or general improvement to LiveSplit One. high priority This is a high priority issue. labels Jun 9, 2024
@CryZe CryZe linked an issue Jun 9, 2024 that may be closed by this pull request
@CryZe CryZe merged commit 3b32a7b into LiveSplit:master Jun 9, 2024
1 check passed
@CryZe CryZe changed the title Add a fallback for the time tracking in the web (#814) Add a fallback for the time tracking in the web Jun 9, 2024
@CryZe CryZe deleted the web-time-fallback branch June 9, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There's a bug in LiveSplit One. enhancement A new feature or general improvement to LiveSplit One. high priority This is a high priority issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time is extremely inaccurate if phone goes to asleep
1 participant