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

Fix wakelock bug - reacquire lock when refocusing tab #450

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

morteako
Copy link
Collaborator

@morteako morteako commented Nov 30, 2024

Current issue with wakelock is related to the wakelock releasing when changing tabs.
Then the wakelock is released.
And we never reacquire it.
This adds an event listener to document.visibilitystate and reacquires the lock when needed

This pr also moves the wakelock-code into a seperate WakeLockContext to avoid cluttering the datacontext code.
Not sure if this use of Context is "normal", but seems ok.
Ofc open to other suggestions, but i feel like this stuff should not be in DataContext at least.

Testing

Tested a lot with console.log on PC, seems to work.

Works on android phone.

Testing on this PC is a bit chaotic due to a minimum 5 minute screensaver, but i will try

Gifs

Added some gifs with a hacky overriding of the HR to display if wakelocked or not 🤠

2024-11-30 12 50 46

2024-11-30 12 50 30

Copy link
Owner

@sivertschou sivertschou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! 🙌

@morteako morteako merged commit 79d247d into main Dec 10, 2024
3 checks passed
@morteako morteako deleted the fix-wakelock-bug branch December 10, 2024 18:20
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.

2 participants