-
Notifications
You must be signed in to change notification settings - Fork 29
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
Promise for unlock()? #104
Comments
@mounirlamouri I’ve been going over the spec with @Johanna-hub and, given unlocking is “lock to the default” (even if there is no actual orientation change) I am starting to be convinced that returning a promise is actually the right thing to do here: if there is no actual change, we just return a resolved promise. Otherwise, wait for orientation change and we resolve the default promise. WDTY? |
It's been a few years but I would look into whether an implementation of this would be reliable on Android and iOS. On Android, unlock will get the app to ask the system to go back to its default orientation which the app doesn't know off hand. We should check whether this is easy to check but either way, there would be some reverse engineering of the Android system code to do in the UA which doesn't seem great. |
Hi guys, I opened this a while back when I was working at another company. As I recall the promise approach would have been nice as it matched up with the lock() method but I'm not sure anymore about that. My case was definitely an edge case at the time but would have been nice not to use the setTimeout hack :D |
Thanks @jjmax75 for following up. It's come up again in a different issue - hi @kenchris! could use your input here too.
Agree - we definitely don't want to go around poking at system code. However, we should check if since we first spec'ed this if the APIs have changed to provide a call back? @Johanna-hub, could you please research "Handling View Rotations" in iOS: And, on Android, @mounirlamouri, I wonder if for unlock we could still just call:
And just resolve the promise? The call at the Android level is synchronous anyway, by the looks of the documentation. |
I would really like these to return promises if possible - it is really brittle integrating this with fullscreen today. cc @dominickng |
I wonder if we have any visibility into the implementation of this in Chrome on Android? I'm guessing not. I'd be really interested to see how |
Gecko's one is here: Looking at |
@Johanna-hub and I went poking around the DOM implementation... basically And for whatever reason (probably the reason @mounirlamouri gave :)), the Hal definition of void UnlockScreenOrientation(); This doesn't seem to align with the Java side tho... which does return a boolean for unlock. Trying to find out more. |
Gecko bug... seeing if it's doable as we suspect this causing intermittent failures because of the interaction with exit fullscreen: https://bugzilla.mozilla.org/show_bug.cgi?id=1567805 |
How would you get confirmation from unlocking? |
I think it might be sufficient to just IPC over to Android and do the call to So, we would just return the promise here, instead of dropping it on the floor: |
Actually, reflecting on this, I think we need to tie the two APIs together. You can't use this API without full screen, and exiting full screen should automatically unlock. I'll spin up a new issue. |
filed #209 |
Reopening, as this is still an issue. @saschanaz, @foolip, @michaelwasserman, we've now hit this issue also in WebKit (this was also an issue in Firefox, IIRC). The problem is that we end up with a race condition:
The IPC calls can arrive and be processed out of order. That makes a mess for FS API and this one. I'd like to make .unlock() return a promise. Would you have any objections to us doing that? |
Could you maybe explain the mess and how returning a promise helps resolve it? At least to me one seems like an implementation concern we'd have to resolve one way or another and the other is a nicety of the API, but doesn't really change the implementation. Except it requires it to do something with the promise, but that seems strictly additional to having to deal with the race. (One way out might be to make |
Sure! ProblemThe over problem with the design of the API is that it's designed to be "fire and forget". I think this was done originally (9 years ago) because some OSs didn't provide any signal about the success of the orientation change. That led to the current model:
And the assumption with
The above assumption is wrong, because Thus, if one calls:
They race, because the IPC messages could end up out of order. Similarly:
Has the race condition, as noted by the OP. This leads to horrible hacks, like using The work around in WebKit's test framework is now to always basically do:
Addressing the issueWhat should have actually happened in the API is that it should have been impossible to make call to .unlock() (or another .lock()) before the first call finishes (and the promise settles). const p1 = orientation.lock("any");
// InvalidStateError, p1 hasn't settled.
const p2 = orientation.lock("landscape");
// Unlock, InvalidStateError, p1 hasn't settled
const p3 = orientation.unlock(); Unfortunately, doing the above might no longer be web compatible... What we should do...Unlocking should be treated exactly the same as .lock(). That is:
That means that .unlock() will abort any pending
The problem is that the API can be used outside the context of the FS API (e.g., a web application that was installed that launched full screen). However, we should nonetheless integrate the two APIs as I proposed here: |
Okay, so the promise gives web developers a chance to do things better, but we still have to define what happens when they don't. I suppose there's also calling |
Not only that, but predictability and a degree of assurance that unlocking actually happened (or, in an exceptional case, not).
Yes, absolutely: that's mostly what all the machinery that aborts the promises of previous calls to
Yeah, this is why the integration with FS API should really help: it will prevent much of the weirdness that can happen when trying to full screen and then change orientation by allowing the user agent to do it all smoothly in one action. |
Sent #231 ... folks interested in this topic, would really appreciate your review and feedback. CC @michaelwasserman |
This seems like it would be a clear win for screen orientation API ergonomics, but I'm curious about the premise: Can you reference source material regarding how underlying OS APIs report the success or failure of these requests? I'm a novice in this space and I don't see anything quite so obvious. It doesn't help that Chromium's current implementation seems incautious at first glance. After issuing OS requests, promises seem to be resolved immediately for locks matching the current orientation, or when a matching orientation change event occurs. Should the spec incorporate potentially undetectable OS API failures, beyond leaving promises indefinitely unresolved? |
I'm not sure about how it works on Android... but quick search says one simply sets On Apple's platform, one can monitor for changes also in a similar manner via There is also |
Returning a promise seems nice, but the spec might need to note they are best-effort? AFAICT:
|
TPAC 2024: We can acknowledge that this is best case. Returning Promise.resolve() would at least spin the event loop to help folks get out of trouble. Change seems fine. |
I understand that this might not be possible from the note -
I am working on building an app that uses WebVR. Entering VR mode requires going fullscreen and then locking orientation to landscape. This works perfectly.
However exiting this mode when phone is in portrait orientation, on tested Android devices, results in the browser bar and menu disappearing and a large white space appearing under the app. Dragging down on the screen reveals the browser bar and covers the white space, you can not then drag back up.
I've overcome this issue using the following code
A cleaner solution would be something like -
The text was updated successfully, but these errors were encountered: