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

Reacquire wake lock as needed #1158

Merged
merged 2 commits into from
Jan 28, 2024

Conversation

DNin01
Copy link
Collaborator

@DNin01 DNin01 commented Nov 19, 2023

Resolves #1120

Currently, if you request a wake lock with the Wake Lock extension and then navigate away from the page, the wake lock gets released in the background because wake locks are automatically released when the document gets hidden, plus, the extension isn't aware of when this happens, so you have no way of knowing.

This change makes the extension automatically request another wake lock when the document regains visibility after having been hidden. It still reports to the project that the wake lock is enabled when this happens, therefore projects will act like nothing happened but the wake lock will still be there as long as you come back. I also considered the possibility of projects enabling or disabling wake lock when the document is hidden and now handle it properly.

I tested these changes in Edge to the best of my ability.

@DNin01
Copy link
Collaborator Author

DNin01 commented Nov 20, 2023

I also realized I didn't do anything about what happens when a wake lock is unexpectedly released. At that point, it still thinks that the wake lock is active. It's a little complicated to do while also making sure it gets reacquired if the user leaves and comes back because it leaves three possible states for the wake lock to be in: off, on, and will be reacquired when the document is visible again, but I have an idea.

@DNin01 DNin01 marked this pull request as draft November 20, 2023 23:33
@DNin01 DNin01 marked this pull request as ready for review November 20, 2023 23:49
@DNin01
Copy link
Collaborator Author

DNin01 commented Nov 20, 2023

Alright! It now detects when wake lock is released. The comment I added is a little confusing, basically what it's saying is that we know that if the document is hidden, that's the reason the wake lock was released and to reacquire it when the document is visible again, so if the wake lock is released while the document is visible, it must be for some other reason so we don't want to reacquire it automatically and we report the wake lock status as disabled.

@GarboMuffin
Copy link
Member

GarboMuffin commented Jan 28, 2024

sorry for delay, this is a bit annoying to test but I'll take your word on it

@GarboMuffin GarboMuffin merged commit db49c37 into TurboWarp:master Jan 28, 2024
3 checks passed
@DNin01 DNin01 deleted the auto-reacquire-wake-lock branch January 1, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Listen for wake lock release
2 participants