mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-05 22:30:29 +00:00
[skip ci] Wait until the user interacts with the page
This commit is contained in:
parent
c52bf5188f
commit
9ae773bcbc
1 changed files with 16 additions and 3 deletions
|
|
@ -140,11 +140,24 @@ static void SDL_WebHID_DisconnectEmscriptenGamepad(int device_index)
|
|||
static void SDL_RequestWebHIDDevice(Uint16 vendor, Uint16 product, int device_index)
|
||||
{
|
||||
MAIN_THREAD_EM_ASM({
|
||||
function timeout(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
if ("hid" in navigator) {
|
||||
async function handler() {
|
||||
let devices = await navigator["hid"]["requestDevice"]({ "filters": [ { "vendorId": $0, "productId": $1, } ]});
|
||||
if (devices) {
|
||||
dynCall("vi", $2, [$3]);
|
||||
while (true) {
|
||||
try {
|
||||
let devices = await navigator["hid"]["requestDevice"]({ "filters": [ { "vendorId": $0, "productId": $1, } ]});
|
||||
if (devices) {
|
||||
dynCall("vi", $2, [$3]);
|
||||
}
|
||||
return;
|
||||
} catch(e) {
|
||||
// Exception, most likely because the user hasn't interacted with the page yet.
|
||||
// Let's wait until they do, hopefully.
|
||||
await timeout(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
handler();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue