-
Notifications
You must be signed in to change notification settings - Fork 108
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
Fullscreen inhibit gets stuck due to a race condition #285
Comments
Thanks for troubleshooting this, I'll try to reproduce this and patch it :) EDIT: So thinking about this, there isn't really a lot that can be done for race conditions in JS, nearly any check we do might still slip through. Maybe we could give each inhibitor an ID as well, like 'fullscreen-1'. Then when 'fullscreen' is removed, it removes all instances of 'fullscreen-[any ID]'. That way a collision can't take place, and inhibitors can't be lost. |
I think I managed a similar issue with apps:
When an app toggle caffeine, it block the signal event for 200 ms: this avoid adding multiple inhibitors. I reckon it can be done for fullscreen inhibitor ? I will check that. |
Since we have no locking primitives in JS, it will probably still be possible to register duplicate entries. Still, it seems like a good approach, I don't see why it shouldn't work. Only semi-related, but I noticed the If you like the sound of that, I'll work on it soon :) EDIT: Whoops sorry if that sounded negative, I accidentally deleted the line where I agreed with you... |
After few test, I came up with a reset of the two second timer for each call of
I can make a PR tonight if you like this solution, it's seams to work fine and fix the issue in my test.
I think it's a good point, it make sense to create a specific class to manage inhibitors. It's something that can be done in a second time maybe but I like this idea. |
Good to hear it working, nice and simple fix :D |
Steps to reproduce:
Output:
By adding debug prints, I found out that
addInhibit('fullscreen')
can be called multiple times in a row, followed by only oneremoveInhibit('fullscreen')
. What I believe to be the root cause of the issue is thataddInhibit()
doesn't populatethis._appInhibitedData
right away, but only after the callback is called. Combined with a 2-second delay intoggleFullscreen()
, this means that this piece of code may be scheduled multiple times over a 2-second window, and when it comes to executing it,this._appInhibitedData.has('fullscreen')
will return false every time,addInhibit
will be called more than once, and only then its callback will kick in and populatethis._appInhibitedData
, effectively overwriting old cookies and not allowing to remove the inhibit anymore.The text was updated successfully, but these errors were encountered: